his_api_controller.go 464KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. if number >= 1000 {
  187. zero = "0000" + strconv.FormatInt(number, 10)
  188. } else if number >= 10000 {
  189. zero = "000" + strconv.FormatInt(number, 10)
  190. } else if number >= 100000 {
  191. zero = "00" + strconv.FormatInt(number, 10)
  192. } else if number >= 1000000 {
  193. zero = "0" + strconv.FormatInt(number, 10)
  194. } else {
  195. zero = strconv.FormatInt(number, 10)
  196. }
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. order.PsnCashPay = order.MedfeeSumamt
  1021. for _, item := range orderInfos {
  1022. if item.MedChrgitmType == "01" { //床位费
  1023. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1024. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1025. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1026. }
  1027. if item.MedChrgitmType == "02" { //诊察费
  1028. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1029. //zhenChaCostSelfTotal = zhenChaCostTotal
  1030. }
  1031. if item.MedChrgitmType == "03" { //检查费
  1032. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "02" { //检查费
  1037. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1039. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1040. }
  1041. if item.MedChrgitmType == "04" { //化验费
  1042. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1043. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1044. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1045. }
  1046. if item.MedChrgitmType == "05" { //治疗费
  1047. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1048. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1049. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1050. }
  1051. if item.MedChrgitmType == "06" { //手术费
  1052. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1053. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1054. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1055. }
  1056. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1057. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1058. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1059. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "09" { //西药费
  1062. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1064. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1065. }
  1066. if item.MedChrgitmType == "11" { //中成费
  1067. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1068. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1069. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1070. }
  1071. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1072. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1073. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1074. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1075. }
  1076. }
  1077. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1078. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1079. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1080. var dia_config []*models.HisXtDiagnoseConfig
  1081. var diagnosis_ids []string
  1082. if his.ID > 0 {
  1083. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1084. } else {
  1085. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1086. }
  1087. for _, item := range diagnosis_ids {
  1088. id, _ := strconv.ParseInt(item, 10, 64)
  1089. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1090. dia_config = append(dia_config, diagnosisConfig)
  1091. }
  1092. var rf []CustomFundPay
  1093. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1094. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1095. c.ServeSuccessJSON(map[string]interface{}{
  1096. "patient": patient,
  1097. "order_infos": orderInfos,
  1098. "diagnosis": name,
  1099. "bedCostTotal": bedCostTotal,
  1100. "bedCostSelfTotal": bedCostTotal,
  1101. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1102. "operationCostTotal": operationCostTotal,
  1103. "operationCostSelfTotal": operationCostTotal,
  1104. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1105. "otherCostTotal": otherCostTotal,
  1106. "otherCostSelfTotal": otherCostTotal,
  1107. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1108. "materialCostTotal": materialCostTotal,
  1109. "materialCostSelfTotal": materialCostTotal,
  1110. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1111. "westernMedicineCostTotal": westernMedicineCostTotal,
  1112. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1113. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1114. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1115. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1116. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1117. "checkCostTotal": checkCostTotal,
  1118. "checkCostSelfTotal": checkCostTotal,
  1119. "zhenChaCostTotal": zhenChaCostTotal,
  1120. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1121. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1122. "laboratoryCostTotal": laboratoryCostTotal,
  1123. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1124. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1125. "treatCostTotal": treatCostTotal,
  1126. "treatCostSelfTotal": treatCostTotal,
  1127. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1128. "charge_admin": charge_admin,
  1129. "printor_admin": printor_admin,
  1130. "org_name": org.OrgName,
  1131. "org_code": miConfig.Code,
  1132. "name": patient.Name,
  1133. "number": order.MdtrtId,
  1134. "date": order.SettleAccountsDate,
  1135. "info": order,
  1136. "new_order": order,
  1137. "his_hospital": his_hospital,
  1138. "his": his,
  1139. "funds": rf,
  1140. "dia_config": dia_config,
  1141. })
  1142. }
  1143. func (c *HisApiController) RefudDetail() {
  1144. order_id, _ := c.GetInt64("order_id")
  1145. order, _ := service.GetHisOrderByID(order_id)
  1146. adminUser := c.GetAdminUserInfo()
  1147. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "msg": "撤销成功",
  1150. })
  1151. }
  1152. func (c *HisApiController) Sscard() {
  1153. //r := CardInit()
  1154. //if r == 0 {
  1155. // GetBaseInfo()
  1156. //}
  1157. //c.ServeSuccessJSON(map[string]interface{}{
  1158. // "list": "11",
  1159. //})
  1160. }
  1161. func GetBaseInfo() error {
  1162. //handle := syscall.MustLoadDLL("SSCard.dll")
  1163. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1164. //
  1165. //str := make([]byte, 256)
  1166. //str1 := make([]byte, 256)
  1167. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1168. //if ferr != nil {
  1169. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1170. // return ferr
  1171. //}
  1172. //
  1173. //fmt.Println(string(str))
  1174. //
  1175. //fmt.Println(r)
  1176. return nil
  1177. }
  1178. func CardInit() int {
  1179. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1180. //add := DllTestDef.MustFindProc("Init")
  1181. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1182. //if err != nil {
  1183. // fmt.Println("SSCard的运算结果为:", ret)
  1184. //}
  1185. //result := int(ret)
  1186. return 0
  1187. }
  1188. func IntPtr(n int) uintptr {
  1189. return uintptr(n)
  1190. }
  1191. func StrPtr(s string) uintptr {
  1192. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1193. }
  1194. func (c *HisApiController) GetHisPatientList() {
  1195. //types, _ := c.GetInt64("type", 0)
  1196. record_date := c.GetString("record_date")
  1197. sch_type, _ := c.GetInt64("sch_type")
  1198. timeLayout := "2006-01-02"
  1199. loc, _ := time.LoadLocation("Local")
  1200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1201. if err != nil {
  1202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1203. return
  1204. }
  1205. recordDateTime := theTime.Unix()
  1206. adminInfo := c.GetAdminUserInfo()
  1207. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1208. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1209. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1210. //获取当前用户的信息
  1211. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1212. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1213. //获取所有科室信息
  1214. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1215. c.ServeSuccessJSON(map[string]interface{}{
  1216. "list": patients,
  1217. "list_two": patients_two,
  1218. "info": adminUserInfo,
  1219. "doctors": doctors,
  1220. "department": department,
  1221. })
  1222. }
  1223. type CustomTemplate struct {
  1224. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1225. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1226. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1227. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1228. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1229. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1230. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1231. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1232. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1233. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1234. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1235. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1236. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1237. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1238. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1239. }
  1240. func (c *HisApiController) GetHisPatientInfo() {
  1241. patient_id, _ := c.GetInt64("patient_id")
  1242. his_patient_id, _ := c.GetInt64("his_patient_id")
  1243. record_date := c.GetString("record_date")
  1244. number := c.GetString("number")
  1245. //start_time := c.GetString("start_time")
  1246. //end_time := c.GetString("end_time")
  1247. p_type, _ := c.GetInt64("p_type")
  1248. timeLayout := "2006-01-02"
  1249. loc, _ := time.LoadLocation("Local")
  1250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1251. if err != nil {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1253. return
  1254. }
  1255. recordDateTime := theTime.Unix()
  1256. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1257. //if err != nil {
  1258. //
  1259. //}
  1260. //startRecordDateTime := startTime.Unix()
  1261. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1262. //if err != nil {
  1263. //
  1264. //}
  1265. //endRecordDateTime := endTime.Unix()
  1266. admin := c.GetAdminUserInfo()
  1267. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1268. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1269. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1270. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1271. var prescriptions []*models.HisPrescription
  1272. var last_prescriptions []*models.HisPrescription
  1273. var sch_prescriptions []CustomTemplate
  1274. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1275. if p_type == 1 { //住院
  1276. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1277. for _, item := range prescriptions {
  1278. for _, subItem := range item.HisDoctorAdviceInfo {
  1279. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1280. if info.RetailPrice > 0 {
  1281. subItem.Drug.MinPrice = info.RetailPrice
  1282. }
  1283. }
  1284. }
  1285. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1286. } else { //门诊
  1287. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1288. for _, item := range prescriptions {
  1289. for _, subItem := range item.HisDoctorAdviceInfo {
  1290. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1291. if info.RetailPrice > 0 {
  1292. subItem.Drug.MinPrice = info.RetailPrice
  1293. }
  1294. }
  1295. }
  1296. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1297. }
  1298. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1299. if sch.ID > 0 {
  1300. var week string
  1301. t := time.Now()
  1302. switch t.Weekday().String() {
  1303. case "Monday":
  1304. week = "周一"
  1305. break
  1306. case "Tuesday":
  1307. week = "周二"
  1308. break
  1309. case "Wednesday":
  1310. week = "周三"
  1311. break
  1312. case "Thursday":
  1313. week = "周四"
  1314. break
  1315. case "Friday":
  1316. week = "周五"
  1317. break
  1318. case "Saturday":
  1319. week = "周六"
  1320. break
  1321. case "Sunday":
  1322. week = "周日"
  1323. break
  1324. }
  1325. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1326. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1327. //根据推送频率组装新的数组
  1328. for _, item := range temp_sch_prescriptions {
  1329. var cus CustomTemplate
  1330. cus.ID = item.ID
  1331. cus.UserOrgId = item.UserOrgId
  1332. cus.PatientId = item.PatientId
  1333. cus.MedType = item.MedType
  1334. cus.RecordDate = item.RecordDate
  1335. cus.Type = item.Type
  1336. cus.PType = item.PType
  1337. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1338. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1339. if subItem.FrequencyType == 1 { //每次必推
  1340. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1341. }
  1342. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 2 { //按照天数频率
  1346. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1347. now := p.Unix()
  1348. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1349. dayStr2 := "-" + dayStr
  1350. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1351. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1352. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1353. if len(advices) == 0 {
  1354. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1355. }
  1356. }
  1357. }
  1358. }
  1359. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1360. if subItem.Type == 2 {
  1361. if subItem.XtHisProject.MedicalStatus != 1 {
  1362. if subItem.FrequencyType == 1 {
  1363. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1364. }
  1365. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 2 {
  1369. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1370. now := p.Unix()
  1371. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1372. dayStr2 := "-" + dayStr
  1373. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1374. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1375. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1376. if len(projects) == 0 {
  1377. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1378. }
  1379. }
  1380. }
  1381. } else if subItem.Type == 3 {
  1382. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1383. if subItem.FrequencyType == 1 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 2 {
  1390. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1391. now := p.Unix()
  1392. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1393. dayStr2 := "-" + dayStr
  1394. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1395. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1396. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1397. if len(projects) == 0 {
  1398. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. sch_prescriptions = append(sch_prescriptions, cus)
  1405. }
  1406. for _, item := range sch_prescriptions {
  1407. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1408. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1409. }
  1410. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1411. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1412. }
  1413. }
  1414. }
  1415. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1416. if config.ID > 0 && config.IsOpen == 1 {
  1417. for _, item := range sch_prescriptions {
  1418. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1419. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1420. if info.RetailPrice > 0 {
  1421. subItem.Drug.MinPrice = info.RetailPrice
  1422. }
  1423. }
  1424. }
  1425. }
  1426. if config.ID > 0 && config.IsOpen == 1 {
  1427. for _, item := range sch_prescriptions {
  1428. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1429. if subItem.Type == 3 {
  1430. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1431. if info.Price > 0 {
  1432. subItem.GoodInfo.PackingPrice = info.Price
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1439. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1440. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1441. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1442. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1443. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1444. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1445. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1446. //获取所有科室信息
  1447. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1448. c.ServeSuccessJSON(map[string]interface{}{
  1449. "his_info": his_patient_info,
  1450. "xt_info": xt_patient_info,
  1451. "prescription": prescriptions,
  1452. "case_history": case_history,
  1453. "info": patientPrescriptionInfo,
  1454. //"month_prescriptions": monthPrescriptions,
  1455. "order": order,
  1456. "doctors": doctors,
  1457. "department": department,
  1458. "sch_prescriptions": sch_prescriptions,
  1459. "last_prescriptions": last_prescriptions,
  1460. "schedule": sch,
  1461. "count": count,
  1462. "drugStockConfig": drugStockConfig,
  1463. "last_info": lastPatientPrescriptionInfo,
  1464. })
  1465. return
  1466. }
  1467. func (c *HisApiController) GetHisPrescriptionConfig() {
  1468. adminInfo := c.GetAdminUserInfo()
  1469. //获取医嘱模版
  1470. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1471. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1472. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1473. //获取所有基础药
  1474. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1475. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1476. if config.ID > 0 && config.IsOpen == 1 {
  1477. for _, item := range drugs {
  1478. var index = 0
  1479. for _, subItem := range item.OtherDrugWarehouseInfo {
  1480. if index == 0 {
  1481. index = index + 1
  1482. if subItem.RetailPrice > 0 {
  1483. item.MinPrice = subItem.RetailPrice
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1490. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1491. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1492. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1493. //获取所有科室信息
  1494. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1495. //获取诊断信息
  1496. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1497. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1498. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1499. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1500. //获取是否开启保存耗材出库的开关
  1501. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1502. c.ServeSuccessJSON(map[string]interface{}{
  1503. "drugs": drugs,
  1504. "advices_template": advices,
  1505. "drugways": drugways,
  1506. "efs": efs,
  1507. "doctors": doctors,
  1508. "department": department,
  1509. "sick": sick,
  1510. "additions": additions,
  1511. "diagnose": diagnose,
  1512. "manufacturers": manufacturers,
  1513. "goodOutOpen": goodOutOpen,
  1514. "patientDiagnose": patientDiagnose,
  1515. })
  1516. }
  1517. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1518. //获取所有基础药
  1519. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1520. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1521. if config.ID > 0 && config.IsOpen == 1 {
  1522. for _, item := range drugs {
  1523. var index = 0
  1524. for _, subItem := range item.OtherDrugWarehouseInfo {
  1525. if index == 0 {
  1526. index = index + 1
  1527. if subItem.RetailPrice > 0 {
  1528. item.MinPrice = subItem.RetailPrice
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1535. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1536. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1537. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1538. //获取所有科室信息
  1539. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1540. //获取诊断信息
  1541. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1542. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1543. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1544. //获取是否开启保存耗材出库的开关
  1545. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1546. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "drugs": drugs,
  1549. "advices_template": advices,
  1550. "drugways": drugways,
  1551. "efs": efs,
  1552. "doctors": doctors,
  1553. "department": department,
  1554. "sick": sick,
  1555. "additions": additions,
  1556. "diagnose": diagnose,
  1557. "manufacturers": manufacturers,
  1558. "goodOutOpen": goodOutOpen,
  1559. "patientDiagnose": patientDiagnose,
  1560. })
  1561. }
  1562. }
  1563. func (c *HisApiController) CreateHisPrescription() {
  1564. record_date := c.GetString("record_date")
  1565. patient_id, _ := c.GetInt64("patient_id")
  1566. reg_type, _ := c.GetInt64("reg_type")
  1567. diagnose := c.GetString("diagnose")
  1568. sick_type, _ := c.GetInt64("sick_type")
  1569. sick_history := c.GetString("sick_history")
  1570. doctor_id, _ := c.GetInt64("doctor", 0)
  1571. department, _ := c.GetInt64("department", 0)
  1572. his_patient_id, _ := c.GetInt64("his_patient_id")
  1573. p_type, _ := c.GetInt64("p_type")
  1574. patient_diagnose := c.GetString("patient_diagnose")
  1575. dataBody := make(map[string]interface{}, 0)
  1576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1577. if err != nil {
  1578. utils.ErrorLog(err.Error())
  1579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1580. return
  1581. }
  1582. //edit, src := GetCompareData(dataBody)
  1583. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1584. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1585. //fmt.Println(drugResult)
  1586. //fmt.Println(goodResult)
  1587. timeLayout := "2006-01-02"
  1588. loc, _ := time.LoadLocation("Local")
  1589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1590. if err != nil {
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. adminInfo := c.GetAdminUserInfo()
  1595. recordDateTime := theTime.Unix()
  1596. //查询默认出库仓库库存
  1597. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1598. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1599. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1600. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1601. if len(lists) == 1 {
  1602. his_patient_id = lists[0].ID
  1603. }
  1604. }
  1605. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1606. //保存处方出库
  1607. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1608. //自动出库
  1609. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1610. //耗材保存处方出库
  1611. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1612. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1613. //已发药和已收费限制逻辑
  1614. isMidicine := false
  1615. isCharge := false
  1616. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1617. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1618. if len(prescriptions) > 0 {
  1619. for _, item := range prescriptions {
  1620. items := item.(map[string]interface{})
  1621. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1622. utils.ErrorLog("id")
  1623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1624. return
  1625. }
  1626. id := int64(items["id"].(float64))
  1627. if id > 0 {
  1628. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1629. if err != nil {
  1630. if new_prescription.OrderStatus == 4 {
  1631. isCharge = true
  1632. }
  1633. }
  1634. }
  1635. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1636. advices := items["advices"].([]interface{})
  1637. if len(advices) > 0 {
  1638. for _, advice := range advices {
  1639. var adviceId int64
  1640. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1641. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1642. }
  1643. if adviceId > 0 {
  1644. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1645. if err == nil {
  1646. if his_advice_info.IsMedicine == 1 {
  1647. isMidicine = true
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. if isMidicine == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1659. return
  1660. }
  1661. if isCharge == true {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1663. return
  1664. }
  1665. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1666. //药品发药出库
  1667. if pharmacyConfig.IsOpen == 1 {
  1668. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1669. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1670. if len(prescriptions) > 0 {
  1671. for _, item := range prescriptions {
  1672. items := item.(map[string]interface{})
  1673. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1674. advices := items["advices"].([]interface{})
  1675. if len(advices) > 0 {
  1676. for _, advice := range advices {
  1677. var drug_id int64
  1678. var prescribing_number float64
  1679. var prescribingNumberUnit string
  1680. var adviceId int64
  1681. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1682. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1683. }
  1684. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1685. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1686. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1687. }
  1688. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1689. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1690. }
  1691. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1692. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1693. }
  1694. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1695. if drug.ID == 0 {
  1696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1697. return
  1698. }
  1699. //查询药品的所有库存
  1700. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1701. var total_count int64
  1702. for _, it := range list {
  1703. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1704. }
  1705. totals := strconv.FormatInt(total_count, 10)
  1706. //查询该药品是否存在开药记录
  1707. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1708. fmt.Println("wooooooooooooo", advicelist.ID)
  1709. fmt.Println("prescribingNumberUnit", prescribingNumberUnit)
  1710. fmt.Println("prescribingNumberUnit", drug.MinUnit)
  1711. fmt.Println("prescribingNumberUnit", drug.MaxUnit)
  1712. //新增处方
  1713. if advicelist.ID == 0 {
  1714. all_count, _ := strconv.ParseFloat(totals, 64)
  1715. if prescribingNumberUnit == drug.MinUnit {
  1716. fmt.Println("prescribing_number", prescribing_number)
  1717. fmt.Println("all_count", all_count)
  1718. if drug.IsUse != 1 {
  1719. if drug.IsProject == 0 || drug.IsProject == 2 {
  1720. if all_count == 0 {
  1721. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1722. return
  1723. }
  1724. if prescribing_number > all_count {
  1725. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1726. return
  1727. }
  1728. }
  1729. }
  1730. }
  1731. if prescribingNumberUnit == drug.MaxUnit {
  1732. num := prescribing_number * float64(drug.MinNumber)
  1733. if drug.IsUse != 1 {
  1734. if drug.IsProject == 0 || drug.IsProject == 2 {
  1735. if all_count == 0 {
  1736. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1737. return
  1738. }
  1739. if num > all_count {
  1740. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1741. return
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1748. if drugOutConfig.IsOpen != 1 {
  1749. //修改处方
  1750. for _, advice := range advices {
  1751. var drug_id int64
  1752. var prescribing_number float64
  1753. var prescribingNumberUnit string
  1754. var prescribingNumber string
  1755. var adviceId int64
  1756. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1757. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1758. }
  1759. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1760. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1761. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1762. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1763. }
  1764. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1765. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1766. }
  1767. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1768. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1769. }
  1770. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1771. if drug.ID == 0 {
  1772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1773. return
  1774. }
  1775. //查询药品的所有库存
  1776. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1777. var total_count int64
  1778. for _, it := range list {
  1779. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1780. }
  1781. totals := strconv.FormatInt(total_count, 10)
  1782. //查询该药品是否存在开药记录
  1783. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1784. //新增处方
  1785. if advicelist.ID == 0 {
  1786. all_count, _ := strconv.ParseFloat(totals, 64)
  1787. if prescribingNumberUnit == drug.MinUnit {
  1788. if drug.IsUse != 1 {
  1789. if drug.IsProject == 0 || drug.IsProject == 2 {
  1790. if all_count == 0 {
  1791. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1792. return
  1793. }
  1794. if prescribing_number > all_count {
  1795. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1796. return
  1797. }
  1798. }
  1799. }
  1800. } else {
  1801. if prescribingNumberUnit == drug.MaxUnit {
  1802. num := prescribing_number * float64(drug.MinNumber)
  1803. if drug.IsUse != 1 {
  1804. if drug.IsProject == 0 || drug.IsProject == 2 {
  1805. if all_count == 0 {
  1806. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1807. return
  1808. }
  1809. if num > all_count {
  1810. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1811. return
  1812. }
  1813. }
  1814. }
  1815. }
  1816. }
  1817. }
  1818. //修改处方
  1819. if advicelist.ID > 0 {
  1820. var device_number int64
  1821. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1822. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1823. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1824. device_number = prescribingNumberInt * drug.MinNumber
  1825. }
  1826. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1827. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1828. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1829. device_number = prescribingNumberInt
  1830. }
  1831. var number_count int64
  1832. if prescribingNumberUnit == drug.MaxUnit {
  1833. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1834. number_count = prescribingNumberInt * drug.MinNumber
  1835. }
  1836. if prescribingNumberUnit == drug.MinUnit {
  1837. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1838. number_count = prescribingNumberInt
  1839. }
  1840. //如果修改的数量大于之前修改的数量
  1841. if (number_count - device_number) > 0 {
  1842. //如果修改的差数量 大于库存数量
  1843. if drug.IsUse != 1 {
  1844. if (number_count - device_number) > total_count {
  1845. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1846. return
  1847. }
  1848. }
  1849. }
  1850. }
  1851. }
  1852. }
  1853. }
  1854. }
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. //已发药和已收费限制逻辑
  1861. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1862. //校验库存总量
  1863. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1864. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1865. if len(prescriptions) > 0 {
  1866. for _, item := range prescriptions {
  1867. items := item.(map[string]interface{})
  1868. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1869. advices := items["advices"].([]interface{})
  1870. if len(advices) > 0 {
  1871. for _, advice := range advices {
  1872. var drug_id int64
  1873. var prescribing_number float64
  1874. var prescribingNumberUnit string
  1875. var adviceId int64
  1876. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1877. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1878. }
  1879. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1880. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1881. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1882. }
  1883. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1884. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1885. }
  1886. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1887. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1888. }
  1889. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1890. if drug.ID == 0 {
  1891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1892. return
  1893. }
  1894. //查询药品的所有库存
  1895. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1896. var total_count int64
  1897. for _, it := range list {
  1898. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1899. }
  1900. totals := strconv.FormatInt(total_count, 10)
  1901. //查询该药品是否存在开药记录
  1902. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1903. //查询最新批次库存
  1904. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1905. var batch_number_count int64
  1906. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1907. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1908. //新增处方
  1909. if advicelist.ID == 0 {
  1910. all_count, _ := strconv.ParseFloat(totals, 64)
  1911. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1912. if prescribingNumberUnit == drug.MinUnit {
  1913. if drug.IsUse != 1 {
  1914. if drug.IsProject == 0 || drug.IsProject == 2 {
  1915. if all_count == 0 {
  1916. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1917. return
  1918. }
  1919. if prescribing_number > all_count {
  1920. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1921. return
  1922. }
  1923. }
  1924. if adminInfo.CurrentOrgId == 10215 {
  1925. if prescribing_number > batch_number_all_count {
  1926. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1927. return
  1928. }
  1929. }
  1930. }
  1931. }
  1932. if prescribingNumberUnit == drug.MaxUnit {
  1933. num := prescribing_number * float64(drug.MinNumber)
  1934. if drug.IsUse != 1 {
  1935. if drug.IsProject == 0 || drug.IsProject == 2 {
  1936. if all_count == 0 {
  1937. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1938. return
  1939. }
  1940. if num > all_count {
  1941. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1942. return
  1943. }
  1944. }
  1945. if adminInfo.CurrentOrgId == 10215 {
  1946. if num > batch_number_all_count {
  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. }
  1954. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1955. if drugOutConfig.IsOpen != 1 {
  1956. //修改处方
  1957. for _, advice := range advices {
  1958. var drug_id int64
  1959. var prescribing_number float64
  1960. var prescribingNumberUnit string
  1961. var prescribingNumber string
  1962. var adviceId int64
  1963. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1964. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1965. }
  1966. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1967. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1968. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1969. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1970. }
  1971. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1972. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1973. }
  1974. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1975. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1976. }
  1977. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1978. if drug.ID == 0 {
  1979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1980. return
  1981. }
  1982. //查询药品的所有库存
  1983. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1984. var total_count int64
  1985. for _, it := range list {
  1986. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1987. }
  1988. totals := strconv.FormatInt(total_count, 10)
  1989. //查询该药品是否存在开药记录
  1990. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1991. //新增处方
  1992. if advicelist.ID == 0 {
  1993. //查询最新批次库存
  1994. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1995. var batch_number_count int64
  1996. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1997. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1998. all_count, _ := strconv.ParseFloat(totals, 64)
  1999. if prescribingNumberUnit == drug.MinUnit {
  2000. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2001. if drug.IsUse != 1 {
  2002. if drug.IsProject == 0 || drug.IsProject == 2 {
  2003. if all_count == 0 {
  2004. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2005. return
  2006. }
  2007. if prescribing_number > all_count {
  2008. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2009. return
  2010. }
  2011. }
  2012. if adminInfo.CurrentOrgId == 10215 {
  2013. if prescribing_number > batch_number_all_count {
  2014. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2015. return
  2016. }
  2017. }
  2018. }
  2019. } else {
  2020. if prescribingNumberUnit == drug.MaxUnit {
  2021. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2022. num := prescribing_number * float64(drug.MinNumber)
  2023. if drug.IsUse != 1 {
  2024. if drug.IsProject == 0 || drug.IsProject == 2 {
  2025. if all_count == 0 {
  2026. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2027. return
  2028. }
  2029. if num > all_count {
  2030. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2031. return
  2032. }
  2033. }
  2034. if adminInfo.CurrentOrgId == 10215 {
  2035. if prescribing_number > batch_number_all_count {
  2036. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2037. return
  2038. }
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. //修改处方
  2045. if advicelist.ID > 0 {
  2046. //查询最新批次库存
  2047. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2048. var batch_number_count int64
  2049. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2050. var device_number int64
  2051. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2052. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2053. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2054. device_number = prescribingNumberInt * drug.MinNumber
  2055. }
  2056. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2057. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2058. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2059. device_number = prescribingNumberInt
  2060. }
  2061. var number_count int64
  2062. if prescribingNumberUnit == drug.MaxUnit {
  2063. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2064. number_count = prescribingNumberInt * drug.MinNumber
  2065. }
  2066. if prescribingNumberUnit == drug.MinUnit {
  2067. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2068. number_count = prescribingNumberInt
  2069. }
  2070. //如果修改的数量大于之前修改的数量
  2071. if (number_count - device_number) > 0 {
  2072. //如果修改的差数量 大于库存数量
  2073. if drug.IsUse != 1 {
  2074. if drug.IsProject == 0 || drug.IsProject == 2 {
  2075. if total_count == 0 {
  2076. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2077. return
  2078. }
  2079. if (number_count - device_number) > total_count {
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2081. return
  2082. }
  2083. if (number_count - device_number) > batch_number_count {
  2084. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2085. return
  2086. }
  2087. }
  2088. if adminInfo.CurrentOrgId == 10215 {
  2089. // 查询该药品最后一次出库记录
  2090. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2091. var out_count int64
  2092. var in_count int64
  2093. var stock_max_number int64
  2094. var stock_min_number int64
  2095. for _, it := range outInfo {
  2096. if it.CountUnit == drug.MaxUnit {
  2097. it.Count = it.Count * drug.MinNumber
  2098. }
  2099. out_count += it.Count
  2100. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2101. stock_max_number = warehouseInfoList.StockMaxNumber
  2102. stock_min_number = warehouseInfoList.StockMinNumber
  2103. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2104. }
  2105. if out_count > 0 {
  2106. if (number_count - device_number) > in_count {
  2107. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2108. return
  2109. }
  2110. }
  2111. // 未出库
  2112. if out_count == 0 {
  2113. var sum_in_count int64
  2114. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2115. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2116. fmt.Println("sum_in_count", sum_in_count)
  2117. //如果修改的数量大于有库存的第一个批次
  2118. if number_count > sum_in_count {
  2119. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2120. return
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2127. if pharmacyConfig.IsOpen != 1 {
  2128. if device_number != number_count {
  2129. // 查询该药品最后一次出库记录
  2130. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2131. //回退库存
  2132. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2133. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2134. }
  2135. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2136. var stock_max_number int64
  2137. var stock_min_number int64
  2138. if number_count >= drug.MinNumber {
  2139. stock_max_number = device_number / drug.MinNumber
  2140. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2141. stock_min_number = device_number % drug.MinNumber
  2142. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2143. } else {
  2144. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2145. }
  2146. }
  2147. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2148. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2149. }
  2150. //删除记录
  2151. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2152. //查询默认仓库剩余多少库存
  2153. var sum_count int64
  2154. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2155. for _, its := range stockInfo {
  2156. if its.MaxUnit == drug.MaxUnit {
  2157. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2158. }
  2159. sum_count += its.StockMaxNumber + its.StockMinNumber
  2160. }
  2161. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2162. }
  2163. }
  2164. }
  2165. }
  2166. }
  2167. //保存处方开药
  2168. if drugOutConfig.IsOpen == 1 {
  2169. //修改处方
  2170. for _, advice := range advices {
  2171. var drug_id int64
  2172. var prescribing_number float64
  2173. var prescribingNumberUnit string
  2174. var prescribingNumber string
  2175. var adviceId int64
  2176. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2177. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2178. }
  2179. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2180. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2181. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2182. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2183. }
  2184. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2185. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2186. }
  2187. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2188. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2189. }
  2190. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2191. if drug.ID == 0 {
  2192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2193. return
  2194. }
  2195. //查询药品的所有库存
  2196. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2197. var total_count int64
  2198. for _, it := range list {
  2199. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2200. }
  2201. totals := strconv.FormatInt(total_count, 10)
  2202. //查询该药品是否存在开药记录
  2203. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2204. //新增处方
  2205. if advicelist.ID == 0 {
  2206. //查询最新批次库存
  2207. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2208. var batch_number_count int64
  2209. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2210. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2211. all_count, _ := strconv.ParseFloat(totals, 64)
  2212. if prescribingNumberUnit == drug.MinUnit {
  2213. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2214. if drug.IsUse != 1 {
  2215. if drug.IsProject == 0 || drug.IsProject == 2 {
  2216. if all_count == 0 {
  2217. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2218. return
  2219. }
  2220. if prescribing_number > all_count {
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2222. return
  2223. }
  2224. }
  2225. if adminInfo.CurrentOrgId == 10215 {
  2226. if prescribing_number > batch_number_all_count {
  2227. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2228. return
  2229. }
  2230. }
  2231. }
  2232. } else {
  2233. if prescribingNumberUnit == drug.MaxUnit {
  2234. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2235. num := prescribing_number * float64(drug.MinNumber)
  2236. if drug.IsUse != 1 {
  2237. if drug.IsProject == 0 || drug.IsProject == 2 {
  2238. if all_count == 0 {
  2239. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2240. return
  2241. }
  2242. if num > all_count {
  2243. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2244. return
  2245. }
  2246. }
  2247. if adminInfo.CurrentOrgId == 10215 {
  2248. if prescribing_number > batch_number_all_count {
  2249. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2250. return
  2251. }
  2252. }
  2253. }
  2254. }
  2255. }
  2256. }
  2257. //修改处方
  2258. if advicelist.ID > 0 {
  2259. //查询最新批次库存
  2260. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2261. var batch_number_count int64
  2262. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2263. var device_number int64
  2264. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2265. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2266. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2267. device_number = prescribingNumberInt * drug.MinNumber
  2268. }
  2269. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2270. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2271. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2272. device_number = prescribingNumberInt
  2273. }
  2274. var number_count int64
  2275. if prescribingNumberUnit == drug.MaxUnit {
  2276. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2277. number_count = prescribingNumberInt * drug.MinNumber
  2278. }
  2279. if prescribingNumberUnit == drug.MinUnit {
  2280. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2281. number_count = prescribingNumberInt
  2282. }
  2283. //如果修改的数量大于之前修改的数量
  2284. if (number_count - device_number) > 0 {
  2285. //如果修改的差数量 大于库存数量
  2286. if drug.IsUse != 1 {
  2287. if drug.IsProject == 0 || drug.IsProject == 2 {
  2288. if total_count == 0 {
  2289. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2290. return
  2291. }
  2292. if (number_count - device_number) > total_count {
  2293. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2294. return
  2295. }
  2296. }
  2297. if adminInfo.CurrentOrgId == 10215 {
  2298. if (number_count - device_number) > batch_number_count {
  2299. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2300. return
  2301. }
  2302. }
  2303. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2304. //查询历史出库数据总批次
  2305. // 查询该药品最后一次出库记录
  2306. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2307. var out_count int64
  2308. var in_count int64
  2309. var stock_max_number int64
  2310. var stock_min_number int64
  2311. for _, it := range outInfo {
  2312. if it.CountUnit == drug.MaxUnit {
  2313. it.Count = it.Count * drug.MinNumber
  2314. }
  2315. out_count += it.Count
  2316. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2317. stock_max_number = warehouseInfoList.StockMaxNumber
  2318. stock_min_number = warehouseInfoList.StockMinNumber
  2319. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2320. }
  2321. if out_count > 0 {
  2322. if (number_count - device_number) > in_count {
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. }
  2327. // 未出库
  2328. if out_count == 0 {
  2329. var sum_in_count int64
  2330. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2331. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2332. if sum_in_count == 0 {
  2333. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2334. return
  2335. }
  2336. //如果修改的数量大于有库存的第一个批次
  2337. if number_count > sum_in_count {
  2338. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2339. return
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. }
  2346. }
  2347. }
  2348. }
  2349. }
  2350. }
  2351. }
  2352. }
  2353. }
  2354. }
  2355. //校验耗材库存
  2356. if goodOutConfig.IsOpen == 1 {
  2357. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2358. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2359. if len(prescriptions) > 0 {
  2360. for _, item := range prescriptions {
  2361. items := item.(map[string]interface{})
  2362. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2363. projects := items["project"].([]interface{})
  2364. if len(projects) > 0 {
  2365. for _, project := range projects {
  2366. var project_id int64
  2367. var project_type int64
  2368. var totals float64
  2369. var project_name string
  2370. var parsetotal int64
  2371. var id int64
  2372. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2373. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2374. }
  2375. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2376. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2377. }
  2378. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2379. total, _ := project.(map[string]interface{})["total"].(string)
  2380. totals, _ = strconv.ParseFloat(total, 64)
  2381. }
  2382. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2383. project_name = project.(map[string]interface{})["project_name"].(string)
  2384. }
  2385. if project_type == 3 {
  2386. //查找该耗材的出库记录
  2387. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2388. if len(goodWarehouseInfo) == 0 {
  2389. //查询耗材库存
  2390. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2391. var stock_count int64
  2392. for _, it := range list {
  2393. stock_count += it.StockCount
  2394. }
  2395. stock_counts := strconv.FormatInt(stock_count, 10)
  2396. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2397. if stock_total_count == 0 {
  2398. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2399. return
  2400. }
  2401. if totals > stock_total_count {
  2402. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2403. return
  2404. }
  2405. }
  2406. if len(goodWarehouseInfo) > 0 {
  2407. //查询该患者耗材的历史数据
  2408. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2409. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2410. //数量发生改变
  2411. if parsetotal != count {
  2412. //如果现在的数量大于历史数量,就要看库存是否足够
  2413. if parsetotal > count {
  2414. //查询耗材所有库存
  2415. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2416. var stock_count int64
  2417. for _, it := range list {
  2418. stock_count += it.StockCount
  2419. }
  2420. //库存不足
  2421. if stock_count == 0 {
  2422. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2423. return
  2424. }
  2425. if (parsetotal - count) > stock_count {
  2426. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2427. return
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. }
  2439. }
  2440. //不使用耗材保存处方出库
  2441. if goodOutConfig.IsOpen != 1 {
  2442. if stockConfig.IsOpen == 1 {
  2443. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2444. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2445. if len(prescriptions) > 0 {
  2446. for _, item := range prescriptions {
  2447. items := item.(map[string]interface{})
  2448. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2449. projects := items["project"].([]interface{})
  2450. if len(projects) > 0 {
  2451. for _, project := range projects {
  2452. var project_id int64
  2453. var project_type int64
  2454. var totals float64
  2455. var project_name string
  2456. var parsetotal int64
  2457. var id int64
  2458. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2459. id = int64(project.(map[string]interface{})["id"].(float64))
  2460. }
  2461. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2462. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2463. }
  2464. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2465. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2466. }
  2467. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2468. total, _ := project.(map[string]interface{})["total"].(string)
  2469. totals, _ = strconv.ParseFloat(total, 64)
  2470. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2471. }
  2472. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2473. project_name = project.(map[string]interface{})["project_name"].(string)
  2474. }
  2475. if project_type == 3 {
  2476. //查找该耗材的出库记录
  2477. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2478. //没有出库记录
  2479. if len(goodWarehouseInfo) == 0 {
  2480. //查询耗材库存
  2481. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2482. var stock_count int64
  2483. for _, it := range list {
  2484. stock_count += it.StockCount
  2485. }
  2486. stock_counts := strconv.FormatInt(stock_count, 10)
  2487. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2488. if stock_total_count == 0 {
  2489. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2490. return
  2491. }
  2492. if totals > stock_total_count {
  2493. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2494. return
  2495. }
  2496. //查找今日该患者已经出库的所有耗材
  2497. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2498. for _, item := range goodList {
  2499. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2500. var flush_count int64
  2501. for _, it := range goodListSix {
  2502. flush_count += it.StockCount
  2503. }
  2504. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2505. creater := adminInfo.AdminUser.Id
  2506. if errs != nil {
  2507. goodErrcode := models.XtGoodErrcode{
  2508. UserOrgId: item.OrgId,
  2509. Errcode: "手动出库更新剩余出库失败",
  2510. GoodId: item.GoodId,
  2511. Status: 1,
  2512. Ctime: time.Now().Unix(),
  2513. Mtime: 0,
  2514. Count: 0,
  2515. StockCount: 0,
  2516. Creater: creater,
  2517. BatchNumberId: 0,
  2518. WarehouseOutId: 0,
  2519. }
  2520. service.CreateGoodErrcode(goodErrcode)
  2521. }
  2522. }
  2523. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2524. }
  2525. //有出库记录
  2526. if len(goodWarehouseInfo) > 0 {
  2527. //查询该患者耗材的历史数据
  2528. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2529. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2530. //数量发生改变
  2531. if parsetotal != count {
  2532. //查找今日该患者已经出库的所有耗材
  2533. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2534. for _, item := range goodList {
  2535. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2536. var flush_count int64
  2537. for _, it := range goodListSix {
  2538. flush_count += it.StockCount
  2539. }
  2540. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2541. //减少出库数量
  2542. creater := adminInfo.AdminUser.Id
  2543. if errs != nil {
  2544. goodErrcode := models.XtGoodErrcode{
  2545. UserOrgId: item.OrgId,
  2546. Errcode: "手动出库更新剩余出库失败",
  2547. GoodId: item.GoodId,
  2548. Status: 1,
  2549. Ctime: time.Now().Unix(),
  2550. Mtime: 0,
  2551. Count: 0,
  2552. StockCount: 0,
  2553. Creater: creater,
  2554. BatchNumberId: 0,
  2555. WarehouseOutId: 0,
  2556. }
  2557. service.CreateGoodErrcode(goodErrcode)
  2558. }
  2559. //查询默认仓库
  2560. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2561. var total_count int64
  2562. for _, it := range stockList {
  2563. total_count += it.StockCount
  2564. }
  2565. //基础库插入数据
  2566. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2567. }
  2568. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2569. }
  2570. }
  2571. }
  2572. }
  2573. }
  2574. }
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2581. var hpInfo models.HisPrescriptionInfo
  2582. if info.ID == 0 {
  2583. var randNum int
  2584. randNum = rand.Intn(10000) + 1000
  2585. timestamp := time.Now().Unix()
  2586. tempTime := time.Unix(timestamp, 0)
  2587. timeFormat := tempTime.Format("20060102150405")
  2588. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2589. hpInfo = models.HisPrescriptionInfo{
  2590. HisPatientId: his_patient_id,
  2591. UserOrgId: adminInfo.CurrentOrgId,
  2592. RecordDate: theTime.Unix(),
  2593. PatientId: patient_id,
  2594. Status: 1,
  2595. Ctime: time.Now().Unix(),
  2596. Mtime: time.Now().Unix(),
  2597. Creator: adminInfo.AdminUser.Id,
  2598. Modifier: adminInfo.AdminUser.Id,
  2599. Diagnosis: diagnose,
  2600. SickHistory: sick_history,
  2601. Departments: department,
  2602. RegisterType: reg_type,
  2603. PrescriptionNumber: p_number,
  2604. PrescriptionStatus: 1,
  2605. Doctor: role.UserName,
  2606. DoctorId: doctor_id,
  2607. SickType: sick_type,
  2608. PType: p_type,
  2609. PatientDiagnosis: patient_diagnose,
  2610. }
  2611. service.SavePatientPrescriptionInfo(hpInfo)
  2612. //创建步骤表
  2613. finish := models.XtDialysisFinish{
  2614. IsFinish: 1,
  2615. UserOrgId: adminInfo.CurrentOrgId,
  2616. Status: 1,
  2617. Ctime: time.Now().Unix(),
  2618. Mtime: 0,
  2619. Module: 4,
  2620. RecordDate: theTime.Unix(),
  2621. Sourse: 1,
  2622. PatientId: patient_id,
  2623. }
  2624. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2625. if dialysisFinish.ID == 0 {
  2626. service.CreateDialysisFinish(finish)
  2627. }
  2628. redis := service.RedisClient()
  2629. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2630. redis.Set(key, "", time.Second)
  2631. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2632. redis.Set(keyOne, "", time.Second)
  2633. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2634. redis.Set(keySeven, "", time.Second)
  2635. defer redis.Close()
  2636. } else {
  2637. hpInfo = models.HisPrescriptionInfo{
  2638. ID: info.ID,
  2639. UserOrgId: adminInfo.CurrentOrgId,
  2640. RecordDate: info.RecordDate,
  2641. PatientId: info.PatientId,
  2642. Status: 1,
  2643. Ctime: info.Ctime,
  2644. Mtime: time.Now().Unix(),
  2645. Creator: info.Creator,
  2646. Modifier: adminInfo.AdminUser.Id,
  2647. Diagnosis: diagnose,
  2648. SickHistory: sick_history,
  2649. Departments: department,
  2650. RegisterType: reg_type,
  2651. PrescriptionNumber: info.PrescriptionNumber,
  2652. Doctor: role.UserName,
  2653. PrescriptionStatus: info.PrescriptionStatus,
  2654. DoctorId: doctor_id,
  2655. SickType: sick_type,
  2656. PType: info.PType,
  2657. HisPatientId: info.HisPatientId,
  2658. PatientDiagnosis: patient_diagnose,
  2659. }
  2660. service.SavePatientPrescriptionInfo(hpInfo)
  2661. //创建步骤表
  2662. finish := models.XtDialysisFinish{
  2663. IsFinish: 1,
  2664. UserOrgId: adminInfo.CurrentOrgId,
  2665. Status: 1,
  2666. Ctime: time.Now().Unix(),
  2667. Mtime: 0,
  2668. Module: 4,
  2669. RecordDate: info.RecordDate,
  2670. Sourse: 1,
  2671. PatientId: info.PatientId,
  2672. }
  2673. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2674. if dialysisFinish.ID == 0 {
  2675. service.CreateDialysisFinish(finish)
  2676. }
  2677. redis := service.RedisClient()
  2678. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2679. redis.Set(key, "", time.Second)
  2680. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2681. redis.Set(keyOne, "", time.Second)
  2682. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2683. redis.Set(keySeven, "", time.Second)
  2684. defer redis.Close()
  2685. }
  2686. //定义切片
  2687. var adviceList []models.HisDoctorAdviceInfo
  2688. var projectList []models.HisPrescriptionProject
  2689. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2690. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2691. var tempPrescription *models.HisPrescription
  2692. if len(prescriptions) > 0 {
  2693. for _, item := range prescriptions {
  2694. items := item.(map[string]interface{})
  2695. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2696. utils.ErrorLog("id")
  2697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2698. return
  2699. }
  2700. id := int64(items["id"].(float64))
  2701. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2702. tempPrescription = &new_prescription
  2703. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2704. utils.ErrorLog("type")
  2705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2706. return
  2707. }
  2708. types := int64(items["type"].(float64))
  2709. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2710. utils.ErrorLog("med_type")
  2711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2712. return
  2713. }
  2714. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2715. if med_type == "0" {
  2716. med_type = "14"
  2717. }
  2718. //if order_status == 0 {
  2719. // order_status = 1
  2720. //}
  2721. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2722. utils.ErrorLog("pre_time")
  2723. }
  2724. preTime, _ := items["pre_time"].(string)
  2725. timeLayout := "2006-01-02"
  2726. loc, _ := time.LoadLocation("Local")
  2727. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2728. if err != nil {
  2729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2730. return
  2731. }
  2732. pTime := theTime2.Unix()
  2733. ctime := time.Now().Unix()
  2734. if tempPrescription.ID == 0 {
  2735. prescription := &models.HisPrescription{
  2736. ID: 0,
  2737. PatientId: patient_id,
  2738. UserOrgId: adminInfo.CurrentOrgId,
  2739. RecordDate: recordDateTime,
  2740. Ctime: ctime,
  2741. Mtime: ctime,
  2742. Type: types,
  2743. Modifier: adminInfo.AdminUser.Id,
  2744. Creator: adminInfo.AdminUser.Id,
  2745. Status: 1,
  2746. Doctor: role.UserName,
  2747. HisPatientId: his_patient_id,
  2748. OrderStatus: 1,
  2749. BatchNumber: "",
  2750. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2751. PreTime: pTime,
  2752. PType: p_type,
  2753. MedType: med_type,
  2754. }
  2755. tempPrescription = prescription
  2756. service.SaveHisPrescription(tempPrescription)
  2757. redis := service.RedisClient()
  2758. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2759. redis.Set(key, "", time.Second)
  2760. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2761. redis.Set(keyOne, "", time.Second)
  2762. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2763. redis.Set(keySeven, "", time.Second)
  2764. defer redis.Close()
  2765. } else {
  2766. tempPrescription.ID = id
  2767. tempPrescription.Type = types
  2768. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2769. tempPrescription.Mtime = time.Now().Unix()
  2770. tempPrescription.Doctor = role.UserName
  2771. //tempPrescription.OrderStatus = order_status
  2772. tempPrescription.PreTime = pTime
  2773. tempPrescription.MedType = med_type
  2774. service.SaveHisPrescription(tempPrescription)
  2775. redis := service.RedisClient()
  2776. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2777. redis.Set(key, "", time.Second)
  2778. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2779. redis.Set(keyOne, "", time.Second)
  2780. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2781. redis.Set(keySeven, "", time.Second)
  2782. defer redis.Close()
  2783. }
  2784. //service.SaveHisPrescription(prescription)
  2785. //更改患者挂号状态
  2786. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2787. fmt.Println("更改失败", err2)
  2788. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2789. advices := items["advices"].([]interface{})
  2790. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2791. groupNo := int64(0)
  2792. ctime := time.Now().Unix()
  2793. mtime := ctime
  2794. if len(advices) > 0 {
  2795. for _, advice := range advices {
  2796. var s models.HisDoctorAdviceInfo
  2797. s.PrescriptionId = tempPrescription.ID
  2798. s.AdviceType = 2
  2799. s.AdviceDoctor = doctor_id
  2800. s.StopState = 2
  2801. s.ExecutionState = 2
  2802. s.AdviceDate = recordDateTime
  2803. s.Status = 1
  2804. s.UserOrgId = adminInfo.CurrentOrgId
  2805. s.RecordDate = recordDateTime
  2806. s.StartTime = tempPrescription.PreTime
  2807. s.Groupno = groupNo
  2808. s.CreatedTime = ctime
  2809. s.UpdatedTime = mtime
  2810. s.PatientId = patient_id
  2811. s.HisPatientId = his_patient_id
  2812. s.StartTime = pTime
  2813. s.IsSettle = 2
  2814. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2815. if errcode > 0 {
  2816. c.ServeFailJSONWithSGJErrorCode(errcode)
  2817. return
  2818. }
  2819. s.StartTime = pTime
  2820. var total_count int64 //处方总库存
  2821. //查询改药品信息
  2822. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2823. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2824. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2825. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2826. total_count += prescribingNumberSeven * medical.MinNumber
  2827. }
  2828. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2829. total_count += prescribingNumberSeven
  2830. }
  2831. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2832. total_count += prescribingNumberSeven
  2833. }
  2834. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2835. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2836. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2837. if s.Price != lastWarehouse.RetailPrice {
  2838. s.Price = lastWarehouse.RetailPrice
  2839. }
  2840. if s.Price == 0 {
  2841. s.Price = lastWarehouse.RetailPrice
  2842. }
  2843. }
  2844. service.CreateHisDoctorAdvice(&s)
  2845. //记录日志
  2846. byterequest, _ := json.Marshal(s)
  2847. adviceLog := models.XtDoctorAdviceLog{
  2848. UserOrgId: s.UserOrgId,
  2849. PatientId: s.PatientId,
  2850. AdminUserId: adminInfo.AdminUser.Id,
  2851. Module: 1,
  2852. ErrLog: string(byterequest),
  2853. Status: 1,
  2854. Ctime: time.Now().Unix(),
  2855. Mtime: 0,
  2856. Source: "电脑端新建his医嘱",
  2857. RecordDate: s.AdviceDate,
  2858. }
  2859. service.CreateDoctorAdviceLog(adviceLog)
  2860. //存储切片中
  2861. adviceList = append(adviceList, s)
  2862. redis := service.RedisClient()
  2863. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2864. redis.Set(key, "", time.Second)
  2865. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2866. redis.Set(keyOne, "", time.Second)
  2867. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2868. redis.Set(keySeven, "", time.Second)
  2869. var randNum int
  2870. randNum = rand.Intn(10000) + 1000
  2871. timestamp := time.Now().Unix()
  2872. tempTime := time.Unix(timestamp, 0)
  2873. timeFormat := tempTime.Format("20060102150405")
  2874. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2875. service.CreateHisDoctorAdvice(&s)
  2876. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2877. redis.Set(keySix, "", time.Second)
  2878. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2879. redis.Set(keyFive, "", time.Second)
  2880. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2881. redis.Set(keyEight, "", time.Second)
  2882. defer redis.Close()
  2883. }
  2884. }
  2885. }
  2886. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2887. projects := items["project"].([]interface{})
  2888. if len(projects) > 0 {
  2889. for _, project := range projects {
  2890. var p models.HisPrescriptionProject
  2891. p.PrescriptionId = tempPrescription.ID
  2892. p.Ctime = time.Now().Unix()
  2893. p.Mtime = time.Now().Unix()
  2894. p.PatientId = patient_id
  2895. p.RecordDate = recordDateTime
  2896. p.Doctor = doctor_id
  2897. p.UserOrgId = adminInfo.CurrentOrgId
  2898. p.HisPatientId = his_patient_id
  2899. p.Status = 1
  2900. p.StartTime = pTime
  2901. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2902. if errcode > 0 {
  2903. c.ServeFailJSONWithSGJErrorCode(errcode)
  2904. return
  2905. }
  2906. if p.ID == 0 {
  2907. p.IsOut = 2
  2908. }
  2909. if p.ID > 0 {
  2910. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2911. p.IsOut = projectDetail.IsOut
  2912. }
  2913. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2914. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2915. if p.Type == 3 {
  2916. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2917. if p.Price != lastWarehouse.PackingPrice {
  2918. p.Price = lastWarehouse.PackingPrice
  2919. }
  2920. if p.Unit == "" {
  2921. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2922. p.Unit = goodInfoOne.PackingUnit
  2923. }
  2924. }
  2925. }
  2926. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2927. //
  2928. // if p.Type == 3 {
  2929. // //查询该耗材是否停用
  2930. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2931. // //表示该耗材已经停用,不能保存
  2932. // if goodInfoSeven.ID == 0 {
  2933. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2934. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2935. // return
  2936. // }
  2937. // }
  2938. //
  2939. //}
  2940. service.CreateHisProjectTwo(&p)
  2941. //记录日志
  2942. byterequest, _ := json.Marshal(p)
  2943. adviceLog := models.XtDoctorAdviceLog{
  2944. UserOrgId: p.UserOrgId,
  2945. PatientId: p.PatientId,
  2946. AdminUserId: adminInfo.AdminUser.Id,
  2947. Module: 1,
  2948. ErrLog: string(byterequest),
  2949. Status: 1,
  2950. Ctime: time.Now().Unix(),
  2951. Mtime: 0,
  2952. Source: "电脑端新建his项目",
  2953. RecordDate: p.RecordDate,
  2954. }
  2955. service.CreateDoctorAdviceLog(adviceLog)
  2956. projectList = append(projectList, p)
  2957. var randNum int
  2958. randNum = rand.Intn(10000) + 1000
  2959. timestamp := time.Now().Unix()
  2960. tempTime := time.Unix(timestamp, 0)
  2961. timeFormat := tempTime.Format("20060102150405")
  2962. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2963. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2964. //新增或者编辑项目,修改对应的标签数据
  2965. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2966. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2967. var label models.HisLabelPrintInfo
  2968. project, _ := service.GetProjectDetail(p.ProjectId)
  2969. if project.CostClassify == 3 { //类别为检验检查
  2970. if p.TeamId > 0 { //检验检查组套
  2971. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2972. if tempLabel.ID == 0 {
  2973. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2974. label.Number = tempPrescription.PrescriptionNumber
  2975. label.ProjectId = project.ID
  2976. label.Status = 1
  2977. label.IsPrint = 2
  2978. label.DoctorId = info.DoctorId
  2979. label.UserOrgId = p.UserOrgId
  2980. label.PatientId = patient_id
  2981. label.RecordDate = recordDateTime
  2982. label.Ctime = time.Now().Unix()
  2983. label.Mtime = time.Now().Unix()
  2984. label.ItemId = p.TeamId
  2985. label.FeedetlSn = p.FeedetlSn
  2986. label.PProjectId = p.ID
  2987. label.ProjectName = team.ProjectTeam
  2988. label.PatientName = patient.Name
  2989. service.CreateHisLabelRecord(&label)
  2990. }
  2991. } else { //单条检验检查项目
  2992. label.Number = tempPrescription.PrescriptionNumber
  2993. label.ProjectId = project.ID
  2994. label.Status = 1
  2995. label.DoctorId = info.DoctorId
  2996. label.UserOrgId = p.UserOrgId
  2997. label.PatientId = patient_id
  2998. label.RecordDate = recordDateTime
  2999. label.IsPrint = 2
  3000. label.Ctime = time.Now().Unix()
  3001. label.Mtime = time.Now().Unix()
  3002. label.FeedetlSn = p.FeedetlSn
  3003. label.PProjectId = p.ID
  3004. label.ItemId = p.TeamId
  3005. label.ProjectName = project.ProjectName
  3006. label.PatientName = patient.Name
  3007. service.CreateHisLabelRecord(&label)
  3008. }
  3009. }
  3010. }
  3011. }
  3012. service.SaveHisProjectTwo(&p)
  3013. }
  3014. }
  3015. }
  3016. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3017. // addition := items["addition"].([]interface{})
  3018. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3019. // ctime := time.Now().Unix()
  3020. // mtime := ctime
  3021. // if len(addition) > 0 {
  3022. // for _, item := range addition {
  3023. // var s models.HisAdditionalCharge
  3024. // s.PrescriptionId = tempPrescription.ID
  3025. // s.Status = 1
  3026. // s.UserOrgId = adminInfo.CurrentOrgId
  3027. // s.RecordDate = recordDateTime
  3028. // s.CreatedTime = ctime
  3029. // s.UpdatedTime = mtime
  3030. // s.PatientId = patient_id
  3031. // s.HisPatientId = his_patient_id
  3032. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3033. // if errcode > 0 {
  3034. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3035. // return
  3036. // }
  3037. // service.CreateAdditionalCharge(&s)
  3038. // var randNum int
  3039. // randNum = rand.Intn(10000) + 1000
  3040. // timestamp := time.Now().Unix()
  3041. // tempTime := time.Unix(timestamp, 0)
  3042. // timeFormat := tempTime.Format("20060102150405")
  3043. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3044. // service.CreateAdditionalCharge(&s)
  3045. //
  3046. // }
  3047. // }
  3048. //}
  3049. }
  3050. }
  3051. //查询今日该患者开的药品处方
  3052. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3053. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3054. //药品出库
  3055. if drugOutConfig.IsOpen == 1 {
  3056. for _, item := range hisdoctorlist {
  3057. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3058. // 查询该药品最后一次出库记录
  3059. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3060. if len(druginfo) > 0 {
  3061. //回退库存
  3062. for _, it := range druginfo {
  3063. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3064. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3065. }
  3066. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3067. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3068. }
  3069. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3070. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3071. }
  3072. }
  3073. }
  3074. //删除记录
  3075. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3076. //查询最后一次数据
  3077. if drugOutConfig.IsOpen == 1 {
  3078. //出库
  3079. if drug.IsUse == 2 {
  3080. creater := adminInfo.AdminUser.Id
  3081. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3082. }
  3083. //更新字典里面的库存
  3084. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3085. var sum_count int64
  3086. for _, its := range stockInfo {
  3087. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3088. if its.MaxUnit == baseDrug.MaxUnit {
  3089. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3090. }
  3091. sum_count += its.StockMaxNumber + its.StockMinNumber
  3092. }
  3093. //更新基础库存
  3094. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3095. //剩余库存
  3096. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3097. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3098. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3099. }
  3100. }
  3101. }
  3102. //耗材保存处方出库
  3103. if goodOutConfig.IsOpen == 1 {
  3104. //查询今日耗材出库数量
  3105. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3106. for _, item := range hisgoodlist {
  3107. //查询历史出库数据
  3108. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3109. var out_count_five int64
  3110. for _, item := range flowGood {
  3111. out_count_five += item.Count
  3112. }
  3113. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3114. if out_count_five != parseIntCount {
  3115. //查询耗材最后一次出库记录
  3116. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3117. //查询默认出库仓库库存
  3118. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3119. if len(wareOut) > 0 {
  3120. for _, it := range wareOut {
  3121. //回退库存
  3122. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3123. //删除出库记录
  3124. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3125. }
  3126. }
  3127. timeStr := time.Now().Format("2006-01-02")
  3128. timeArr := strings.Split(timeStr, "-")
  3129. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3130. total = total + 1
  3131. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3132. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3133. number = number + total
  3134. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3135. operation_time := time.Now().Unix()
  3136. creater := c.GetAdminUserInfo().AdminUser.Id
  3137. recordDateStr := time.Now().Format("2006-01-02")
  3138. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3139. nowtime := recordDate.Unix()
  3140. warehouseOut := models.WarehouseOut{
  3141. WarehouseOutOrderNumber: warehousing_out_order,
  3142. OperationTime: operation_time,
  3143. OrgId: adminInfo.CurrentOrgId,
  3144. Creater: creater,
  3145. Ctime: time.Now().Unix(),
  3146. Status: 1,
  3147. WarehouseOutTime: nowtime,
  3148. Type: 1,
  3149. StorehouseId: storeConfig.StorehouseOutInfo,
  3150. IsCheck: 1,
  3151. IsSys: 1,
  3152. }
  3153. //查询是否生成出库单
  3154. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3155. if out.ID == 0 {
  3156. service.AddSigleWarehouseOut(&warehouseOut)
  3157. }
  3158. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3159. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3160. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3161. dialyPrepareOne := models.DialysisBeforePrepare{
  3162. GoodTypeId: goodObj.GoodTypeId,
  3163. GoodId: item.ProjectId,
  3164. PatientId: item.PatientId,
  3165. RecordDate: item.RecordDate,
  3166. UserOrgId: adminInfo.CurrentOrgId,
  3167. Count: parseIntCount,
  3168. Ctime: time.Now().Unix(),
  3169. Creater: creater,
  3170. Status: 1,
  3171. StorehouseId: houseConfig.StorehouseOutInfo,
  3172. ProjectId: item.ID,
  3173. }
  3174. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3175. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3176. //查询历史出库数据
  3177. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3178. var out_count int64
  3179. for _, item := range flowGood {
  3180. out_count += item.Count
  3181. }
  3182. //如果历史数和当前数据不想等才进行退库出库
  3183. if out_count != parseIntCount {
  3184. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3185. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3186. detail := models.AutomaticReduceDetail{
  3187. WarehouseOutId: 0,
  3188. WarehouseOutOrderNumber: "",
  3189. PatientId: item.PatientId,
  3190. Ctime: time.Now().Unix(),
  3191. Mtime: 0,
  3192. Status: 1,
  3193. RecordTime: item.RecordDate,
  3194. OrgId: item.UserOrgId,
  3195. GoodId: item.ProjectId,
  3196. GoodTypeId: 0,
  3197. Count: parseIntCount,
  3198. Type: 0,
  3199. ProjectId: item.ID,
  3200. StorehouseId: 0,
  3201. }
  3202. service.CreateAutoDetail(detail)
  3203. //查询剩余库存
  3204. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3205. var sum_count int64
  3206. for _, item := range goodList {
  3207. sum_count += item.StockCount
  3208. }
  3209. //更新剩余库存
  3210. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3211. //耗材
  3212. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3213. }
  3214. }
  3215. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3216. //查询历史出库数据
  3217. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3218. var out_count int64
  3219. for _, item := range flowGood {
  3220. out_count += item.Count
  3221. }
  3222. //如果历史数和当前数据不想等才进行退库出库
  3223. if out_count != parseIntCount {
  3224. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3225. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3226. detail := models.AutomaticReduceDetail{
  3227. WarehouseOutId: 0,
  3228. WarehouseOutOrderNumber: "",
  3229. PatientId: item.PatientId,
  3230. Ctime: time.Now().Unix(),
  3231. Mtime: 0,
  3232. Status: 1,
  3233. RecordTime: item.RecordDate,
  3234. OrgId: item.UserOrgId,
  3235. GoodId: item.ProjectId,
  3236. GoodTypeId: 0,
  3237. Count: parseIntCount,
  3238. Type: 0,
  3239. ProjectId: item.ID,
  3240. StorehouseId: 0,
  3241. }
  3242. service.CreateAutoDetail(detail)
  3243. //查询剩余库存
  3244. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3245. var sum_count int64
  3246. for _, item := range goodList {
  3247. sum_count += item.StockCount
  3248. }
  3249. //更新剩余库存
  3250. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3251. //耗材
  3252. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3253. }
  3254. }
  3255. }
  3256. }
  3257. }
  3258. }
  3259. //redisClient := service.RedisClient()
  3260. //defer redisClient.Close()
  3261. //
  3262. //list := models.HisList{
  3263. // Patient_id: patient_id,
  3264. // Advice_id:0,
  3265. // Record_date: 0,
  3266. // Advice: adviceList,
  3267. // Project: nil,
  3268. //}
  3269. //hisLis = append(hisLis, list)
  3270. //
  3271. //advice_json, _ := json.Marshal(&hisLis)
  3272. //redisClient.RPush("111", advice_json).Result()
  3273. //result, _ := redisClient.RPop("111").Result()
  3274. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3275. //
  3276. //var dat []map[string]interface{}
  3277. //json.Unmarshal([]byte(result), &dat)
  3278. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3279. //
  3280. //for k,v:=range dat{
  3281. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3282. //}
  3283. //project_json, _ := json.Marshal(&projectList)
  3284. //redisClient.LPush("222", project_json).Result()
  3285. if err == nil {
  3286. c.ServeSuccessJSON(map[string]interface{}{
  3287. "msg": "保存成功",
  3288. })
  3289. return
  3290. } else {
  3291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3292. return
  3293. }
  3294. }
  3295. func (c *HisApiController) EditHisPrescription() {
  3296. record_date := c.GetString("record_date")
  3297. patient_id, _ := c.GetInt64("patient_id")
  3298. reg_type, _ := c.GetInt64("reg_type")
  3299. //diagnose, _ := c.GetInt64("diagnose", 0)
  3300. diagnose := c.GetString("diagnose")
  3301. sick_type, _ := c.GetInt64("sick_type")
  3302. sick_history := c.GetString("sick_history")
  3303. doctor_id, _ := c.GetInt64("doctor", 0)
  3304. department, _ := c.GetInt64("department", 0)
  3305. his_patient_id, _ := c.GetInt64("his_patient_id")
  3306. p_type, _ := c.GetInt64("p_type")
  3307. dataBody := make(map[string]interface{}, 0)
  3308. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3309. if err != nil {
  3310. utils.ErrorLog(err.Error())
  3311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3312. return
  3313. }
  3314. timeLayout := "2006-01-02"
  3315. loc, _ := time.LoadLocation("Local")
  3316. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3317. if err != nil {
  3318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3319. return
  3320. }
  3321. adminInfo := c.GetAdminUserInfo()
  3322. recordDateTime := theTime.Unix()
  3323. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3324. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3325. var hpInfo models.HisPrescriptionInfo
  3326. if info.ID == 0 {
  3327. var randNum int
  3328. randNum = rand.Intn(10000) + 1000
  3329. timestamp := time.Now().Unix()
  3330. tempTime := time.Unix(timestamp, 0)
  3331. timeFormat := tempTime.Format("20060102150405")
  3332. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3333. hpInfo = models.HisPrescriptionInfo{
  3334. UserOrgId: adminInfo.CurrentOrgId,
  3335. RecordDate: theTime.Unix(),
  3336. PatientId: patient_id,
  3337. Status: 1,
  3338. Ctime: time.Now().Unix(),
  3339. Mtime: time.Now().Unix(),
  3340. Creator: adminInfo.AdminUser.Id,
  3341. Modifier: adminInfo.AdminUser.Id,
  3342. Diagnosis: diagnose,
  3343. SickHistory: sick_history,
  3344. Departments: department,
  3345. RegisterType: reg_type,
  3346. PrescriptionNumber: p_number,
  3347. PrescriptionStatus: 1,
  3348. Doctor: role.UserName,
  3349. DoctorId: doctor_id,
  3350. SickType: sick_type,
  3351. PType: p_type,
  3352. }
  3353. service.SavePatientPrescriptionInfo(hpInfo)
  3354. } else {
  3355. hpInfo = models.HisPrescriptionInfo{
  3356. ID: info.ID,
  3357. UserOrgId: adminInfo.CurrentOrgId,
  3358. RecordDate: info.RecordDate,
  3359. PatientId: info.PatientId,
  3360. Status: 1,
  3361. Ctime: info.Ctime,
  3362. Mtime: time.Now().Unix(),
  3363. Creator: info.Creator,
  3364. Modifier: adminInfo.AdminUser.Id,
  3365. Diagnosis: diagnose,
  3366. SickHistory: sick_history,
  3367. Departments: department,
  3368. RegisterType: reg_type,
  3369. PrescriptionNumber: info.PrescriptionNumber,
  3370. Doctor: role.UserName,
  3371. PrescriptionStatus: info.PrescriptionStatus,
  3372. DoctorId: doctor_id,
  3373. SickType: sick_type,
  3374. PType: info.PType,
  3375. }
  3376. service.SavePatientPrescriptionInfo(hpInfo)
  3377. }
  3378. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3379. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3380. if len(prescriptions) > 0 {
  3381. for _, item := range prescriptions {
  3382. items := item.(map[string]interface{})
  3383. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3384. utils.ErrorLog("id")
  3385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3386. return
  3387. }
  3388. id := int64(items["id"].(float64))
  3389. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3390. utils.ErrorLog("type")
  3391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3392. return
  3393. }
  3394. types := int64(items["type"].(float64))
  3395. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3396. utils.ErrorLog("med_type")
  3397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3398. return
  3399. }
  3400. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3401. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3402. ctime := time.Now().Unix()
  3403. prescription := &models.HisPrescription{
  3404. ID: id,
  3405. PatientId: patient_id,
  3406. UserOrgId: adminInfo.CurrentOrgId,
  3407. RecordDate: recordDateTime,
  3408. Ctime: ctime,
  3409. Mtime: ctime,
  3410. Type: types,
  3411. Modifier: adminInfo.AdminUser.Id,
  3412. Creator: adminInfo.AdminUser.Id,
  3413. Status: 1,
  3414. Doctor: role.UserName,
  3415. HisPatientId: his_patient_id,
  3416. OrderStatus: 1,
  3417. BatchNumber: "",
  3418. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3419. PType: hpInfo.PType,
  3420. MedType: med_type,
  3421. }
  3422. if historyPrescription.ID > 0 {
  3423. prescription.PreTime = historyPrescription.PreTime
  3424. }
  3425. service.SaveHisPrescription(prescription)
  3426. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3427. advices := items["advices"].([]interface{})
  3428. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3429. groupNo := int64(0)
  3430. ctime := time.Now().Unix()
  3431. mtime := ctime
  3432. if len(advices) > 0 {
  3433. for _, advice := range advices {
  3434. var s models.HisDoctorAdviceInfo
  3435. s.PrescriptionId = prescription.ID
  3436. s.AdviceType = 2
  3437. s.AdviceDoctor = adminInfo.AdminUser.Id
  3438. s.StopState = 2
  3439. s.ExecutionState = 2
  3440. s.AdviceDate = recordDateTime
  3441. s.Status = 1
  3442. s.UserOrgId = adminInfo.CurrentOrgId
  3443. s.RecordDate = recordDateTime
  3444. s.StartTime = prescription.PreTime
  3445. s.Groupno = groupNo
  3446. s.CreatedTime = ctime
  3447. s.UpdatedTime = mtime
  3448. s.PatientId = patient_id
  3449. s.HisPatientId = his_patient_id
  3450. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3451. if errcode > 0 {
  3452. c.ServeFailJSONWithSGJErrorCode(errcode)
  3453. return
  3454. }
  3455. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3456. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3457. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3458. if s.Price == 0 {
  3459. s.Price = lastWarehouse.RetailPrice
  3460. }
  3461. }
  3462. service.CreateHisDoctorAdvice(&s)
  3463. //记录日志
  3464. byterequest, _ := json.Marshal(s)
  3465. adviceLog := models.XtDoctorAdviceLog{
  3466. UserOrgId: s.UserOrgId,
  3467. PatientId: s.PatientId,
  3468. AdminUserId: adminInfo.AdminUser.Id,
  3469. Module: 1,
  3470. ErrLog: string(byterequest),
  3471. Status: 1,
  3472. Ctime: time.Now().Unix(),
  3473. Mtime: 0,
  3474. Source: "电脑端his医嘱修改",
  3475. RecordDate: s.AdviceDate,
  3476. }
  3477. service.CreateDoctorAdviceLog(adviceLog)
  3478. redis := service.RedisClient()
  3479. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3480. redis.Set(key, "", time.Second)
  3481. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3482. fmt.Println("keyOne", keyOne)
  3483. redis.Set(keyOne, "", time.Second)
  3484. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3485. redis.Set(keySeven, "", time.Second)
  3486. redis.Close()
  3487. }
  3488. }
  3489. }
  3490. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3491. projects := items["project"].([]interface{})
  3492. if len(projects) > 0 {
  3493. for _, project := range projects {
  3494. var p models.HisPrescriptionProject
  3495. p.PrescriptionId = prescription.ID
  3496. p.Ctime = time.Now().Unix()
  3497. p.Mtime = time.Now().Unix()
  3498. p.PatientId = patient_id
  3499. p.RecordDate = recordDateTime
  3500. p.UserOrgId = adminInfo.CurrentOrgId
  3501. p.HisPatientId = his_patient_id
  3502. p.Status = 1
  3503. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3504. if errcode > 0 {
  3505. c.ServeFailJSONWithSGJErrorCode(errcode)
  3506. return
  3507. }
  3508. service.CreateHisProjectTwo(&p)
  3509. //记录日志
  3510. byterequest, _ := json.Marshal(p)
  3511. adviceLog := models.XtDoctorAdviceLog{
  3512. UserOrgId: p.UserOrgId,
  3513. PatientId: p.PatientId,
  3514. AdminUserId: adminInfo.AdminUser.Id,
  3515. Module: 1,
  3516. ErrLog: string(byterequest),
  3517. Status: 1,
  3518. Ctime: time.Now().Unix(),
  3519. Mtime: 0,
  3520. Source: "电脑端his项目修改",
  3521. RecordDate: p.RecordDate,
  3522. }
  3523. service.CreateDoctorAdviceLog(adviceLog)
  3524. }
  3525. }
  3526. }
  3527. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3528. addition := items["addition"].([]interface{})
  3529. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3530. ctime := time.Now().Unix()
  3531. mtime := ctime
  3532. if len(addition) > 0 {
  3533. for _, item := range addition {
  3534. var s models.HisAdditionalCharge
  3535. s.PrescriptionId = prescription.ID
  3536. s.Status = 1
  3537. s.UserOrgId = adminInfo.CurrentOrgId
  3538. s.RecordDate = recordDateTime
  3539. s.CreatedTime = ctime
  3540. s.UpdatedTime = mtime
  3541. s.PatientId = patient_id
  3542. s.HisPatientId = his_patient_id
  3543. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3544. if errcode > 0 {
  3545. c.ServeFailJSONWithSGJErrorCode(errcode)
  3546. return
  3547. }
  3548. service.CreateAdditionalCharge(&s)
  3549. }
  3550. }
  3551. }
  3552. }
  3553. }
  3554. }
  3555. if err == nil {
  3556. c.ServeSuccessJSON(map[string]interface{}{
  3557. "msg": "保存成功",
  3558. })
  3559. return
  3560. } else {
  3561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3562. return
  3563. }
  3564. }
  3565. func (c *HisApiController) DeletePrescription() {
  3566. prescription_id, _ := c.GetInt64("id")
  3567. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3568. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3569. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3570. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3571. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3572. //耗材保存处方出库
  3573. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3574. //已收费和已发药限制逻辑
  3575. isCharge := false
  3576. isMedicine := false
  3577. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3578. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3579. for _, item := range new_prescriptions {
  3580. if item.IsMedicine == 1 {
  3581. isMedicine = true
  3582. }
  3583. }
  3584. for _, item := range new_prescriptions {
  3585. if item.OrderStatus == 4 {
  3586. isCharge = true
  3587. }
  3588. }
  3589. if p_err != nil {
  3590. if new_prescription.ID > 0 {
  3591. if new_prescription.OrderStatus == 2 {
  3592. isCharge = true
  3593. }
  3594. }
  3595. }
  3596. for _, item := range advices {
  3597. if item.IsMedicine == 1 {
  3598. isMedicine = true
  3599. }
  3600. }
  3601. if isCharge {
  3602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3603. return
  3604. }
  3605. if isMedicine {
  3606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3607. return
  3608. }
  3609. //已收费和已发药限制逻辑
  3610. if len(projects) > 0 {
  3611. for _, item := range projects {
  3612. service.DeletePrintInfo(item.ID) //删除打印信息
  3613. if goodOutConfig.IsOpen != 1 {
  3614. if stockConfig.IsOpen == 1 {
  3615. if item.Type == 3 && item.IsOut == 1 {
  3616. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3617. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3618. good.Total = good.Total + f_count
  3619. service.UpdateGoodInfo(&good)
  3620. operation_time := time.Now().Unix()
  3621. creater := c.GetAdminUserInfo().AdminUser.Id
  3622. //创建退库单
  3623. timeStr := time.Now().Format("2006-01-02")
  3624. timeArr := strings.Split(timeStr, "-")
  3625. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3626. total = total + 1
  3627. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3628. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3629. cancelStock := models.CancelStock{
  3630. OrderNumber: orderNumber,
  3631. OperaTime: operation_time,
  3632. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3633. Creater: creater,
  3634. Ctime: time.Now().Unix(),
  3635. Status: 1,
  3636. ReturnTime: item.RecordDate,
  3637. Type: 1,
  3638. StorehouseId: houseConfig.StorehouseOutInfo,
  3639. IsCheck: 1,
  3640. }
  3641. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3642. if msgerrkonde == gorm.ErrRecordNotFound {
  3643. service.AddSigleCancelStock(&cancelStock)
  3644. }
  3645. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3646. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3647. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3648. //查询该耗材是否出库
  3649. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3650. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3651. deaerler, _ := service.GetDealerById(info.Dealer)
  3652. var total_count int64
  3653. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3654. total_count += count
  3655. if info.ID > 0 {
  3656. if info.Count >= total_count {
  3657. //回退库存
  3658. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3659. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3660. var flush_count int64
  3661. for _, it := range goodList {
  3662. flush_count += it.StockCount
  3663. }
  3664. cancelStockInfo := models.CancelStockInfo{
  3665. GoodId: item.ProjectId,
  3666. CancelStockId: cancel.ID,
  3667. GoodTypeId: good.GoodTypeId,
  3668. Count: prescribingNumber,
  3669. Price: info.Price,
  3670. Total: 0,
  3671. ProductDate: info.ProductDate,
  3672. ExpiryDate: info.ExpiryDate,
  3673. Ctime: time.Now().Unix(),
  3674. Status: 1,
  3675. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3676. OrderNumber: cancel.OrderNumber,
  3677. Type: 0,
  3678. Dealer: deaerler.DealerName,
  3679. Manufacturer: manufacturer.ManufacturerName,
  3680. Number: info.Number,
  3681. RegisterAccount: "",
  3682. Remark: "",
  3683. WarehouseInfoId: info.WarehouseInfotId,
  3684. PatientId: info.PatientId,
  3685. RecordDate: info.SysRecordTime,
  3686. StorehouseId: houseConfig.StorehouseOutInfo,
  3687. IsCheck: 1,
  3688. }
  3689. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3690. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3691. flow := models.VmStockFlow{
  3692. WarehousingId: info.WarehouseInfotId,
  3693. GoodId: item.ProjectId,
  3694. Number: info.Number,
  3695. LicenseNumber: info.LicenseNumber,
  3696. Count: prescribingNumber,
  3697. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3698. PatientId: item.PatientId,
  3699. SystemTime: info.SysRecordTime,
  3700. ConsumableType: 7,
  3701. IsSys: 0,
  3702. WarehousingOrder: "",
  3703. WarehouseOutId: info.WarehouseOutId,
  3704. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3705. IsEdit: 0,
  3706. CancelStockId: cancel.ID,
  3707. CancelOrderNumber: cancel.OrderNumber,
  3708. Manufacturer: manufacturer.ID,
  3709. Dealer: 0,
  3710. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3711. UpdateCreator: 0,
  3712. Status: 1,
  3713. Ctime: time.Now().Unix(),
  3714. Mtime: 0,
  3715. Price: info.Price,
  3716. WarehousingDetailId: info.WarehouseInfotId,
  3717. WarehouseOutDetailId: info.ID,
  3718. CancelOutDetailId: cancelInfo.ID,
  3719. ProductDate: info.ProductDate,
  3720. ExpireDate: info.ExpiryDate,
  3721. StorehouseId: houseConfig.StorehouseOutInfo,
  3722. OverCount: flush_count,
  3723. }
  3724. service.CreateStockFlowOne(flow)
  3725. //退库数量增加
  3726. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3727. //出库数量减少
  3728. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3729. }
  3730. if info.Count < total_count {
  3731. //回退库存
  3732. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3733. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3734. var flush_count int64
  3735. for _, it := range goodList {
  3736. flush_count += it.StockCount
  3737. }
  3738. cancelStockInfo := models.CancelStockInfo{
  3739. GoodId: item.ProjectId,
  3740. CancelStockId: cancel.ID,
  3741. GoodTypeId: good.GoodTypeId,
  3742. Count: info.Count,
  3743. Price: info.Price,
  3744. Total: 0,
  3745. ProductDate: info.ProductDate,
  3746. ExpiryDate: info.ExpiryDate,
  3747. Ctime: time.Now().Unix(),
  3748. Status: 1,
  3749. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3750. OrderNumber: cancel.OrderNumber,
  3751. Type: 0,
  3752. Dealer: deaerler.DealerName,
  3753. Manufacturer: manufacturer.ManufacturerName,
  3754. Number: info.Number,
  3755. RegisterAccount: "",
  3756. Remark: "",
  3757. WarehouseInfoId: info.WarehouseInfotId,
  3758. PatientId: info.PatientId,
  3759. RecordDate: info.SysRecordTime,
  3760. StorehouseId: houseConfig.StorehouseOutInfo,
  3761. IsCheck: 1,
  3762. }
  3763. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3764. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3765. flow := models.VmStockFlow{
  3766. WarehousingId: info.WarehouseInfotId,
  3767. GoodId: item.ProjectId,
  3768. Number: info.Number,
  3769. LicenseNumber: info.LicenseNumber,
  3770. Count: info.Count,
  3771. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3772. PatientId: item.PatientId,
  3773. SystemTime: info.SysRecordTime,
  3774. ConsumableType: 7,
  3775. IsSys: 0,
  3776. WarehousingOrder: "",
  3777. WarehouseOutId: info.WarehouseOutId,
  3778. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3779. IsEdit: 0,
  3780. CancelStockId: cancel.ID,
  3781. CancelOrderNumber: cancel.OrderNumber,
  3782. Manufacturer: manufacturer.ID,
  3783. Dealer: 0,
  3784. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3785. UpdateCreator: 0,
  3786. Status: 1,
  3787. Ctime: time.Now().Unix(),
  3788. Mtime: 0,
  3789. Price: info.Price,
  3790. WarehousingDetailId: info.WarehouseInfotId,
  3791. WarehouseOutDetailId: info.ID,
  3792. CancelOutDetailId: cancelInfo.ID,
  3793. ProductDate: info.ProductDate,
  3794. ExpireDate: info.ExpiryDate,
  3795. StorehouseId: houseConfig.StorehouseOutInfo,
  3796. OverCount: flush_count,
  3797. }
  3798. service.CreateStockFlowOne(flow)
  3799. //退库数量增加
  3800. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3801. //出库数量减少
  3802. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3803. }
  3804. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3805. var flush_count int64
  3806. for _, it := range goodList {
  3807. flush_count += it.StockCount
  3808. }
  3809. //查询已出库数量
  3810. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3811. if prescribingNumber < dialysisInfo.Count {
  3812. //改变数量
  3813. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3814. }
  3815. if prescribingNumber >= dialysisInfo.Count {
  3816. //删除出库表
  3817. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3818. }
  3819. //更新库存
  3820. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3821. //更新基础库库存
  3822. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3823. }
  3824. }
  3825. }
  3826. }
  3827. //保存耗材出库
  3828. if goodOutConfig.IsOpen == 1 {
  3829. if item.Type == 3 {
  3830. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3831. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3832. good.Total = good.Total + f_count
  3833. service.UpdateGoodInfo(&good)
  3834. operation_time := time.Now().Unix()
  3835. creater := c.GetAdminUserInfo().AdminUser.Id
  3836. //创建退库单
  3837. timeStr := time.Now().Format("2006-01-02")
  3838. timeArr := strings.Split(timeStr, "-")
  3839. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3840. total = total + 1
  3841. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3842. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3843. cancelStock := models.CancelStock{
  3844. OrderNumber: orderNumber,
  3845. OperaTime: operation_time,
  3846. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3847. Creater: creater,
  3848. Ctime: time.Now().Unix(),
  3849. Status: 1,
  3850. ReturnTime: item.RecordDate,
  3851. Type: 1,
  3852. StorehouseId: houseConfig.StorehouseOutInfo,
  3853. IsCheck: 1,
  3854. }
  3855. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3856. if msgerrkonde == gorm.ErrRecordNotFound {
  3857. service.AddSigleCancelStock(&cancelStock)
  3858. }
  3859. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3860. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3861. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3862. //查询该耗材是否出库
  3863. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3864. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3865. deaerler, _ := service.GetDealerById(info.Dealer)
  3866. var total_count int64
  3867. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3868. total_count += count
  3869. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3870. var flush_count int64
  3871. for _, it := range goodList {
  3872. flush_count += it.StockCount
  3873. }
  3874. fmt.Println("历史出库数据", info.Count)
  3875. fmt.Println("出库数量", total_count)
  3876. if info.ID > 0 {
  3877. cancelStockInfo := models.CancelStockInfo{
  3878. GoodId: item.ProjectId,
  3879. CancelStockId: cancel.ID,
  3880. GoodTypeId: good.GoodTypeId,
  3881. Count: prescribingNumber,
  3882. Price: info.Price,
  3883. Total: 0,
  3884. ProductDate: info.ProductDate,
  3885. ExpiryDate: info.ExpiryDate,
  3886. Ctime: time.Now().Unix(),
  3887. Status: 1,
  3888. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3889. OrderNumber: cancel.OrderNumber,
  3890. Type: 0,
  3891. Dealer: deaerler.DealerName,
  3892. Manufacturer: manufacturer.ManufacturerName,
  3893. Number: info.Number,
  3894. RegisterAccount: "",
  3895. Remark: "",
  3896. WarehouseInfoId: info.WarehouseInfotId,
  3897. PatientId: info.PatientId,
  3898. RecordDate: info.SysRecordTime,
  3899. StorehouseId: houseConfig.StorehouseOutInfo,
  3900. IsCheck: 1,
  3901. }
  3902. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3903. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3904. //查询出库数量
  3905. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3906. //出库数据 大于 退库数量
  3907. if len(list) > 0 {
  3908. for _, it := range list {
  3909. //回退库存
  3910. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3911. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3912. var flush_count_one int64
  3913. for _, it := range goodList {
  3914. flush_count_one += it.StockCount
  3915. }
  3916. //查询该批次是否有退库数据
  3917. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3918. creater := c.GetAdminUserInfo().AdminUser.Id
  3919. flow := models.VmStockFlow{
  3920. WarehousingId: it.WarehouseInfotId,
  3921. GoodId: it.GoodId,
  3922. Number: it.Number,
  3923. LicenseNumber: it.LicenseNumber,
  3924. Count: it.Count,
  3925. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3926. PatientId: it.PatientId,
  3927. SystemTime: it.SysRecordTime,
  3928. ConsumableType: 7,
  3929. IsSys: 0,
  3930. WarehousingOrder: "",
  3931. WarehouseOutId: it.WarehouseOutId,
  3932. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3933. IsEdit: 0,
  3934. CancelStockId: cancel.ID,
  3935. CancelOrderNumber: cancel.OrderNumber,
  3936. Manufacturer: manufacturer.ID,
  3937. Dealer: 0,
  3938. Creator: creater,
  3939. UpdateCreator: 0,
  3940. Status: 1,
  3941. Ctime: time.Now().Unix(),
  3942. Mtime: 0,
  3943. Price: it.Price,
  3944. WarehousingDetailId: it.WarehouseInfotId,
  3945. WarehouseOutDetailId: it.ID,
  3946. CancelOutDetailId: cancelInfo.ID,
  3947. ProductDate: it.ProductDate,
  3948. ExpireDate: it.ExpiryDate,
  3949. StorehouseId: houseConfig.StorehouseOutInfo,
  3950. OverCount: flush_count_one,
  3951. }
  3952. service.CreateStockFlowOne(flow)
  3953. //if flow.ID > 0 {
  3954. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3955. //}
  3956. }
  3957. }
  3958. //flow := models.VmStockFlow{
  3959. // WarehousingId: info.WarehouseInfotId,
  3960. // GoodId: item.ProjectId,
  3961. // Number: info.Number,
  3962. // LicenseNumber: info.LicenseNumber,
  3963. // Count: prescribingNumber,
  3964. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3965. // PatientId: item.PatientId,
  3966. // SystemTime: info.SysRecordTime,
  3967. // ConsumableType: 7,
  3968. // IsSys: 0,
  3969. // WarehousingOrder: "",
  3970. // WarehouseOutId: info.WarehouseOutId,
  3971. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3972. // IsEdit: 0,
  3973. // CancelStockId: cancel.ID,
  3974. // CancelOrderNumber: cancel.OrderNumber,
  3975. // Manufacturer: manufacturer.ID,
  3976. // Dealer: 0,
  3977. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3978. // UpdateCreator: 0,
  3979. // Status: 1,
  3980. // Ctime: time.Now().Unix(),
  3981. // Mtime: 0,
  3982. // Price: info.Price,
  3983. // WarehousingDetailId: info.WarehouseInfotId,
  3984. // WarehouseOutDetailId: info.ID,
  3985. // CancelOutDetailId: cancelInfo.ID,
  3986. // ProductDate: info.ProductDate,
  3987. // ExpireDate: info.ExpiryDate,
  3988. // StorehouseId: houseConfig.StorehouseOutInfo,
  3989. // OverCount: flush_count,
  3990. //}
  3991. //service.CreateStockFlowOne(flow)
  3992. //退库数量增加
  3993. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3994. //出库数量减少
  3995. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3996. //查询已出库数量
  3997. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3998. if prescribingNumber < dialysisInfo.Count {
  3999. //改变数量
  4000. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4001. }
  4002. if prescribingNumber >= dialysisInfo.Count {
  4003. //删除出库表
  4004. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4005. }
  4006. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4007. var flush_count_one int64
  4008. for _, it := range goodList {
  4009. flush_count_one += it.StockCount
  4010. }
  4011. //更新库存
  4012. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4013. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4014. //更新基础库库存
  4015. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4016. }
  4017. }
  4018. }
  4019. }
  4020. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4021. fmt.Println(err)
  4022. }
  4023. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4024. fmt.Println(err)
  4025. if len(advices) > 0 {
  4026. for _, item := range advices {
  4027. redis := service.RedisClient()
  4028. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4029. redis.Set(keyFive, "", time.Second)
  4030. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4031. redis.Set(keyOne, "", time.Second)
  4032. redis.Close()
  4033. }
  4034. }
  4035. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4036. if len(advices) > 0 {
  4037. for _, item := range advices {
  4038. creater := c.GetAdminUserInfo().AdminUser.Id
  4039. service.DrugAutoAddCancelInfo(item, creater)
  4040. }
  4041. }
  4042. } else {
  4043. if drugOutConfig.IsOpen == 1 {
  4044. if len(advices) > 0 {
  4045. for _, item := range advices {
  4046. creater := c.GetAdminUserInfo().AdminUser.Id
  4047. service.DrugAutoAddCancelInfo(item, creater)
  4048. }
  4049. }
  4050. } else {
  4051. if len(advices) > 0 {
  4052. for _, item := range advices {
  4053. creater := c.GetAdminUserInfo().AdminUser.Id
  4054. service.DrugAutoAddCancelInfo(item, creater)
  4055. }
  4056. }
  4057. }
  4058. }
  4059. c.ServeSuccessJSON(map[string]interface{}{
  4060. "msg": "删除成功",
  4061. })
  4062. return
  4063. }
  4064. func (c *HisApiController) DeleteDoctorAdvice() {
  4065. id, _ := c.GetInt64("id")
  4066. advice, _ := service.GetHisDoctorAdvicesById(id)
  4067. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4068. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4069. //已收费和已发药的限制逻辑
  4070. isCharge := false
  4071. isMedicine := false
  4072. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4073. //获取今天该患者所有处方,判断是否发药或者收费
  4074. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4075. for _, item := range new_prescriptions {
  4076. if item.IsMedicine == 1 {
  4077. isMedicine = true
  4078. }
  4079. }
  4080. for _, item := range new_prescriptions {
  4081. if item.OrderStatus == 4 {
  4082. isCharge = true
  4083. }
  4084. }
  4085. if isMedicine {
  4086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4087. return
  4088. }
  4089. if isCharge {
  4090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4091. return
  4092. }
  4093. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4094. for _, item := range advices {
  4095. if item.IsMedicine == 1 {
  4096. isMedicine = true
  4097. }
  4098. }
  4099. if isMedicine {
  4100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4101. return
  4102. }
  4103. if new_prescription.ID > 0 {
  4104. if new_prescription.OrderStatus == 2 {
  4105. isCharge = true
  4106. }
  4107. }
  4108. if isCharge {
  4109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4110. return
  4111. }
  4112. //已收费和已发药的限制逻辑
  4113. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4114. redis := service.RedisClient()
  4115. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4116. redis.Set(keyFive, "", time.Second)
  4117. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4118. redis.Set(keyOne, "", time.Second)
  4119. defer redis.Close()
  4120. if err == nil {
  4121. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4122. //查询是否在处方中出库
  4123. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4124. if openConfig.IsOpen != 1 {
  4125. //判断该医嘱是否执行了
  4126. if advice.ExecutionState == 1 {
  4127. creater := c.GetAdminUserInfo().AdminUser.Id
  4128. service.DrugAutoAddCancelInfo(&advice, creater)
  4129. }
  4130. }
  4131. //开启保存处方扣减功能
  4132. if openConfig.IsOpen == 1 {
  4133. creater := c.GetAdminUserInfo().AdminUser.Id
  4134. service.DrugAutoAddCancelInfo(&advice, creater)
  4135. }
  4136. } else {
  4137. if drugOutConfig.IsOpen == 1 {
  4138. //查询是否在处方中出库
  4139. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4140. if openConfig.IsOpen != 1 {
  4141. //判断该医嘱是否执行了
  4142. if advice.ExecutionState == 1 {
  4143. creater := c.GetAdminUserInfo().AdminUser.Id
  4144. service.DrugAutoAddCancelInfo(&advice, creater)
  4145. }
  4146. }
  4147. //开启保存处方扣减功能
  4148. if openConfig.IsOpen == 1 {
  4149. creater := c.GetAdminUserInfo().AdminUser.Id
  4150. service.DrugAutoAddCancelInfo(&advice, creater)
  4151. }
  4152. } else {
  4153. //判断该医嘱是否执行了
  4154. if advice.ExecutionState == 1 {
  4155. creater := c.GetAdminUserInfo().AdminUser.Id
  4156. service.DrugAutoAddCancelInfo(&advice, creater)
  4157. }
  4158. }
  4159. }
  4160. c.ServeSuccessJSON(map[string]interface{}{
  4161. "msg": "删除成功",
  4162. })
  4163. return
  4164. } else {
  4165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4166. return
  4167. }
  4168. }
  4169. func (c *HisApiController) DeleteProject() {
  4170. id, _ := c.GetInt64("id")
  4171. adminInfo := c.GetAdminUserInfo()
  4172. project, _ := service.GetHisProjectByID(id)
  4173. // var consumable models.DialysisBeforePrepare
  4174. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4175. //耗材保存处方出库
  4176. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4177. isCharge := false
  4178. isMedicine := false
  4179. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4180. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4181. for _, item := range new_prescriptions {
  4182. if item.IsMedicine == 1 {
  4183. isMedicine = true
  4184. }
  4185. }
  4186. for _, item := range new_prescriptions {
  4187. if item.OrderStatus == 4 {
  4188. isCharge = true
  4189. }
  4190. }
  4191. if isMedicine {
  4192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4193. return
  4194. }
  4195. if isCharge {
  4196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4197. return
  4198. }
  4199. if new_prescription.ID > 0 {
  4200. if new_prescription.OrderStatus == 2 {
  4201. isCharge = true
  4202. }
  4203. }
  4204. if isCharge {
  4205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4206. return
  4207. }
  4208. service.DeletePrintInfo(id)
  4209. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4210. label.Status = 0
  4211. service.CreateHisLabelRecord(&label)
  4212. fmt.Println(goodOutConfig.IsOpen)
  4213. if goodOutConfig.IsOpen != 1 {
  4214. if stockConfig.IsOpen == 1 {
  4215. if project.Type == 2 {
  4216. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4217. fmt.Println(err)
  4218. }
  4219. if project.Type == 3 && project.IsOut == 1 {
  4220. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4221. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4222. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4223. operation_time := time.Now().Unix()
  4224. creater := adminInfo.AdminUser.Id
  4225. //创建退库单
  4226. timeStr := time.Now().Format("2006-01-02")
  4227. timeArr := strings.Split(timeStr, "-")
  4228. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4229. total = total + 1
  4230. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4231. cancelStock := models.CancelStock{
  4232. OrderNumber: orderNumber,
  4233. OperaTime: operation_time,
  4234. OrgId: adminInfo.CurrentOrgId,
  4235. Creater: creater,
  4236. Ctime: time.Now().Unix(),
  4237. Status: 1,
  4238. ReturnTime: project.RecordDate,
  4239. Type: 1,
  4240. StorehouseId: houseConfig.StorehouseOutInfo,
  4241. IsCheck: 1,
  4242. }
  4243. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4244. if msgerrkonde == gorm.ErrRecordNotFound {
  4245. service.AddSigleCancelStock(&cancelStock)
  4246. }
  4247. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4248. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4249. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4250. //查询是否有出库
  4251. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4252. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4253. deaerler, _ := service.GetDealerById(info.Dealer)
  4254. if info.ID > 0 {
  4255. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4256. if info.Count >= prescribingNumber {
  4257. cancelStockInfo := models.CancelStockInfo{
  4258. GoodId: project.ProjectId,
  4259. CancelStockId: cancel.ID,
  4260. GoodTypeId: good.GoodTypeId,
  4261. Count: prescribingNumber,
  4262. Price: info.Price,
  4263. Total: 0,
  4264. ProductDate: info.ProductDate,
  4265. ExpiryDate: info.ExpiryDate,
  4266. Ctime: time.Now().Unix(),
  4267. Status: 1,
  4268. OrgId: adminInfo.CurrentOrgId,
  4269. OrderNumber: cancel.OrderNumber,
  4270. Type: 0,
  4271. Dealer: deaerler.DealerName,
  4272. Manufacturer: manufacturer.ManufacturerName,
  4273. Number: info.Number,
  4274. RegisterAccount: "",
  4275. Remark: "",
  4276. WarehouseInfoId: info.WarehouseInfotId,
  4277. PatientId: info.PatientId,
  4278. RecordDate: info.SysRecordTime,
  4279. StorehouseId: houseConfig.StorehouseOutInfo,
  4280. IsCheck: 1,
  4281. }
  4282. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4283. //回退库存
  4284. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4285. //退库数量增加
  4286. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4287. //出库数量减少
  4288. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4289. }
  4290. if info.Count < prescribingNumber {
  4291. cancelStockInfo := models.CancelStockInfo{
  4292. GoodId: project.ProjectId,
  4293. CancelStockId: cancel.ID,
  4294. GoodTypeId: good.GoodTypeId,
  4295. Count: info.Count,
  4296. Price: info.Price,
  4297. Total: 0,
  4298. ProductDate: info.ProductDate,
  4299. ExpiryDate: info.ExpiryDate,
  4300. Ctime: time.Now().Unix(),
  4301. Status: 1,
  4302. OrgId: adminInfo.CurrentOrgId,
  4303. OrderNumber: cancel.OrderNumber,
  4304. Type: 0,
  4305. Dealer: deaerler.DealerName,
  4306. Manufacturer: manufacturer.ManufacturerName,
  4307. Number: info.Number,
  4308. RegisterAccount: "",
  4309. Remark: "",
  4310. WarehouseInfoId: info.WarehouseInfotId,
  4311. PatientId: info.PatientId,
  4312. RecordDate: info.SysRecordTime,
  4313. StorehouseId: houseConfig.StorehouseOutInfo,
  4314. IsCheck: 1,
  4315. }
  4316. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4317. //回退库存
  4318. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4319. //退库数量增加
  4320. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4321. //出库数量减少
  4322. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4323. }
  4324. //查询剩余库存
  4325. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4326. var over_count int64
  4327. for _, it := range goodList {
  4328. over_count += it.StockCount
  4329. }
  4330. //出库数据 大于 退库数量
  4331. if info.Count >= prescribingNumber {
  4332. flow := models.VmStockFlow{
  4333. WarehousingId: info.WarehouseInfotId,
  4334. GoodId: project.ProjectId,
  4335. Number: info.Number,
  4336. LicenseNumber: info.LicenseNumber,
  4337. Count: prescribingNumber,
  4338. UserOrgId: adminInfo.CurrentOrgId,
  4339. PatientId: project.PatientId,
  4340. SystemTime: info.SysRecordTime,
  4341. ConsumableType: 7,
  4342. IsSys: 0,
  4343. WarehousingOrder: "",
  4344. WarehouseOutId: info.WarehouseOutId,
  4345. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4346. IsEdit: 0,
  4347. CancelStockId: cancel.ID,
  4348. CancelOrderNumber: cancel.OrderNumber,
  4349. Manufacturer: manufacturer.ID,
  4350. Dealer: 0,
  4351. Creator: adminInfo.AdminUser.Id,
  4352. UpdateCreator: 0,
  4353. Status: 1,
  4354. Ctime: time.Now().Unix(),
  4355. Mtime: 0,
  4356. Price: info.Price,
  4357. WarehousingDetailId: info.WarehouseInfotId,
  4358. WarehouseOutDetailId: info.ID,
  4359. CancelOutDetailId: cancelInfo.ID,
  4360. ProductDate: info.ProductDate,
  4361. ExpireDate: info.ExpiryDate,
  4362. StorehouseId: houseConfig.StorehouseOutInfo,
  4363. OverCount: over_count,
  4364. }
  4365. service.CreateStockFlowOne(flow)
  4366. }
  4367. //出库数据小于退库数据
  4368. if info.Count < prescribingNumber {
  4369. flow := models.VmStockFlow{
  4370. WarehousingId: info.WarehouseInfotId,
  4371. GoodId: project.ProjectId,
  4372. Number: info.Number,
  4373. LicenseNumber: info.LicenseNumber,
  4374. Count: info.Count,
  4375. UserOrgId: adminInfo.CurrentOrgId,
  4376. PatientId: project.PatientId,
  4377. SystemTime: info.SysRecordTime,
  4378. ConsumableType: 7,
  4379. IsSys: 0,
  4380. WarehousingOrder: "",
  4381. WarehouseOutId: info.WarehouseOutId,
  4382. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4383. IsEdit: 0,
  4384. CancelStockId: cancel.ID,
  4385. CancelOrderNumber: cancel.OrderNumber,
  4386. Manufacturer: manufacturer.ID,
  4387. Dealer: 0,
  4388. Creator: adminInfo.AdminUser.Id,
  4389. UpdateCreator: 0,
  4390. Status: 1,
  4391. Ctime: time.Now().Unix(),
  4392. Mtime: 0,
  4393. Price: info.Price,
  4394. WarehousingDetailId: info.WarehouseInfotId,
  4395. WarehouseOutDetailId: info.ID,
  4396. CancelOutDetailId: cancelInfo.ID,
  4397. ProductDate: info.ProductDate,
  4398. ExpireDate: info.ExpiryDate,
  4399. StorehouseId: houseConfig.StorehouseOutInfo,
  4400. OverCount: over_count,
  4401. }
  4402. service.CreateStockFlowOne(flow)
  4403. }
  4404. //查询已出库数量
  4405. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4406. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4407. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4408. if prescribingNumber < dialysisInfo.Count {
  4409. //改变数量
  4410. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4411. }
  4412. if prescribingNumber >= dialysisInfo.Count {
  4413. //删除出库表
  4414. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4415. }
  4416. //更新剩余库存
  4417. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4418. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4419. var total_count_one int64
  4420. for _, it := range stockList {
  4421. total_count_one += it.StockCount
  4422. }
  4423. //基础库插入数据
  4424. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4425. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4426. var flush_count int64
  4427. for _, it := range goodListOne {
  4428. flush_count += it.StockCount
  4429. }
  4430. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4431. if errs != nil {
  4432. goodErrcode := models.XtGoodErrcode{
  4433. UserOrgId: project.UserOrgId,
  4434. Errcode: "手动出库更新剩余出库失败",
  4435. GoodId: project.ProjectId,
  4436. Status: 1,
  4437. Ctime: time.Now().Unix(),
  4438. Mtime: 0,
  4439. Count: 0,
  4440. StockCount: 0,
  4441. Creater: creater,
  4442. BatchNumberId: 0,
  4443. WarehouseOutId: 0,
  4444. }
  4445. service.CreateGoodErrcode(goodErrcode)
  4446. }
  4447. }
  4448. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4449. fmt.Println(err)
  4450. } else {
  4451. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4452. fmt.Println(err)
  4453. }
  4454. } else {
  4455. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4456. fmt.Println(err)
  4457. }
  4458. }
  4459. //保存处方出库
  4460. if goodOutConfig.IsOpen == 1 {
  4461. if project.Type == 3 {
  4462. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4463. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4464. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4465. operation_time := time.Now().Unix()
  4466. creater := adminInfo.AdminUser.Id
  4467. //创建退库单
  4468. timeStr := time.Now().Format("2006-01-02")
  4469. timeArr := strings.Split(timeStr, "-")
  4470. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4471. total = total + 1
  4472. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4473. cancelStock := models.CancelStock{
  4474. OrderNumber: orderNumber,
  4475. OperaTime: operation_time,
  4476. OrgId: adminInfo.CurrentOrgId,
  4477. Creater: creater,
  4478. Ctime: time.Now().Unix(),
  4479. Status: 1,
  4480. ReturnTime: project.RecordDate,
  4481. Type: 1,
  4482. StorehouseId: houseConfig.StorehouseOutInfo,
  4483. IsCheck: 1,
  4484. }
  4485. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4486. if msgerrkonde == gorm.ErrRecordNotFound {
  4487. service.AddSigleCancelStock(&cancelStock)
  4488. }
  4489. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4490. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4491. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4492. //获取出库数据
  4493. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4494. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4495. deaerler, _ := service.GetDealerById(info.Dealer)
  4496. if info.ID > 0 {
  4497. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4498. if info.Count >= prescribingNumber {
  4499. cancelStockInfo := models.CancelStockInfo{
  4500. GoodId: project.ProjectId,
  4501. CancelStockId: cancel.ID,
  4502. GoodTypeId: good.GoodTypeId,
  4503. Count: prescribingNumber,
  4504. Price: info.Price,
  4505. Total: 0,
  4506. ProductDate: info.ProductDate,
  4507. ExpiryDate: info.ExpiryDate,
  4508. Ctime: time.Now().Unix(),
  4509. Status: 1,
  4510. OrgId: adminInfo.CurrentOrgId,
  4511. OrderNumber: cancel.OrderNumber,
  4512. Type: 0,
  4513. Dealer: deaerler.DealerName,
  4514. Manufacturer: manufacturer.ManufacturerName,
  4515. Number: info.Number,
  4516. RegisterAccount: "",
  4517. Remark: "",
  4518. WarehouseInfoId: info.WarehouseInfotId,
  4519. PatientId: info.PatientId,
  4520. RecordDate: info.SysRecordTime,
  4521. StorehouseId: houseConfig.StorehouseOutInfo,
  4522. IsCheck: 1,
  4523. }
  4524. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4525. //退库数量增加
  4526. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4527. //出库数量减少
  4528. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4529. }
  4530. if info.Count < prescribingNumber {
  4531. cancelStockInfo := models.CancelStockInfo{
  4532. GoodId: project.ProjectId,
  4533. CancelStockId: cancel.ID,
  4534. GoodTypeId: good.GoodTypeId,
  4535. Count: prescribingNumber,
  4536. Price: info.Price,
  4537. Total: 0,
  4538. ProductDate: info.ProductDate,
  4539. ExpiryDate: info.ExpiryDate,
  4540. Ctime: time.Now().Unix(),
  4541. Status: 1,
  4542. OrgId: adminInfo.CurrentOrgId,
  4543. OrderNumber: cancel.OrderNumber,
  4544. Type: 0,
  4545. Dealer: deaerler.DealerName,
  4546. Manufacturer: manufacturer.ManufacturerName,
  4547. Number: info.Number,
  4548. RegisterAccount: "",
  4549. Remark: "",
  4550. WarehouseInfoId: info.WarehouseInfotId,
  4551. PatientId: info.PatientId,
  4552. RecordDate: info.SysRecordTime,
  4553. StorehouseId: houseConfig.StorehouseOutInfo,
  4554. IsCheck: 1,
  4555. }
  4556. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4557. //回退库存
  4558. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4559. }
  4560. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4561. var over_count int64
  4562. for _, it := range goodList {
  4563. over_count += it.StockCount
  4564. }
  4565. //查询出库数量
  4566. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4567. //出库数据 大于 退库数量
  4568. if len(list) > 0 {
  4569. for _, it := range list {
  4570. //回退库存
  4571. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4572. //退库数量增加
  4573. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4574. //出库数量减少
  4575. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4576. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4577. var over_count_one int64
  4578. for _, it := range goodList {
  4579. over_count_one += it.StockCount
  4580. }
  4581. //查询该批次是否有退库数据
  4582. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4583. flow := models.VmStockFlow{
  4584. WarehousingId: it.WarehouseInfotId,
  4585. GoodId: it.GoodId,
  4586. Number: it.Number,
  4587. LicenseNumber: it.LicenseNumber,
  4588. Count: it.Count,
  4589. UserOrgId: adminInfo.CurrentOrgId,
  4590. PatientId: it.PatientId,
  4591. SystemTime: it.SysRecordTime,
  4592. ConsumableType: 7,
  4593. IsSys: 0,
  4594. WarehousingOrder: "",
  4595. WarehouseOutId: it.WarehouseOutId,
  4596. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4597. IsEdit: 0,
  4598. CancelStockId: cancel.ID,
  4599. CancelOrderNumber: cancel.OrderNumber,
  4600. Manufacturer: manufacturer.ID,
  4601. Dealer: 0,
  4602. Creator: adminInfo.AdminUser.Id,
  4603. UpdateCreator: 0,
  4604. Status: 1,
  4605. Ctime: time.Now().Unix(),
  4606. Mtime: 0,
  4607. Price: it.Price,
  4608. WarehousingDetailId: it.WarehouseInfotId,
  4609. WarehouseOutDetailId: it.ID,
  4610. CancelOutDetailId: cancelInfo.ID,
  4611. ProductDate: it.ProductDate,
  4612. ExpireDate: it.ExpiryDate,
  4613. StorehouseId: houseConfig.StorehouseOutInfo,
  4614. OverCount: over_count_one,
  4615. }
  4616. service.CreateStockFlowOne(flow)
  4617. }
  4618. }
  4619. //查询已出库数量
  4620. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4621. if prescribingNumber < dialysisInfo.Count {
  4622. //改变数量
  4623. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4624. }
  4625. if prescribingNumber >= dialysisInfo.Count {
  4626. //删除出库表
  4627. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4628. }
  4629. //更新剩余库存
  4630. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4631. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4632. var total_count_one int64
  4633. for _, it := range stockList {
  4634. total_count_one += it.StockCount
  4635. }
  4636. //基础库插入数据
  4637. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4638. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4639. var flush_count int64
  4640. for _, it := range goodListOne {
  4641. flush_count += it.StockCount
  4642. }
  4643. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4644. if errs != nil {
  4645. goodErrcode := models.XtGoodErrcode{
  4646. UserOrgId: project.UserOrgId,
  4647. Errcode: "手动出库更新剩余出库失败",
  4648. GoodId: project.ProjectId,
  4649. Status: 1,
  4650. Ctime: time.Now().Unix(),
  4651. Mtime: 0,
  4652. Count: 0,
  4653. StockCount: 0,
  4654. Creater: creater,
  4655. BatchNumberId: 0,
  4656. WarehouseOutId: 0,
  4657. }
  4658. service.CreateGoodErrcode(goodErrcode)
  4659. }
  4660. }
  4661. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4662. fmt.Println(err)
  4663. } else {
  4664. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4665. fmt.Println(err)
  4666. }
  4667. }
  4668. c.ServeSuccessJSON(map[string]interface{}{
  4669. "msg": "删除成功",
  4670. })
  4671. return
  4672. }
  4673. func (c *HisApiController) CreateHisAdditionalCharge() {
  4674. his_patient_id, _ := c.GetInt64("his_patient_id")
  4675. patient_id, _ := c.GetInt64("patient_id")
  4676. record_date := c.GetString("record_date")
  4677. timeLayout := "2006-01-02"
  4678. loc, _ := time.LoadLocation("Local")
  4679. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4680. if err != nil {
  4681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4682. return
  4683. }
  4684. adminInfo := c.GetAdminUserInfo()
  4685. recordDateTime := theTime.Unix()
  4686. dataBody := make(map[string]interface{}, 0)
  4687. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4688. if err != nil {
  4689. utils.ErrorLog(err.Error())
  4690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4691. return
  4692. }
  4693. var additions []*models.HisAdditionalCharge
  4694. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4695. additions, _ := dataBody["addition"].([]interface{})
  4696. if len(additions) > 0 {
  4697. for _, item := range additions {
  4698. items := item.(map[string]interface{})
  4699. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4700. utils.ErrorLog("item_id")
  4701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4702. return
  4703. }
  4704. item_id := int64(items["item_id"].(float64))
  4705. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4706. utils.ErrorLog("item_name")
  4707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4708. return
  4709. }
  4710. item_name := items["item_name"].(string)
  4711. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4712. utils.ErrorLog("price")
  4713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4714. return
  4715. }
  4716. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4717. ctime := time.Now().Unix()
  4718. additional := &models.HisAdditionalCharge{
  4719. PatientId: patient_id,
  4720. HisPatientId: his_patient_id,
  4721. UserOrgId: adminInfo.CurrentOrgId,
  4722. RecordDate: recordDateTime,
  4723. CreatedTime: ctime,
  4724. UpdatedTime: ctime,
  4725. Modifier: adminInfo.AdminUser.Id,
  4726. Creator: adminInfo.AdminUser.Id,
  4727. Price: price,
  4728. ItemName: item_name,
  4729. ItemId: item_id,
  4730. Status: 1,
  4731. }
  4732. additions = append(additions, additional)
  4733. }
  4734. }
  4735. }
  4736. for _, item := range additions {
  4737. service.CreateAddtionalCharge(item)
  4738. }
  4739. c.ServeSuccessJSON(map[string]interface{}{
  4740. "msg": "创建成功",
  4741. })
  4742. }
  4743. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4744. blood_fat := c.GetString("blood_fat")
  4745. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4746. blood_sugar := c.GetString("blood_sugar")
  4747. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4748. chief_conplaint := c.GetString("chief_conplaint")
  4749. dbp := c.GetString("dbp")
  4750. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4751. delivery_way, _ := c.GetInt64("delivery_way")
  4752. diagnostic := c.GetString("diagnostic")
  4753. family_history := c.GetString("family_history")
  4754. height := c.GetString("height")
  4755. history_of_present_illness := c.GetString("history_of_present_illness")
  4756. is_infect, _ := c.GetInt64("is_infect")
  4757. past_history := c.GetString("past_history")
  4758. patient_id, _ := c.GetInt64("patient_id")
  4759. his_patient_id, _ := c.GetInt64("his_patient_id")
  4760. personal_history := c.GetString("personal_history")
  4761. pulse := c.GetString("pulse")
  4762. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4763. sbp := c.GetString("sbp")
  4764. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4765. heightfloat, _ := strconv.ParseFloat(height, 64)
  4766. sicktype := c.GetString("sick_type")
  4767. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4768. symptom := c.GetString("symptom")
  4769. sick_date := c.GetString("sick_date")
  4770. temperatures := c.GetString("temperature")
  4771. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4772. record_date := c.GetString("record_date")
  4773. breathing := c.GetString("breathing")
  4774. doctor_advice := c.GetString("doctor_advice")
  4775. remark := c.GetString("remark")
  4776. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4777. sick, _ := c.GetInt64("sick")
  4778. diagnose, _ := c.GetInt64("diagnose")
  4779. //id, _ := c.GetInt64("id")
  4780. timeLayout := "2006-01-02"
  4781. loc, _ := time.LoadLocation("Local")
  4782. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4783. allergic_history := c.GetString("allergic_history")
  4784. if err != nil {
  4785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4786. return
  4787. }
  4788. recordDateTime := theTime.Unix()
  4789. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4790. if err != nil {
  4791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4792. return
  4793. }
  4794. sickTimes := sickTime.Unix()
  4795. ctime := time.Now().Unix()
  4796. primary_disease := c.GetString("primary_disease")
  4797. confirm_failure_date := c.GetString("confirm_failure_date")
  4798. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4799. drug_allergy_history := c.GetString("drug_allergy_history")
  4800. physical_examination := c.GetString("physical_examination")
  4801. special_inspection := c.GetString("special_inspection")
  4802. lab_apparatus := c.GetString("lab_apparatus")
  4803. caseHistory := models.HisPatientCaseHistory{
  4804. HisPatientId: his_patient_id,
  4805. PatientId: patient_id,
  4806. Temperature: temperature,
  4807. BloodSugar: bloodsugarfloat,
  4808. Pulse: pulsefloat,
  4809. Sbp: sbpfloat,
  4810. Dbp: dbpfloat,
  4811. Height: heightfloat,
  4812. BloodFat: bloodfatfloat,
  4813. SickType: sick_type,
  4814. Symptom: symptom,
  4815. SickDate: sickTimes,
  4816. IsInfect: is_infect,
  4817. HistoryOfPresentIllness: history_of_present_illness,
  4818. PastHistory: past_history,
  4819. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4820. ChiefConplaint: chief_conplaint,
  4821. PersonalHistory: personal_history,
  4822. FamilyHistory: family_history,
  4823. Diagnostic: diagnostic,
  4824. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4825. Status: 1,
  4826. Ctime: ctime,
  4827. Mtime: ctime,
  4828. RecordDate: recordDateTime,
  4829. DeliveryWay: delivery_way,
  4830. Breathing: breathingfloat,
  4831. DoctorAdvice: doctor_advice,
  4832. Remark: remark,
  4833. Sick: sick,
  4834. Diagnose: diagnose,
  4835. AllergicHistory: allergic_history,
  4836. PrimaryDisease: primary_disease,
  4837. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4838. DrugAllergyHistory: drug_allergy_history,
  4839. PhysicalExamination: physical_examination,
  4840. SpecialInspection: special_inspection,
  4841. LabApparatus: lab_apparatus,
  4842. }
  4843. //查询该患者是否有病历
  4844. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4845. if errcodes == gorm.ErrRecordNotFound {
  4846. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4847. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4848. if err != nil {
  4849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4850. return
  4851. }
  4852. c.ServeSuccessJSON(map[string]interface{}{
  4853. "caseHistory": caseHistory,
  4854. "historyInfo": historyInfo,
  4855. })
  4856. return
  4857. } else if errcodes == nil {
  4858. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4859. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4860. if err != nil {
  4861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4862. return
  4863. }
  4864. c.ServeSuccessJSON(map[string]interface{}{
  4865. "caseHistory": caseHistory,
  4866. "historyInfo": historyInfo,
  4867. })
  4868. }
  4869. //查询该患者是否有病历
  4870. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4871. //if errcode == gorm.ErrRecordNotFound {
  4872. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4873. // if err != nil {
  4874. // c.ServeSuccessJSON(map[string]interface{}{
  4875. // "msg": "保存成功",
  4876. // })
  4877. // }
  4878. //} else if errcode == nil {
  4879. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4880. // return
  4881. //}
  4882. }
  4883. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4884. patient_id, _ := c.GetInt64("patient_id", 0)
  4885. adminUser := c.GetAdminUserInfo()
  4886. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4887. c.ServeSuccessJSON(map[string]interface{}{
  4888. "list": caseHistorys,
  4889. })
  4890. }
  4891. func (c *HisApiController) GetHisPatientCaseHistory() {
  4892. record_date, _ := c.GetInt64("record_date", 0)
  4893. patient_id, _ := c.GetInt64("patient_id", 0)
  4894. admin := c.GetAdminUserInfo()
  4895. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4896. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4897. c.ServeSuccessJSON(map[string]interface{}{
  4898. "info": info,
  4899. "case_history": case_history,
  4900. })
  4901. }
  4902. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4903. template_name := c.GetString("template_name")
  4904. template_remark := c.GetString("template_remark")
  4905. doctor := c.GetAdminUserInfo().AdminUser.Id
  4906. diagnostic := c.GetString("diagnostic")
  4907. chief_conplaint := c.GetString("chief_conplain")
  4908. history_of_present_illness := c.GetString("history_of_present_illness")
  4909. past_history := c.GetString("past_history")
  4910. personal_history := c.GetString("personal_history")
  4911. family_history := c.GetString("family_history")
  4912. user_name := c.GetString("user_name")
  4913. doctor_advice := c.GetString("doctor_advice")
  4914. remark := c.GetString("remark")
  4915. //record_date := c.GetString("record_date")
  4916. //fmt.Println("record_date--------",record_date)
  4917. //timeLayout := "2006-01-02"
  4918. //loc, _ := time.LoadLocation("Local")
  4919. //
  4920. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4921. //if err != nil {
  4922. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4923. // return
  4924. //}
  4925. //recordDateTime := theTime.Unix()
  4926. ctime := time.Now().Unix()
  4927. template := models.HisCaseHistoryTemplate{
  4928. HistoryOfPresentIllness: history_of_present_illness,
  4929. PastHistory: past_history,
  4930. ChiefConplaint: chief_conplaint,
  4931. PersonalHistory: personal_history,
  4932. FamilyHistory: family_history,
  4933. Diagnostic: diagnostic,
  4934. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4935. Status: 1,
  4936. Ctime: ctime,
  4937. Mtime: ctime,
  4938. RecordDate: time.Now().Unix(),
  4939. TemplateName: template_name,
  4940. TemplateRemark: template_remark,
  4941. Creator: doctor,
  4942. Modifier: doctor,
  4943. UserName: user_name,
  4944. DoctorAdvice: doctor_advice,
  4945. Remark: remark,
  4946. }
  4947. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4948. if err == nil {
  4949. c.ServeSuccessJSON(map[string]interface{}{
  4950. "msg": "保存成功",
  4951. })
  4952. } else {
  4953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4954. return
  4955. }
  4956. }
  4957. func (c *HisApiController) GetCaseHistoryTemplate() {
  4958. timeLayout := "2006-01-02"
  4959. loc, _ := time.LoadLocation("Local")
  4960. keyword := c.GetString("keyword")
  4961. start_time := c.GetString("start_time")
  4962. end_time := c.GetString("end_time")
  4963. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4964. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4965. admin := c.GetAdminUserInfo()
  4966. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4967. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4968. c.ServeSuccessJSON(map[string]interface{}{
  4969. "template": template,
  4970. //"history": history,
  4971. })
  4972. }
  4973. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4974. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4975. utils.ErrorLog("drug_name")
  4976. return enums.ErrorCodeParamWrong
  4977. }
  4978. adviceName, _ := json["drug_name"].(string)
  4979. if len(adviceName) == 0 {
  4980. utils.ErrorLog("len(advice_name) == 0")
  4981. return enums.ErrorCodeParamWrong
  4982. }
  4983. advice.AdviceName = adviceName
  4984. adviceDesc, _ := json["advice_desc"].(string)
  4985. advice.AdviceDesc = adviceDesc
  4986. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4987. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4988. advice.DrugSpec = drugSpec
  4989. }
  4990. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4991. remark, _ := json["remark"].(string)
  4992. advice.Remark = remark
  4993. }
  4994. if json["id"] == nil {
  4995. advice.DrugId = 0
  4996. } else {
  4997. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4998. drug_id := int64(json["id"].(float64))
  4999. advice.DrugId = drug_id
  5000. }
  5001. }
  5002. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5003. advice_id := int64(json["advice_id"].(float64))
  5004. advice.ID = advice_id
  5005. if advice.ID > 0 {
  5006. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5007. if err == nil {
  5008. if hisAdvice.ID > 0 {
  5009. advice.ExecutionTime = hisAdvice.ExecutionTime
  5010. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5011. advice.ExecutionState = hisAdvice.ExecutionState
  5012. advice.CheckTime = hisAdvice.CheckTime
  5013. advice.Checker = hisAdvice.Checker
  5014. advice.CheckState = hisAdvice.CheckState
  5015. advice.StartTime = hisAdvice.StartTime
  5016. advice.FeedetlSn = hisAdvice.FeedetlSn
  5017. }
  5018. }
  5019. }
  5020. }
  5021. //
  5022. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5023. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5024. // advice.ExecutionTime = execution_time
  5025. //}
  5026. //
  5027. //
  5028. //
  5029. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5030. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5031. // advice.ExecutionStaff = execution_staff
  5032. //}
  5033. //
  5034. //
  5035. //
  5036. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5037. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5038. // advice.ExecutionState = execution_state
  5039. //}
  5040. //
  5041. //
  5042. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5043. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5044. // advice.CheckTime = check_time
  5045. //}
  5046. //
  5047. //
  5048. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5049. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5050. // advice.CheckState = check_state
  5051. //}
  5052. //
  5053. //
  5054. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5055. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5056. // advice.Checker = checker
  5057. //}
  5058. //
  5059. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5060. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5061. // advice.StartTime = start_time
  5062. //}
  5063. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5064. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5065. advice.IsSelfDrug = is_self_drug
  5066. }
  5067. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5068. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5069. drug_way_count, _ := json["drug_way_count"].(string)
  5070. advice.DrugWayCount = drug_way_count
  5071. }
  5072. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5073. drugSpecUnit, _ := json["min_unit"].(string)
  5074. advice.DrugSpecUnit = drugSpecUnit
  5075. }
  5076. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5077. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5078. advice.SingleDose = singleDose
  5079. }
  5080. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5081. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5082. advice.SingleDoseUnit = singleDoseUnit
  5083. }
  5084. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5085. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5086. advice.PrescribingNumber = prescribingNumber
  5087. }
  5088. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5089. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5090. advice.PrescribingNumberUnit = prescribingNumberUnit
  5091. }
  5092. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5093. deliveryWay, _ := json["delivery_way"].(string)
  5094. advice.DeliveryWay = deliveryWay
  5095. }
  5096. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5097. executionFrequency, _ := json["execution_frequency"].(string)
  5098. advice.ExecutionFrequency = executionFrequency
  5099. }
  5100. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5101. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5102. advice.Price = price
  5103. }
  5104. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5105. med_list_codg, _ := json["medical_insurance_number"].(string)
  5106. advice.MedListCodg = med_list_codg
  5107. }
  5108. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5109. day := int64(json["day"].(float64))
  5110. advice.Day = day
  5111. }
  5112. return 0
  5113. }
  5114. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5115. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5116. id := int64(json["id"].(float64))
  5117. project.ID = id
  5118. historyProject, _ := service.GetHisProjectByID(id)
  5119. project.FeedetlSn = historyProject.FeedetlSn
  5120. }
  5121. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5122. project_id := int64(json["project_id"].(float64))
  5123. project.ProjectId = project_id
  5124. }
  5125. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5126. // price := int64(json["price"].(float64))
  5127. // formatInt_price := strconv.FormatInt(price, 10)
  5128. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5129. // project.Price = float_price
  5130. // }
  5131. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5132. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5133. project.Price = price
  5134. }
  5135. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5136. total, _ := json["total"].(string)
  5137. project.Count = total
  5138. }
  5139. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5140. medical_code, _ := json["medical_code"].(string)
  5141. project.MedListCodg = medical_code
  5142. }
  5143. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5144. single_dose, _ := json["single_dose"].(string)
  5145. project.SingleDose = single_dose
  5146. }
  5147. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5148. delivery_way, _ := json["delivery_way"].(string)
  5149. project.DeliveryWay = delivery_way
  5150. }
  5151. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5152. execution_frequency, _ := json["execution_frequency"].(string)
  5153. project.ExecutionFrequency = execution_frequency
  5154. }
  5155. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5156. remark, _ := json["remark"].(string)
  5157. project.Remark = remark
  5158. }
  5159. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5160. day, _ := json["number_days"].(string)
  5161. project.Day = day
  5162. }
  5163. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5164. unit, _ := json["unit"].(string)
  5165. project.Unit = unit
  5166. }
  5167. return 0
  5168. }
  5169. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5170. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5171. id := int64(json["id"].(float64))
  5172. historyAddtions, _ := service.GetHisAdditionByID(id)
  5173. additionalCharge.ID = id
  5174. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5175. }
  5176. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5177. item_id := int64(json["item_id"].(float64))
  5178. additionalCharge.ItemId = item_id
  5179. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5180. if config.ID > 0 {
  5181. if len(config.Code) > 0 {
  5182. additionalCharge.MedListCodg = config.Code
  5183. }
  5184. }
  5185. }
  5186. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5187. // price := int64(json["price"].(float64))
  5188. // formatInt_price := strconv.FormatInt(price, 10)
  5189. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5190. // additionalCharge.Price = float_price
  5191. // }
  5192. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5193. // price := int64(json["price"].(float64))
  5194. // formatInt_price := strconv.FormatInt(price, 10)
  5195. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5196. // additionalCharge.Price = float_price
  5197. //}
  5198. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5199. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5200. additionalCharge.Price = price
  5201. }
  5202. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5203. count, _ := json["count"].(string)
  5204. counts, _ := strconv.ParseInt(count, 10, 64)
  5205. additionalCharge.Count = counts
  5206. }
  5207. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5208. item_name, _ := json["item_name"].(string)
  5209. additionalCharge.ItemName = item_name
  5210. }
  5211. return 0
  5212. }
  5213. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5214. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5215. utils.ErrorLog("drug_name")
  5216. return enums.ErrorCodeParamWrong
  5217. }
  5218. adviceName, _ := json["drug_name"].(string)
  5219. if len(adviceName) == 0 {
  5220. utils.ErrorLog("len(advice_name) == 0")
  5221. return enums.ErrorCodeParamWrong
  5222. }
  5223. advice.AdviceName = adviceName
  5224. adviceDesc, _ := json["advice_desc"].(string)
  5225. advice.AdviceDesc = adviceDesc
  5226. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5227. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5228. advice.DrugSpec = drugSpec
  5229. }
  5230. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5231. remark, _ := json["remark"].(string)
  5232. advice.Remark = remark
  5233. }
  5234. if json["id"] == nil {
  5235. advice.DrugId = 0
  5236. } else {
  5237. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5238. drug_id := int64(json["id"].(float64))
  5239. advice.DrugId = drug_id
  5240. }
  5241. }
  5242. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5243. groupno := int64(json["groupno"].(float64))
  5244. advice.Groupno = groupno
  5245. }
  5246. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5247. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5248. advice.IsSelfDrug = is_self_drug
  5249. }
  5250. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5251. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5252. drug_way_count, _ := json["drug_way_count"].(string)
  5253. advice.DrugWayCount = drug_way_count
  5254. }
  5255. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5256. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5257. advice.HospApprFlag = hosp_appr_flag
  5258. }
  5259. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5260. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5261. advice.PrescribingNumber = prescribingNumber
  5262. }
  5263. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5264. // frequency_type := int64(json["frequency_type"].(float64))
  5265. // advice.FrequencyType = frequency_type
  5266. //}
  5267. //
  5268. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5269. // day_count := int64(json["day_count"].(float64))
  5270. // advice.DayCount = day_count
  5271. //}
  5272. //
  5273. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5274. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5275. // week_day, _ := json["week_day"].(string)
  5276. // advice.WeekDay = week_day
  5277. //}
  5278. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5279. drugSpecUnit, _ := json["min_unit"].(string)
  5280. advice.DrugSpecUnit = drugSpecUnit
  5281. }
  5282. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5283. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5284. advice.SingleDose = singleDose
  5285. }
  5286. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5287. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5288. advice.SingleDoseUnit = singleDoseUnit
  5289. }
  5290. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5291. deliveryWay, _ := json["delivery_way"].(string)
  5292. advice.DeliveryWay = deliveryWay
  5293. }
  5294. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5295. executionFrequency, _ := json["execution_frequency"].(string)
  5296. advice.ExecutionFrequency = executionFrequency
  5297. }
  5298. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5299. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5300. advice.Price = price
  5301. }
  5302. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5303. med_list_codg, _ := json["medical_insurance_number"].(string)
  5304. advice.MedListCodg = med_list_codg
  5305. }
  5306. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5307. day := int64(json["day"].(float64))
  5308. advice.Day = day
  5309. }
  5310. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5311. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5312. advice.PrescribingNumberUnit = prescribingNumberUnit
  5313. }
  5314. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5315. advice_id := int64(json["advice_id"].(float64))
  5316. advice.ID = advice_id
  5317. if advice.ID > 0 {
  5318. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5319. if err == nil {
  5320. if hisAdvice.ID > 0 {
  5321. advice.ExecutionTime = hisAdvice.ExecutionTime
  5322. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5323. advice.ExecutionState = hisAdvice.ExecutionState
  5324. advice.CheckTime = hisAdvice.CheckTime
  5325. advice.Checker = hisAdvice.Checker
  5326. advice.CheckState = hisAdvice.CheckState
  5327. advice.StartTime = hisAdvice.StartTime
  5328. advice.HospApprFlag = hisAdvice.HospApprFlag
  5329. advice.IsMedicine = hisAdvice.IsMedicine
  5330. if hisAdvice.UserOrgId == 10028 {
  5331. 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 {
  5332. advice.ExecutionTime = 0
  5333. advice.ExecutionStaff = 0
  5334. advice.ExecutionState = 2
  5335. advice.CheckTime = 0
  5336. advice.Checker = 0
  5337. advice.CheckState = 2
  5338. }
  5339. } else {
  5340. 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 {
  5341. advice.ExecutionTime = 0
  5342. advice.ExecutionStaff = 0
  5343. advice.ExecutionState = 2
  5344. advice.CheckTime = 0
  5345. advice.Checker = 0
  5346. advice.CheckState = 2
  5347. }
  5348. }
  5349. //advice.Groupno = hisAdvice.Groupno
  5350. }
  5351. }
  5352. }
  5353. }
  5354. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5355. //
  5356. //if drugStockConfig.IsOpen == 1 {
  5357. //
  5358. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5359. // if advice.ID == 0 { //医嘱不存在
  5360. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5361. // drug.Total = drug.Total - advice.PrescribingNumber
  5362. // service.UpdateBaseDrugLib(&drug)
  5363. //
  5364. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5365. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5366. // drug.Total = drug.Total - num
  5367. // service.UpdateBaseDrugLib(&drug)
  5368. // }
  5369. //
  5370. // } else if advice.ID > 0 { //医嘱存在
  5371. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5372. // var num float64
  5373. //
  5374. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5375. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5376. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5377. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5378. // drug.Total = drug.Total + num
  5379. // service.UpdateBaseDrugLib(&drug)
  5380. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5381. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5382. // drug.Total = drug.Total - num
  5383. // service.UpdateBaseDrugLib(&drug)
  5384. // }
  5385. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5386. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5387. // if num2 > advice.PrescribingNumber {
  5388. // num = num2 - advice.PrescribingNumber
  5389. // drug.Total = drug.Total + num
  5390. // service.UpdateBaseDrugLib(&drug)
  5391. // } else if num2 < advice.PrescribingNumber {
  5392. // num = advice.PrescribingNumber - num2
  5393. // drug.Total = drug.Total - num
  5394. // service.UpdateBaseDrugLib(&drug)
  5395. // }
  5396. //
  5397. // }
  5398. //
  5399. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5400. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5401. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5402. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5403. // if num1 > num2 {
  5404. // num = num1 - num2
  5405. // drug.Total = drug.Total + num
  5406. // service.UpdateBaseDrugLib(&drug)
  5407. // } else if num1 < num2 {
  5408. // num = num2 - num1
  5409. // drug.Total = drug.Total - num
  5410. // service.UpdateBaseDrugLib(&drug)
  5411. // }
  5412. //
  5413. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5414. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5415. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5416. // if hisAdvice.PrescribingNumber > num2 {
  5417. // num = hisAdvice.PrescribingNumber - num2
  5418. // drug.Total = drug.Total + num
  5419. // service.UpdateBaseDrugLib(&drug)
  5420. // } else if num2 < advice.PrescribingNumber {
  5421. // num = num2 - hisAdvice.PrescribingNumber
  5422. // drug.Total = drug.Total - num
  5423. // service.UpdateBaseDrugLib(&drug)
  5424. // }
  5425. //
  5426. // }
  5427. // }
  5428. // }
  5429. //}
  5430. //
  5431. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5432. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5433. // advice.ExecutionTime = execution_time
  5434. //}
  5435. //
  5436. //
  5437. //
  5438. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5439. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5440. // advice.ExecutionStaff = execution_staff
  5441. //}
  5442. //
  5443. //
  5444. //
  5445. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5446. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5447. // advice.ExecutionState = execution_state
  5448. //}
  5449. //
  5450. //
  5451. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5452. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5453. // advice.CheckTime = check_time
  5454. //}
  5455. //
  5456. //
  5457. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5458. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5459. // advice.CheckState = check_state
  5460. //}
  5461. //
  5462. //
  5463. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5464. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5465. // advice.Checker = checker
  5466. //}
  5467. //
  5468. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5469. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5470. // advice.StartTime = start_time
  5471. //}
  5472. return 0
  5473. }
  5474. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5475. project.ExecutionStaff = 0
  5476. project.ExecutionState = 2
  5477. project.ExecutionTime = 0
  5478. project.Checker = 0
  5479. project.CheckState = 2
  5480. project.CheckTime = 0
  5481. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5482. id := int64(json["id"].(float64))
  5483. project.ID = id
  5484. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5485. project.ExecutionStaff = temp_project.ExecutionStaff
  5486. project.ExecutionState = temp_project.ExecutionState
  5487. project.ExecutionTime = temp_project.ExecutionTime
  5488. project.Checker = temp_project.Checker
  5489. project.CheckState = temp_project.CheckState
  5490. project.CheckTime = temp_project.CheckTime
  5491. project.TeamId = temp_project.TeamId
  5492. }
  5493. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5494. types := int64(json["type"].(float64))
  5495. project.Type = types
  5496. }
  5497. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5498. project_id := int64(json["project_id"].(float64))
  5499. project.ProjectId = project_id
  5500. }
  5501. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5502. team_id := int64(json["team_id"].(float64))
  5503. project.TeamId = team_id
  5504. }
  5505. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5506. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5507. project.Price = price
  5508. }
  5509. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5510. total, _ := json["total"].(string)
  5511. //totals, _ := strconv.ParseInt(total, 10, 64)
  5512. project.Count = total
  5513. }
  5514. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5515. medical_code, _ := json["medical_code"].(string)
  5516. project.MedListCodg = medical_code
  5517. }
  5518. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5519. single_dose, _ := json["single_dose"].(string)
  5520. project.SingleDose = single_dose
  5521. }
  5522. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5523. delivery_way, _ := json["delivery_way"].(string)
  5524. project.DeliveryWay = delivery_way
  5525. }
  5526. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5527. execution_frequency, _ := json["execution_frequency"].(string)
  5528. project.ExecutionFrequency = execution_frequency
  5529. }
  5530. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5531. remark, _ := json["remark"].(string)
  5532. project.Remark = remark
  5533. }
  5534. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5535. day, _ := json["number_days"].(string)
  5536. project.Day = day
  5537. }
  5538. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5539. unit, _ := json["unit"].(string)
  5540. project.Unit = unit
  5541. }
  5542. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5543. // frequency_type := int64(json["frequency_type"].(float64))
  5544. // project.FrequencyType = frequency_type
  5545. //}
  5546. //
  5547. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5548. // day_count := int64(json["day_count"].(float64))
  5549. // project.DayCount = day_count
  5550. //}
  5551. //
  5552. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5553. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5554. // week_day, _ := json["week_day"].(string)
  5555. // project.WeekDay = week_day
  5556. //}
  5557. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5558. //
  5559. //if project.ID == 0 {
  5560. // if stockConfig.IsOpen == 1 {
  5561. // if project.Type == 3 {
  5562. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5563. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5564. // good.Total = good.Total - f_count
  5565. // service.UpdateGoodInfo(&good)
  5566. // }
  5567. // }
  5568. //
  5569. //} else {
  5570. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5571. //
  5572. // if stockConfig.IsOpen == 1 {
  5573. // if project.Type == 3 {
  5574. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5575. // if project.Count < temp_project.Count {
  5576. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5577. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5578. //
  5579. // other_count := f_count_two - f_count_one
  5580. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5581. // good.Total = good.Total + other_count_two
  5582. // service.UpdateGoodInfo(&good)
  5583. // } else if project.Count > temp_project.Count {
  5584. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5585. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5586. //
  5587. // other_count := f_count_one - f_count_two
  5588. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5589. // good.Total = good.Total - other_count_two
  5590. // service.UpdateGoodInfo(&good)
  5591. // }
  5592. //
  5593. // }
  5594. // }
  5595. //
  5596. //}
  5597. return 0
  5598. }
  5599. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5600. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5601. utils.ErrorLog("drug_name")
  5602. return enums.ErrorCodeParamWrong
  5603. }
  5604. adviceName, _ := json["drug_name"].(string)
  5605. if len(adviceName) == 0 {
  5606. utils.ErrorLog("len(advice_name) == 0")
  5607. return enums.ErrorCodeParamWrong
  5608. }
  5609. advice.AdviceName = adviceName
  5610. adviceDesc, _ := json["advice_desc"].(string)
  5611. advice.AdviceDesc = adviceDesc
  5612. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5613. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5614. advice.DrugSpec = drugSpec
  5615. }
  5616. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5617. remark, _ := json["remark"].(string)
  5618. advice.Remark = remark
  5619. }
  5620. if json["id"] == nil {
  5621. advice.DrugId = 0
  5622. } else {
  5623. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5624. drug_id := int64(json["id"].(float64))
  5625. advice.DrugId = drug_id
  5626. }
  5627. }
  5628. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5629. groupno := int64(json["groupno"].(float64))
  5630. advice.Groupno = groupno
  5631. }
  5632. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5633. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5634. advice.IsSelfDrug = is_self_drug
  5635. }
  5636. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5637. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5638. drug_way_count, _ := json["drug_way_count"].(string)
  5639. advice.DrugWayCount = drug_way_count
  5640. }
  5641. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5642. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5643. advice.HospApprFlag = hosp_appr_flag
  5644. }
  5645. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5646. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5647. advice.PrescribingNumber = prescribingNumber
  5648. }
  5649. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5650. // frequency_type := int64(json["frequency_type"].(float64))
  5651. // advice.FrequencyType = frequency_type
  5652. //}
  5653. //
  5654. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5655. // day_count := int64(json["day_count"].(float64))
  5656. // advice.DayCount = day_count
  5657. //}
  5658. //
  5659. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5660. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5661. // week_day, _ := json["week_day"].(string)
  5662. // advice.WeekDay = week_day
  5663. //}
  5664. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5665. drugSpecUnit, _ := json["min_unit"].(string)
  5666. advice.DrugSpecUnit = drugSpecUnit
  5667. }
  5668. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5669. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5670. advice.SingleDose = singleDose
  5671. }
  5672. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5673. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5674. advice.SingleDoseUnit = singleDoseUnit
  5675. }
  5676. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5677. deliveryWay, _ := json["delivery_way"].(string)
  5678. advice.DeliveryWay = deliveryWay
  5679. }
  5680. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5681. executionFrequency, _ := json["execution_frequency"].(string)
  5682. advice.ExecutionFrequency = executionFrequency
  5683. }
  5684. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5685. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5686. advice.Price = price
  5687. }
  5688. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5689. med_list_codg, _ := json["medical_insurance_number"].(string)
  5690. advice.MedListCodg = med_list_codg
  5691. }
  5692. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5693. day := int64(json["day"].(float64))
  5694. advice.Day = day
  5695. }
  5696. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5697. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5698. advice.PrescribingNumberUnit = prescribingNumberUnit
  5699. }
  5700. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5701. advice_id := int64(json["advice_id"].(float64))
  5702. advice.ID = advice_id
  5703. if advice.ID > 0 {
  5704. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5705. if err == nil {
  5706. if hisAdvice.ID > 0 {
  5707. advice.ExecutionTime = hisAdvice.ExecutionTime
  5708. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5709. advice.ExecutionState = hisAdvice.ExecutionState
  5710. advice.CheckTime = hisAdvice.CheckTime
  5711. advice.Checker = hisAdvice.Checker
  5712. advice.CheckState = hisAdvice.CheckState
  5713. advice.StartTime = hisAdvice.StartTime
  5714. advice.HospApprFlag = hisAdvice.HospApprFlag
  5715. advice.IsMedicine = hisAdvice.IsMedicine
  5716. if hisAdvice.UserOrgId == 10028 {
  5717. 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 {
  5718. advice.ExecutionTime = 0
  5719. advice.ExecutionStaff = 0
  5720. advice.ExecutionState = 2
  5721. advice.CheckTime = 0
  5722. advice.Checker = 0
  5723. advice.CheckState = 2
  5724. }
  5725. } else {
  5726. 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 {
  5727. advice.ExecutionTime = 0
  5728. advice.ExecutionStaff = 0
  5729. advice.ExecutionState = 2
  5730. advice.CheckTime = 0
  5731. advice.Checker = 0
  5732. advice.CheckState = 2
  5733. }
  5734. }
  5735. //advice.Groupno = hisAdvice.Groupno
  5736. }
  5737. }
  5738. }
  5739. }
  5740. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5741. //
  5742. //if drugStockConfig.IsOpen == 1 {
  5743. //
  5744. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5745. // if advice.ID == 0 { //医嘱不存在
  5746. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5747. // drug.Total = drug.Total - advice.PrescribingNumber
  5748. // service.UpdateBaseDrugLib(&drug)
  5749. //
  5750. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5751. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5752. // drug.Total = drug.Total - num
  5753. // service.UpdateBaseDrugLib(&drug)
  5754. // }
  5755. //
  5756. // } else if advice.ID > 0 { //医嘱存在
  5757. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5758. // var num float64
  5759. //
  5760. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5761. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5762. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5763. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5764. // drug.Total = drug.Total + num
  5765. // service.UpdateBaseDrugLib(&drug)
  5766. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5767. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5768. // drug.Total = drug.Total - num
  5769. // service.UpdateBaseDrugLib(&drug)
  5770. // }
  5771. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5772. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5773. // if num2 > advice.PrescribingNumber {
  5774. // num = num2 - advice.PrescribingNumber
  5775. // drug.Total = drug.Total + num
  5776. // service.UpdateBaseDrugLib(&drug)
  5777. // } else if num2 < advice.PrescribingNumber {
  5778. // num = advice.PrescribingNumber - num2
  5779. // drug.Total = drug.Total - num
  5780. // service.UpdateBaseDrugLib(&drug)
  5781. // }
  5782. //
  5783. // }
  5784. //
  5785. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5786. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5787. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5788. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5789. // if num1 > num2 {
  5790. // num = num1 - num2
  5791. // drug.Total = drug.Total + num
  5792. // service.UpdateBaseDrugLib(&drug)
  5793. // } else if num1 < num2 {
  5794. // num = num2 - num1
  5795. // drug.Total = drug.Total - num
  5796. // service.UpdateBaseDrugLib(&drug)
  5797. // }
  5798. //
  5799. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5800. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5801. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5802. // if hisAdvice.PrescribingNumber > num2 {
  5803. // num = hisAdvice.PrescribingNumber - num2
  5804. // drug.Total = drug.Total + num
  5805. // service.UpdateBaseDrugLib(&drug)
  5806. // } else if num2 < advice.PrescribingNumber {
  5807. // num = num2 - hisAdvice.PrescribingNumber
  5808. // drug.Total = drug.Total - num
  5809. // service.UpdateBaseDrugLib(&drug)
  5810. // }
  5811. //
  5812. // }
  5813. // }
  5814. // }
  5815. //}
  5816. //
  5817. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5818. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5819. // advice.ExecutionTime = execution_time
  5820. //}
  5821. //
  5822. //
  5823. //
  5824. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5825. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5826. // advice.ExecutionStaff = execution_staff
  5827. //}
  5828. //
  5829. //
  5830. //
  5831. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5832. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5833. // advice.ExecutionState = execution_state
  5834. //}
  5835. //
  5836. //
  5837. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5838. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5839. // advice.CheckTime = check_time
  5840. //}
  5841. //
  5842. //
  5843. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5844. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5845. // advice.CheckState = check_state
  5846. //}
  5847. //
  5848. //
  5849. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5850. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5851. // advice.Checker = checker
  5852. //}
  5853. //
  5854. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5855. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5856. // advice.StartTime = start_time
  5857. //}
  5858. return 0
  5859. }
  5860. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5861. project.ExecutionStaff = 0
  5862. project.ExecutionState = 2
  5863. project.ExecutionTime = 0
  5864. project.Checker = 0
  5865. project.CheckState = 2
  5866. project.CheckTime = 0
  5867. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5868. id := int64(json["id"].(float64))
  5869. project.ID = id
  5870. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5871. project.ExecutionStaff = temp_project.ExecutionStaff
  5872. project.ExecutionState = temp_project.ExecutionState
  5873. project.ExecutionTime = temp_project.ExecutionTime
  5874. project.Checker = temp_project.Checker
  5875. project.CheckState = temp_project.CheckState
  5876. project.CheckTime = temp_project.CheckTime
  5877. project.TeamId = temp_project.TeamId
  5878. }
  5879. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5880. types := int64(json["type"].(float64))
  5881. project.Type = types
  5882. }
  5883. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5884. project_id := int64(json["project_id"].(float64))
  5885. project.ProjectId = project_id
  5886. }
  5887. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5888. team_id := int64(json["team_id"].(float64))
  5889. project.TeamId = team_id
  5890. }
  5891. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5892. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5893. project.Price = price
  5894. }
  5895. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5896. total, _ := json["total"].(string)
  5897. //totals, _ := strconv.ParseInt(total, 10, 64)
  5898. project.Count = total
  5899. }
  5900. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5901. medical_code, _ := json["medical_code"].(string)
  5902. project.MedListCodg = medical_code
  5903. }
  5904. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5905. single_dose, _ := json["single_dose"].(string)
  5906. project.SingleDose = single_dose
  5907. }
  5908. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5909. delivery_way, _ := json["delivery_way"].(string)
  5910. project.DeliveryWay = delivery_way
  5911. }
  5912. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5913. execution_frequency, _ := json["execution_frequency"].(string)
  5914. project.ExecutionFrequency = execution_frequency
  5915. }
  5916. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5917. remark, _ := json["remark"].(string)
  5918. project.Remark = remark
  5919. }
  5920. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5921. day, _ := json["number_days"].(string)
  5922. project.Day = day
  5923. }
  5924. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5925. unit, _ := json["unit"].(string)
  5926. project.Unit = unit
  5927. }
  5928. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5929. // frequency_type := int64(json["frequency_type"].(float64))
  5930. // project.FrequencyType = frequency_type
  5931. //}
  5932. //
  5933. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5934. // day_count := int64(json["day_count"].(float64))
  5935. // project.DayCount = day_count
  5936. //}
  5937. //
  5938. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5939. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5940. // week_day, _ := json["week_day"].(string)
  5941. // project.WeekDay = week_day
  5942. //}
  5943. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5944. //
  5945. //if project.ID == 0 {
  5946. // if stockConfig.IsOpen == 1 {
  5947. // if project.Type == 3 {
  5948. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5949. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5950. // good.Total = good.Total - f_count
  5951. // service.UpdateGoodInfo(&good)
  5952. // }
  5953. // }
  5954. //
  5955. //} else {
  5956. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5957. //
  5958. // if stockConfig.IsOpen == 1 {
  5959. // if project.Type == 3 {
  5960. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5961. // if project.Count < temp_project.Count {
  5962. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5963. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5964. //
  5965. // other_count := f_count_two - f_count_one
  5966. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5967. // good.Total = good.Total + other_count_two
  5968. // service.UpdateGoodInfo(&good)
  5969. // } else if project.Count > temp_project.Count {
  5970. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5971. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5972. //
  5973. // other_count := f_count_one - f_count_two
  5974. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5975. // good.Total = good.Total - other_count_two
  5976. // service.UpdateGoodInfo(&good)
  5977. // }
  5978. //
  5979. // }
  5980. // }
  5981. //
  5982. //}
  5983. return 0
  5984. }
  5985. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5986. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5987. id := int64(json["id"].(float64))
  5988. additionalCharge.ID = id
  5989. }
  5990. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5991. item_id := int64(json["item_id"].(float64))
  5992. additionalCharge.ItemId = item_id
  5993. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5994. if config.ID > 0 {
  5995. if len(config.Code) > 0 {
  5996. additionalCharge.MedListCodg = config.Code
  5997. }
  5998. }
  5999. }
  6000. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6001. // price := int64(json["price"].(float64))
  6002. // formatInt_price := strconv.FormatInt(price, 10)
  6003. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6004. // additionalCharge.Price = float_price
  6005. // }
  6006. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6007. // price := int64(json["price"].(float64))
  6008. // formatInt_price := strconv.FormatInt(price, 10)
  6009. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6010. // additionalCharge.Price = float_price
  6011. //}
  6012. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6013. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6014. additionalCharge.Price = price
  6015. }
  6016. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6017. count, _ := json["count"].(string)
  6018. counts, _ := strconv.ParseInt(count, 10, 64)
  6019. additionalCharge.Count = counts
  6020. }
  6021. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6022. item_name, _ := json["item_name"].(string)
  6023. additionalCharge.ItemName = item_name
  6024. }
  6025. return 0
  6026. }
  6027. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6028. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6029. utils.ErrorLog("drug_name")
  6030. return enums.ErrorCodeParamWrong
  6031. }
  6032. adviceName, _ := json["drug_name"].(string)
  6033. if len(adviceName) == 0 {
  6034. utils.ErrorLog("len(advice_name) == 0")
  6035. return enums.ErrorCodeParamWrong
  6036. }
  6037. advice.AdviceName = adviceName
  6038. adviceDesc, _ := json["advice_desc"].(string)
  6039. advice.AdviceDesc = adviceDesc
  6040. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6041. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6042. advice.DrugSpec = drugSpec
  6043. }
  6044. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6045. remark, _ := json["remark"].(string)
  6046. advice.Remark = remark
  6047. }
  6048. if json["id"] == nil {
  6049. advice.DrugId = 0
  6050. } else {
  6051. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6052. drug_id := int64(json["id"].(float64))
  6053. advice.DrugId = drug_id
  6054. }
  6055. }
  6056. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6057. groupno := int64(json["groupno"].(float64))
  6058. advice.Groupno = groupno
  6059. }
  6060. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6061. drugSpecUnit, _ := json["min_unit"].(string)
  6062. advice.DrugSpecUnit = drugSpecUnit
  6063. }
  6064. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6065. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6066. advice.SingleDose = singleDose
  6067. }
  6068. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6069. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6070. advice.SingleDoseUnit = singleDoseUnit
  6071. }
  6072. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6073. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6074. advice.PrescribingNumber = prescribingNumber
  6075. }
  6076. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6077. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6078. advice.PrescribingNumberUnit = prescribingNumberUnit
  6079. }
  6080. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6081. deliveryWay, _ := json["delivery_way"].(string)
  6082. advice.DeliveryWay = deliveryWay
  6083. }
  6084. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6085. executionFrequency, _ := json["execution_frequency"].(string)
  6086. advice.ExecutionFrequency = executionFrequency
  6087. }
  6088. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6089. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6090. advice.Price = price
  6091. }
  6092. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6093. med_list_codg, _ := json["medical_insurance_number"].(string)
  6094. advice.MedListCodg = med_list_codg
  6095. }
  6096. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6097. day := int64(json["day"].(float64))
  6098. advice.Day = day
  6099. }
  6100. advice.FrequencyType = 1
  6101. return 0
  6102. }
  6103. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  6104. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6105. types := int64(json["type"].(float64))
  6106. project.Type = types
  6107. }
  6108. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6109. project_id := int64(json["project_id"].(float64))
  6110. project.ProjectId = project_id
  6111. }
  6112. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6113. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6114. project.Price = price
  6115. }
  6116. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6117. total, _ := json["total"].(string)
  6118. //totals, _ := strconv.ParseInt(total, 10, 64)
  6119. project.Count = total
  6120. }
  6121. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6122. medical_code, _ := json["medical_code"].(string)
  6123. project.MedListCodg = medical_code
  6124. }
  6125. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6126. single_dose, _ := json["single_dose"].(string)
  6127. project.SingleDose = single_dose
  6128. }
  6129. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6130. delivery_way, _ := json["delivery_way"].(string)
  6131. project.DeliveryWay = delivery_way
  6132. }
  6133. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6134. execution_frequency, _ := json["execution_frequency"].(string)
  6135. project.ExecutionFrequency = execution_frequency
  6136. }
  6137. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6138. remark, _ := json["remark"].(string)
  6139. project.Remark = remark
  6140. }
  6141. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6142. day, _ := json["number_days"].(string)
  6143. project.Day = day
  6144. }
  6145. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6146. unit, _ := json["unit"].(string)
  6147. project.Unit = unit
  6148. }
  6149. project.FrequencyType = 1
  6150. return 0
  6151. }
  6152. func (c *HisApiController) GetHisOrderListTwo() {
  6153. start_time := c.GetString("start_time")
  6154. end_time := c.GetString("end_time")
  6155. timeLayout := "2006-01-02"
  6156. loc, _ := time.LoadLocation("Local")
  6157. var startTime int64
  6158. if len(start_time) > 0 {
  6159. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6160. if err != nil {
  6161. //fmt.Println(err)
  6162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6163. return
  6164. }
  6165. startTime = theTime.Unix()
  6166. }
  6167. var endTime int64
  6168. if len(end_time) > 0 {
  6169. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6170. if err != nil {
  6171. utils.ErrorLog(err.Error())
  6172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6173. return
  6174. }
  6175. endTime = theTime.Unix()
  6176. }
  6177. adminUser := c.GetAdminUserInfo()
  6178. org_id := adminUser.CurrentOrgId
  6179. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  6180. if err == nil {
  6181. c.ServeSuccessJSON(map[string]interface{}{
  6182. "order2": order,
  6183. })
  6184. } else {
  6185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6186. return
  6187. }
  6188. }
  6189. func (c *HisApiController) GetHisOrderList() {
  6190. page, _ := c.GetInt64("page", -1)
  6191. limit, _ := c.GetInt64("limit", -1)
  6192. start_time := c.GetString("start_time")
  6193. end_time := c.GetString("end_time")
  6194. types, _ := c.GetInt64("type", 0)
  6195. keywords := c.GetString("keywords")
  6196. p_type, _ := c.GetInt64("p_type", 0)
  6197. sort_type, _ := c.GetInt64("sort_type", 0)
  6198. charge_type, _ := c.GetInt64("charge_type", 0)
  6199. sch_type, _ := c.GetInt64("sch_type", 0)
  6200. zone_type, _ := c.GetInt64("zone_type", 0)
  6201. med_type, _ := c.GetInt64("med_type", 0)
  6202. timeLayout := "2006-01-02"
  6203. loc, _ := time.LoadLocation("Local")
  6204. var startTime int64
  6205. if len(start_time) > 0 {
  6206. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6207. if err != nil {
  6208. //fmt.Println(err)
  6209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6210. return
  6211. }
  6212. startTime = theTime.Unix()
  6213. }
  6214. var endTime int64
  6215. if len(end_time) > 0 {
  6216. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6217. if err != nil {
  6218. utils.ErrorLog(err.Error())
  6219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6220. return
  6221. }
  6222. endTime = theTime.Unix()
  6223. }
  6224. adminUser := c.GetAdminUserInfo()
  6225. org_id := adminUser.CurrentOrgId
  6226. 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)
  6227. for _, item := range order {
  6228. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  6229. item.DoctorName = info.Doctor
  6230. item.DepartmentName = info.XtHisDepartment.Name
  6231. }
  6232. if err == nil {
  6233. c.ServeSuccessJSON(map[string]interface{}{
  6234. "order": order,
  6235. "total": total,
  6236. })
  6237. } else {
  6238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6239. return
  6240. }
  6241. }
  6242. func (c *HisApiController) GetHisOrder() {
  6243. patient_id, _ := c.GetInt64("patient_id", 0)
  6244. number := c.GetString("number")
  6245. adminInfo := c.GetAdminUserInfo()
  6246. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  6247. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  6248. if err == nil {
  6249. c.ServeSuccessJSON(map[string]interface{}{
  6250. "order": order,
  6251. "prescription": prescriptions,
  6252. })
  6253. } else {
  6254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6255. return
  6256. }
  6257. }
  6258. func (c *HisApiController) GetHisPrescriptionList() {
  6259. record_date := c.GetString("record_date")
  6260. keywords := c.GetString("keywords")
  6261. page, _ := c.GetInt64("page")
  6262. limit, _ := c.GetInt64("limit")
  6263. sch_type, _ := c.GetInt64("sch_type")
  6264. timeLayout := "2006-01-02"
  6265. loc, _ := time.LoadLocation("Local")
  6266. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6267. if err != nil {
  6268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6269. return
  6270. }
  6271. recordDateTime := theTime.Unix()
  6272. adminInfo := c.GetAdminUserInfo()
  6273. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  6274. //adminInfo := c.GetAdminUserInfo()
  6275. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  6276. //fmt.Println(prescriptionOrder)
  6277. if err == nil {
  6278. c.ServeSuccessJSON(map[string]interface{}{
  6279. "order": prescriptionOrder,
  6280. "total": total,
  6281. })
  6282. } else {
  6283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6284. return
  6285. }
  6286. }
  6287. func (c *HisApiController) GetHisPrescriptionInfo() {
  6288. id, _ := c.GetInt64("id")
  6289. adminInfo := c.GetAdminUserInfo()
  6290. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  6291. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  6292. if err == nil {
  6293. c.ServeSuccessJSON(map[string]interface{}{
  6294. "order": prescriptionOrder,
  6295. "prescription": prescription,
  6296. })
  6297. } else {
  6298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6299. return
  6300. }
  6301. }
  6302. func (c *HisApiController) GetMedicalInsuranceConfig() {
  6303. adminUser := c.GetAdminUserInfo()
  6304. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  6305. c.ServeSuccessJSON(map[string]interface{}{
  6306. "config": config,
  6307. })
  6308. }
  6309. type ResultTwo struct {
  6310. ErrMsg interface{} `json:"err_msg"`
  6311. InfRefmsgid string `json:"inf_refmsgid"`
  6312. Infcode int64 `json:"infcode"`
  6313. Output struct {
  6314. Baseinfo struct {
  6315. Age float64 `json:"age"`
  6316. Brdy string `json:"brdy"`
  6317. Certno string `json:"certno"`
  6318. Gend string `json:"gend"`
  6319. Naty string `json:"naty"`
  6320. PsnCertType string `json:"psn_cert_type"`
  6321. PsnName string `json:"psn_name"`
  6322. PsnNo string `json:"psn_no"`
  6323. } `json:"baseinfo"`
  6324. Idetinfo []interface{} `json:"idetinfo"`
  6325. Iinfo []struct {
  6326. Balc float64 `json:"balc"`
  6327. CvlservFlag string `json:"cvlserv_flag"`
  6328. EmpName string `json:"emp_name"`
  6329. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  6330. Insutype string `json:"insutype"`
  6331. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  6332. PausInsuDate interface{} `json:"paus_insu_date"`
  6333. PsnInsuDate string `json:"psn_insu_date"`
  6334. PsnInsuStas string `json:"psn_insu_stas"`
  6335. PsnType string `json:"psn_type"`
  6336. } `json:"insuinfo"`
  6337. } `json:"output"`
  6338. RefmsgTime string `json:"refmsg_time"`
  6339. RespondTime string `json:"respond_time"`
  6340. Signtype interface{} `json:"signtype"`
  6341. WarnInfo interface{} `json:"warn_info"`
  6342. }
  6343. type ResultThree struct {
  6344. Cainfo interface{} `json:"cainfo"`
  6345. ErrMsg interface{} `json:"err_msg"`
  6346. InfRefmsgid string `json:"inf_refmsgid"`
  6347. Infcode int64 `json:"infcode"`
  6348. Output struct {
  6349. Data struct {
  6350. IptOtpNo string `json:"ipt_otp_no"`
  6351. MdtrtID string `json:"mdtrt_id"`
  6352. PsnNo string `json:"psn_no"`
  6353. } `json:"data"`
  6354. } `json:"output"`
  6355. RefmsgTime string `json:"refmsg_time"`
  6356. RespondTime string `json:"respond_time"`
  6357. Signtype interface{} `json:"signtype"`
  6358. WarnMsg interface{} `json:"warn_msg"`
  6359. }
  6360. type ResultFour struct {
  6361. Cainfo string `json:"cainfo"`
  6362. ErrMsg string `json:"err_msg"`
  6363. InfRefmsgid string `json:"inf_refmsgid"`
  6364. Infcode int64 `json:"infcode"`
  6365. Output struct {
  6366. Result []struct {
  6367. BasMednFlag string `json:"bas_medn_flag"`
  6368. ChldMedcFlag string `json:"chld_medc_flag"`
  6369. ChrgitmLv string `json:"chrgitm_lv"`
  6370. Cnt float64 `json:"cnt"`
  6371. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  6372. DrtReimFlag string `json:"drt_reim_flag"`
  6373. FeedetlSn string `json:"feedetl_sn"`
  6374. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6375. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  6376. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6377. ListSpItemFlag string `json:"list_sp_item_flag"`
  6378. LmtUsedFlag string `json:"lmt_used_flag"`
  6379. MedChrgitmType string `json:"med_chrgitm_type"`
  6380. Memo string `json:"memo"`
  6381. OverlmtAmt float64 `json:"overlmt_amt"`
  6382. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6383. Pric float64 `json:"pric"`
  6384. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  6385. SelfpayProp float64 `json:"selfpay_prop"`
  6386. } `json:"result"`
  6387. } `json:"output"`
  6388. RefmsgTime string `json:"refmsg_time"`
  6389. RespondTime string `json:"respond_time"`
  6390. Signtype string `json:"signtype"`
  6391. WarnMsg string `json:"warn_msg"`
  6392. }
  6393. type ResultFive struct {
  6394. Insutype string `json:"insutype"`
  6395. }
  6396. type ResultSix struct {
  6397. Cainfo interface{} `json:"cainfo"`
  6398. ErrMsg interface{} `json:"err_msg"`
  6399. InfRefmsgid string `json:"inf_refmsgid"`
  6400. Infcode int64 `json:"infcode"`
  6401. Output struct {
  6402. } `json:"output"`
  6403. RefmsgTime string `json:"refmsg_time"`
  6404. RespondTime string `json:"respond_time"`
  6405. Signtype interface{} `json:"signtype"`
  6406. WarnMsg interface{} `json:"warn_msg"`
  6407. }
  6408. type ResultSeven struct {
  6409. Cainfo string `json:"cainfo"`
  6410. ErrMsg string `json:"err_msg"`
  6411. InfRefmsgid string `json:"inf_refmsgid"`
  6412. Infcode int64 `json:"infcode"`
  6413. Output struct {
  6414. Setldetail []interface{} `json:"setldetail"`
  6415. Setlinfo struct {
  6416. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6417. AcctPay float64 `json:"acct_pay"`
  6418. ActPayDedc float64 `json:"act_pay_dedc"`
  6419. Age float64 `json:"age"`
  6420. Balc float64 `json:"balc"`
  6421. Brdy string `json:"brdy"`
  6422. Certno string `json:"certno"`
  6423. ClrOptins string `json:"clr_optins"`
  6424. ClrType string `json:"clr_type"`
  6425. ClrWay string `json:"clr_way"`
  6426. CvlservFlag string `json:"cvlserv_flag"`
  6427. CvlservPay float64 `json:"cvlserv_pay"`
  6428. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6429. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6430. Gend string `json:"gend"`
  6431. HifesPay float64 `json:"hifes_pay"`
  6432. HifmiPay float64 `json:"hifmi_pay"`
  6433. HifobPay float64 `json:"hifob_pay"`
  6434. HifpPay float64 `json:"hifp_pay"`
  6435. HospPartAmt float64 `json:"hosp_part_amt"`
  6436. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6437. Insutype string `json:"insutype"`
  6438. MafPay float64 `json:"maf_pay"`
  6439. MdtrtCertType string `json:"mdtrt_cert_type"`
  6440. MdtrtID string `json:"mdtrt_id"`
  6441. MedType string `json:"med_type"`
  6442. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6443. MedinsSetlID string `json:"medins_setl_id"`
  6444. Naty string `json:"naty"`
  6445. OthPay float64 `json:"oth_pay"`
  6446. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6447. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6448. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6449. PsnCashPay float64 `json:"psn_cash_pay"`
  6450. PsnCertType string `json:"psn_cert_type"`
  6451. PsnName string `json:"psn_name"`
  6452. PsnNo string `json:"psn_no"`
  6453. PsnPartAmt float64 `json:"psn_part_amt"`
  6454. PsnType string `json:"psn_type"`
  6455. SetlID string `json:"setl_id"`
  6456. SetlTime string `json:"setl_time"`
  6457. } `json:"setlinfo"`
  6458. } `json:"output"`
  6459. RefmsgTime string `json:"refmsg_time"`
  6460. RespondTime string `json:"respond_time"`
  6461. Signtype interface{} `json:"signtype"`
  6462. WarnMsg interface{} `json:"warn_msg"`
  6463. }
  6464. type ResultEight struct {
  6465. Cainfo string `json:"cainfo"`
  6466. ErrMsg string `json:"err_msg"`
  6467. InfRefmsgid string `json:"inf_refmsgid"`
  6468. Infcode int64 `json:"infcode"`
  6469. Output struct {
  6470. Stmtinfo struct {
  6471. SetlOptins string `json:"setl_optins"`
  6472. StmtRslt string `json:"stmt_rslt"`
  6473. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  6474. } `json:"stmtinfo"`
  6475. } `json:"output"`
  6476. RefmsgTime string `json:"refmsg_time"`
  6477. RespondTime string `json:"respond_time"`
  6478. Signtype interface{} `json:"signtype"`
  6479. WarnMsg interface{} `json:"warn_msg"`
  6480. }
  6481. type ResultNine struct {
  6482. Cainfo string `json:"cainfo"`
  6483. ErrMsg string `json:"err_msg"`
  6484. InfRefmsgid string `json:"inf_refmsgid"`
  6485. Infcode int64 `json:"infcode"`
  6486. Output struct {
  6487. FileQuryNo string `json:"file_qury_no"`
  6488. } `json:"output"`
  6489. RefmsgTime string `json:"refmsg_time"`
  6490. RespondTime string `json:"respond_time"`
  6491. Signtype interface{} `json:"signtype"`
  6492. WarnMsg interface{} `json:"warn_msg"`
  6493. }
  6494. type ResultTen struct {
  6495. Cainfo string `json:"cainfo"`
  6496. ErrMsg string `json:"err_msg"`
  6497. InfRefmsgid string `json:"inf_refmsgid"`
  6498. Infcode int64 `json:"infcode"`
  6499. Output struct {
  6500. DldEndtime string `json:"dld_endtime"`
  6501. FileQuryNo string `json:"file_qury_no"`
  6502. Filename string `json:"filename"`
  6503. } `json:"output"`
  6504. RefmsgTime string `json:"refmsg_time"`
  6505. RespondTime string `json:"respond_time"`
  6506. Signtype interface{} `json:"signtype"`
  6507. WarnMsg interface{} `json:"warn_msg"`
  6508. }
  6509. type ResultEleven struct {
  6510. Cainfo string `json:"cainfo"`
  6511. ErrMsg string `json:"err_msg"`
  6512. InfRefmsgid string `json:"inf_refmsgid"`
  6513. Infcode int64 `json:"infcode"`
  6514. Output struct {
  6515. Setlinfo struct {
  6516. FixmedinsName string `json:"fixmedins_name"`
  6517. FixmedinsCode string `json:"fixmedins_code"`
  6518. PsnNo string `json:"psn_no"`
  6519. PsnName string `json:"psn_name"`
  6520. HifobPay float64 `json:"hifob_pay"`
  6521. Gend string `json:"gend"`
  6522. Brdy string `json:"brdy"`
  6523. PsnCertType string `json:"psn_cert_type"`
  6524. PsnType string `json:"psn_type"`
  6525. EmpName string `json:"emp_name"`
  6526. Certno string `json:"certno"`
  6527. Insutype string `json:"insutype"`
  6528. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6529. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6530. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6531. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6532. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6533. ActPayDedc float64 `json:"act_pay_dedc"`
  6534. HifpPay float64 `json:"hifp_pay"`
  6535. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6536. CvlservPay float64 `json:"cvlserv_pay"`
  6537. HifesPay float64 `json:"hifes_pay"`
  6538. HifmiPay float64 `json:"hifmi_pay"`
  6539. MafPay float64 `json:"maf_pay"`
  6540. OthPay float64 `json:"oth_pay"`
  6541. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6542. PsnPay float64 `json:"psn_pay"`
  6543. AcctPay float64 `json:"acct_pay"`
  6544. CashPayamt float64 `json:"cash_payamt"`
  6545. Balc float64 `json:"balc"`
  6546. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6547. MedinsSetlId string `json:"medins_setl_id"`
  6548. RefdSetlFlag string `json:"refd_setl_flag"`
  6549. SetlTime string `json:"setl_time"`
  6550. MedType string `json:"med_type"`
  6551. } `json:"setlinfo"`
  6552. } `json:"output"`
  6553. RefmsgTime string `json:"refmsg_time"`
  6554. RespondTime string `json:"respond_time"`
  6555. Signtype interface{} `json:"signtype"`
  6556. WarnMsg interface{} `json:"warn_msg"`
  6557. }
  6558. type Custom struct {
  6559. DetItemFeeSumamt string
  6560. Cut string
  6561. FeedetlSn string
  6562. Price string
  6563. MedListCodg string
  6564. Type int64
  6565. AdviceId int64
  6566. ProjectId int64
  6567. ItemId int64
  6568. }
  6569. // 获取个人信息----挂号-----上传就诊信息
  6570. func (c *HisApiController) GetRegisterInfo() {
  6571. id, _ := c.GetInt64("id")
  6572. record_time := c.GetString("record_time")
  6573. settlementValue, _ := c.GetInt64("settlement_value")
  6574. medical_insurance_card := c.GetString("medical_insurance_card")
  6575. name := c.GetString("name")
  6576. id_card_type, _ := c.GetInt64("id_card_type")
  6577. certificates, _ := c.GetInt64("certificates")
  6578. medical_care, _ := c.GetInt64("medical_care")
  6579. birthday := c.GetString("birthday")
  6580. age, _ := c.GetInt64("age")
  6581. id_card := c.GetString("id_card")
  6582. register_type, _ := c.GetInt64("register")
  6583. doctor, _ := c.GetInt64("doctor")
  6584. department, _ := c.GetInt64("department")
  6585. gender, _ := c.GetInt64("sex")
  6586. phone := c.GetString("phone")
  6587. registration_fee, _ := c.GetFloat("registration_fee")
  6588. medical_expenses, _ := c.GetFloat("medical_expenses")
  6589. social_type, _ := c.GetInt64("social_type")
  6590. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6591. diagnosis_ids := c.GetString("diagnosis")
  6592. sick_type, _ := c.GetInt64("sick_type")
  6593. reg_type := c.GetString("p_type")
  6594. timeLayout := "2006-01-02"
  6595. loc, _ := time.LoadLocation("Local")
  6596. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6597. birthUnix := birthdays.Unix()
  6598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6599. if err != nil {
  6600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6601. return
  6602. }
  6603. recordDateTime := theTime.Unix()
  6604. adminInfo := c.GetAdminUserInfo()
  6605. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6606. if tempPatient.ID == 0 {
  6607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6608. return
  6609. }
  6610. var patient service.Patients
  6611. if id == 0 {
  6612. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6613. } else {
  6614. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6615. }
  6616. if patient.ID == 0 {
  6617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6618. return
  6619. }
  6620. if len(patient.IdCardNo) == 0 {
  6621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6622. return
  6623. }
  6624. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6625. if len(his) >= 1 {
  6626. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6627. if len(his) >= 1 && order.ID == 0 {
  6628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6629. return
  6630. }
  6631. }
  6632. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6633. fmt.Println(timeStr)
  6634. timeArr := strings.Split(timeStr, " ")
  6635. fmt.Println(timeArr)
  6636. timeArrTwo := strings.Split(timeArr[0], "-")
  6637. timeArrThree := strings.Split(timeArr[1], ":")
  6638. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6639. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6640. if len(lists) == 0 {
  6641. var hisPatient models.XtHisPatient
  6642. hisPatient = models.XtHisPatient{
  6643. Name: name,
  6644. Age: age,
  6645. Gender: gender,
  6646. Birthday: birthUnix,
  6647. Phone: phone,
  6648. MedicalTreatmentType: medical_care,
  6649. IdType: certificates,
  6650. IdCardNo: id_card,
  6651. BalanceAccountsType: settlementValue,
  6652. SocialType: social_type,
  6653. MedicalInsuranceNumber: medical_insurance_card,
  6654. RegisterType: register_type,
  6655. RegisterCost: registration_fee,
  6656. TreatmentCost: medical_expenses,
  6657. AdminUserId: adminInfo.AdminUser.Id,
  6658. UserOrgId: adminInfo.CurrentOrgId,
  6659. Status: 1,
  6660. RecordDate: recordDateTime,
  6661. IsReturn: 1,
  6662. PatientId: patient.ID,
  6663. Ctime: time.Now().Unix(),
  6664. Mtime: time.Now().Unix(),
  6665. Number: str,
  6666. IdCardType: id_card_type,
  6667. Departments: department,
  6668. Doctor: doctor,
  6669. PType: reg_type,
  6670. Diagnosis: diagnosis_ids,
  6671. SickType: sick_type,
  6672. }
  6673. service.CreateHisPatient(&hisPatient)
  6674. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6675. c.ServeSuccessJSON(map[string]interface{}{
  6676. "his_info": hisPatient,
  6677. })
  6678. } else {
  6679. //chrgBchno := rand.Intn(1000000) + 10000
  6680. var hisPatient models.XtHisPatient
  6681. hisPatient = models.XtHisPatient{
  6682. Name: name,
  6683. Age: age,
  6684. Gender: gender,
  6685. Birthday: birthUnix,
  6686. Phone: phone,
  6687. MedicalTreatmentType: medical_care,
  6688. IdType: certificates,
  6689. IdCardNo: id_card,
  6690. BalanceAccountsType: settlementValue,
  6691. SocialType: social_type,
  6692. MedicalInsuranceNumber: medical_insurance_card,
  6693. RegisterType: register_type,
  6694. RegisterCost: registration_fee,
  6695. TreatmentCost: medical_expenses,
  6696. AdminUserId: adminInfo.AdminUser.Id,
  6697. UserOrgId: adminInfo.CurrentOrgId,
  6698. Status: 1,
  6699. RecordDate: recordDateTime,
  6700. IsReturn: 1,
  6701. PatientId: patient.ID,
  6702. Ctime: time.Now().Unix(),
  6703. Mtime: time.Now().Unix(),
  6704. Number: str,
  6705. IdCardType: id_card_type,
  6706. Departments: department,
  6707. Doctor: doctor,
  6708. PType: reg_type,
  6709. Diagnosis: diagnosis_ids,
  6710. SickType: sick_type,
  6711. }
  6712. service.CreateHisPatient(&hisPatient)
  6713. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6714. c.ServeSuccessJSON(map[string]interface{}{
  6715. "his_info": hisPatient,
  6716. })
  6717. }
  6718. }
  6719. // 上传明细----结算
  6720. func (c *HisApiController) GetUploadInfo() {
  6721. id, _ := c.GetInt64("id")
  6722. record_time := c.GetString("record_time")
  6723. his_patient_id, _ := c.GetInt64("his_patient_id")
  6724. oth_desc := c.GetString("oth_desc")
  6725. pay_way, _ := c.GetInt64("pay_way")
  6726. pay_ways := c.GetString("pay_ways")
  6727. pay_price, _ := c.GetFloat("pay_price")
  6728. pay_card_no := c.GetString("pay_card_no")
  6729. discount_price, _ := c.GetFloat("discount_price")
  6730. preferential_price, _ := c.GetFloat("preferential_price")
  6731. reality_price, _ := c.GetFloat("reality_price")
  6732. found_price, _ := c.GetFloat("found_price")
  6733. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6734. private_price, _ := c.GetFloat("private_price")
  6735. timeLayout := "2006-01-02"
  6736. loc, _ := time.LoadLocation("Local")
  6737. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6738. fapiao_code := c.GetString("fapiao_code")
  6739. fapiao_number := c.GetString("fapiao_number")
  6740. diagnosis_id := c.GetString("diagnosis")
  6741. sick_type, _ := c.GetInt64("sick_type")
  6742. reg_type, _ := c.GetInt64("p_type")
  6743. order_id, _ := c.GetInt64("order_id")
  6744. cash_pay := c.GetString("cash_pay")
  6745. wechat_pay := c.GetString("wechat_pay")
  6746. ali_pay := c.GetString("ali_pay")
  6747. jifen_pay := c.GetString("jifen_pay")
  6748. band_card_pay := c.GetString("band_card_pay")
  6749. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6750. tmp_decimal := c.GetString("tmp_decimal")
  6751. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6752. var decimal float64 //本次使用的押金
  6753. var errmsg error
  6754. tx := service.XTWriteDB().Begin() //开了事务
  6755. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6756. defer func() {
  6757. if errmsg != nil {
  6758. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6759. tx.Rollback()
  6760. } else {
  6761. tx.Commit()
  6762. }
  6763. }()
  6764. fmt.Println("dec_way", dec_way)
  6765. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6766. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6767. return
  6768. }
  6769. if len(tmp_decimal) > 0 {
  6770. if tmp_decimal[0] == 45 {
  6771. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6772. return
  6773. }
  6774. }
  6775. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6776. fmt.Println(errs)
  6777. decimal = tt
  6778. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6779. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6780. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6781. if err != nil {
  6782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6783. return
  6784. }
  6785. recordDateTime := theTime.Unix()
  6786. adminUser := c.GetAdminUserInfo()
  6787. var prescriptions []*models.HisPrescription
  6788. var prescriptionsOne []*models.HisPrescription
  6789. var start_time int64
  6790. var end_time int64
  6791. ids_str := c.GetString("ids")
  6792. ids_arr := strings.Split(ids_str, ",")
  6793. if tempOrder.ID == 0 {
  6794. if settle_accounts_type == 1 { //日结
  6795. fmt.Println(reg_type)
  6796. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6797. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6798. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6799. } else {
  6800. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6801. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6802. }
  6803. } else { //月结
  6804. start_time_str := c.GetString("start_time")
  6805. end_time_str := c.GetString("end_time")
  6806. timeLayout := "2006-01-02"
  6807. loc, _ := time.LoadLocation("Local")
  6808. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6809. if err != nil {
  6810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6811. return
  6812. }
  6813. recordStartTime := theStartTime.Unix()
  6814. start_time = recordStartTime
  6815. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6816. if err != nil {
  6817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6818. return
  6819. }
  6820. recordEndTime := theEndTime.Unix()
  6821. end_time = recordEndTime
  6822. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6823. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6824. }
  6825. var goods []*models.DialysisBeforePrepareGoods
  6826. var newGoods []*models.NewDialysisBeforePrepareGoods
  6827. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6828. var infos []*models.HisDoctorAdviceInfo
  6829. var infoList []*models.HisDoctorAdviceInfo
  6830. var hisAdvice []*models.HisDoctorAdviceInfo
  6831. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6832. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6833. //判断库存不足
  6834. //结算出库开关
  6835. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6836. if settConfig.IsOpen == 1 {
  6837. //判断库存的地方
  6838. for _, info := range prescriptions {
  6839. if info.Type == 1 {
  6840. infos = append(infos, info.HisDoctorAdviceInfo...)
  6841. }
  6842. if info.Type == 2 {
  6843. for _, sumItem := range info.HisPrescriptionProject {
  6844. if sumItem.Type == 3 {
  6845. var good models.DialysisBeforePrepareGoods
  6846. var newGood models.NewDialysisBeforePrepareGoods
  6847. good.GoodId = sumItem.GoodInfo.ID
  6848. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6849. count, _ := strconv.Atoi(sumItem.Count)
  6850. good.Count = int64(count)
  6851. good.StorehouseId = houseConfig.StorehouseOutInfo
  6852. good.ProjectId = sumItem.ID
  6853. goods = append(goods, &good)
  6854. newGood.GoodId = sumItem.GoodInfo.ID
  6855. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6856. count2, _ := strconv.Atoi(sumItem.Count)
  6857. newGood.Count = int64(count2)
  6858. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6859. newGood.ProjectId = sumItem.ID
  6860. newGoods = append(newGoods, &newGood)
  6861. }
  6862. }
  6863. }
  6864. }
  6865. for _, info := range prescriptionsOne {
  6866. if info.Type == 1 {
  6867. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6868. }
  6869. if info.Type == 2 {
  6870. for _, sumItem := range info.HisPrescriptionProject {
  6871. if sumItem.Type == 3 {
  6872. var newGood models.NewDialysisBeforePrepareGoods
  6873. newGood.GoodId = sumItem.GoodInfo.ID
  6874. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6875. count2, _ := strconv.Atoi(sumItem.Count)
  6876. newGood.Count = int64(count2)
  6877. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6878. newGood.ProjectId = sumItem.ID
  6879. newGoodOne = append(newGoodOne, &newGood)
  6880. }
  6881. }
  6882. }
  6883. }
  6884. //判断
  6885. for _, itemOne := range infos {
  6886. for _, itemTwo := range hisAdvice {
  6887. if itemOne.DrugId == itemTwo.DrugId {
  6888. itemTwo.Child = append(itemTwo.Child, itemOne)
  6889. }
  6890. }
  6891. }
  6892. for _, itemTwo := range hisAdvice {
  6893. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6894. var sum_out_count int64
  6895. for _, itemThree := range itemTwo.Child {
  6896. var prescribing_number int64
  6897. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6898. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6899. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6900. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6901. }
  6902. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6903. prescribing_number = parseIntPrescribingNumber
  6904. }
  6905. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6906. prescribing_number = parseIntPrescribingNumber
  6907. }
  6908. sum_out_count += prescribing_number
  6909. }
  6910. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6911. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6912. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6913. if sum_out_count > drugStockOut.FlushCount {
  6914. c.ServeSuccessJSON(map[string]interface{}{
  6915. "msg": "2",
  6916. "drug": medical,
  6917. })
  6918. return
  6919. }
  6920. }
  6921. fmt.Println("newGoods99999988882os", newGoods)
  6922. for _, itemOne := range newGoods {
  6923. for _, item := range newGoodOne {
  6924. if itemOne.GoodId == item.GoodId {
  6925. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6926. }
  6927. }
  6928. }
  6929. for _, item := range newGoodOne {
  6930. var sum_out_count_one int64
  6931. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6932. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6933. sum_out_count_one += itemOne.Count
  6934. }
  6935. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6936. fmt.Println("sum_out_count_one", sum_out_count_one)
  6937. fmt.Println("list.FlushCount", list.FlushCount)
  6938. if sum_out_count_one > list.FlushCount {
  6939. c.ServeSuccessJSON(map[string]interface{}{
  6940. "msg": "3",
  6941. "good": good,
  6942. })
  6943. return
  6944. }
  6945. }
  6946. }
  6947. timestamp := time.Now().Unix()
  6948. tempTime := time.Unix(timestamp, 0)
  6949. timeFormat := tempTime.Format("20060102150405")
  6950. chrgBchno := rand.Intn(100000) + 10000
  6951. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6952. strconv.FormatInt(his.PatientId, 10)
  6953. var ids []int64
  6954. for _, item := range prescriptions {
  6955. ids = append(ids, item.ID)
  6956. }
  6957. var total float64
  6958. for _, item := range prescriptions {
  6959. fmt.Println(item)
  6960. if item.Type == 1 { //药品
  6961. for _, subItem := range item.HisDoctorAdviceInfo {
  6962. total = total + (subItem.Price * subItem.PrescribingNumber)
  6963. }
  6964. }
  6965. if item.Type == 2 { //项目
  6966. for _, subItem := range item.HisPrescriptionProject {
  6967. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6968. total = total + (subItem.Price * cnt)
  6969. }
  6970. }
  6971. for _, subItem := range item.HisAdditionalCharge {
  6972. total = total + (subItem.Price * float64(subItem.Count))
  6973. }
  6974. }
  6975. if reg_type == 1111 || reg_type == 1112 {
  6976. reg_type = 11
  6977. }
  6978. tm := time.Unix(time.Now().Unix(), 0)
  6979. allTotal := fmt.Sprintf("%.4f", total)
  6980. totals, _ := strconv.ParseFloat(allTotal, 64)
  6981. order := &models.HisOrder{
  6982. UserOrgId: adminUser.CurrentOrgId,
  6983. HisPatientId: his.ID,
  6984. PatientId: id,
  6985. SettleAccountsDate: recordDateTime,
  6986. Ctime: time.Now().Unix(),
  6987. Mtime: time.Now().Unix(),
  6988. Status: 1,
  6989. OrderStatus: 2,
  6990. MdtrtId: his.Number,
  6991. Number: chrg_bchno,
  6992. MedfeeSumamt: totals,
  6993. PayWay: pay_way,
  6994. PayWays: pay_ways,
  6995. PayPrice: pay_price,
  6996. MedType: strconv.Itoa(int(reg_type)),
  6997. PayCardNo: pay_card_no,
  6998. DiscountPrice: discount_price,
  6999. PreferentialPrice: preferential_price,
  7000. RealityPrice: reality_price,
  7001. FoundPrice: found_price,
  7002. MedicalInsurancePrice: medical_insurance_price,
  7003. PrivatePrice: private_price,
  7004. SettleEndTime: end_time,
  7005. SettleStartTime: start_time,
  7006. PsnPartAmt: totals,
  7007. PsnCashPay: totals,
  7008. SettleType: settle_accounts_type,
  7009. FaPiaoCode: fapiao_code,
  7010. FaPiaoNumber: fapiao_number,
  7011. Diagnosis: diagnosis_id,
  7012. PType: 2,
  7013. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7014. Decimal: decimal,
  7015. OthDesc: oth_desc,
  7016. CashPay: cash_pay,
  7017. WechatPay: wechat_pay,
  7018. AliPay: ali_pay,
  7019. JifenPay: jifen_pay,
  7020. BandCardPay: band_card_pay,
  7021. Creator: adminUser.AdminUser.Id,
  7022. }
  7023. err = service.CreateOrderTX(order, tx)
  7024. if err != nil {
  7025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7026. return
  7027. }
  7028. var customs []*Custom
  7029. for _, item := range prescriptions {
  7030. if item.Type == 1 { //药品a
  7031. for _, subItem := range item.HisDoctorAdviceInfo {
  7032. cus := &Custom{
  7033. AdviceId: subItem.ID,
  7034. ProjectId: 0,
  7035. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7036. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7037. FeedetlSn: subItem.FeedetlSn,
  7038. Price: fmt.Sprintf("%.4f", subItem.Price),
  7039. MedListCodg: subItem.MedListCodg,
  7040. Type: 1,
  7041. }
  7042. customs = append(customs, cus)
  7043. }
  7044. }
  7045. if item.Type == 2 { //项目
  7046. for _, subItem := range item.HisPrescriptionProject {
  7047. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7048. cus := &Custom{
  7049. AdviceId: 0,
  7050. ProjectId: subItem.ID,
  7051. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7052. Cut: fmt.Sprintf("%.4f", cnt),
  7053. FeedetlSn: subItem.FeedetlSn,
  7054. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7055. MedListCodg: subItem.MedListCodg,
  7056. Type: 2,
  7057. }
  7058. customs = append(customs, cus)
  7059. }
  7060. }
  7061. for _, item := range item.HisAdditionalCharge {
  7062. cus := &Custom{
  7063. ItemId: item.ID,
  7064. AdviceId: 0,
  7065. ProjectId: 0,
  7066. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  7067. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  7068. FeedetlSn: item.FeedetlSn,
  7069. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  7070. MedListCodg: item.XtHisAddtionConfig.Code,
  7071. Type: 3,
  7072. }
  7073. customs = append(customs, cus)
  7074. }
  7075. }
  7076. for _, item := range customs {
  7077. var advice_id int64 = 0
  7078. var project_id int64 = 0
  7079. var item_id int64 = 0
  7080. var types int64 = 0
  7081. if item.Type == 1 {
  7082. advice_id = item.AdviceId
  7083. project_id = 0
  7084. item_id = 0
  7085. } else if item.Type == 2 {
  7086. advice_id = 0
  7087. item_id = 0
  7088. project_id = item.ProjectId
  7089. } else if item.Type == 3 {
  7090. advice_id = 0
  7091. item_id = item.ItemId
  7092. project_id = 0
  7093. }
  7094. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  7095. cut, _ := strconv.ParseFloat(item.Cut, 32)
  7096. pric, _ := strconv.ParseFloat(item.Price, 32)
  7097. info := &models.HisOrderInfo{
  7098. OrderNumber: order.Number,
  7099. UploadDate: time.Now().Unix(),
  7100. AdviceId: advice_id,
  7101. DetItemFeeSumamt: detItemFeeSumamt,
  7102. Cnt: cut,
  7103. Pric: pric,
  7104. PatientId: id,
  7105. Status: 1,
  7106. Mtime: time.Now().Unix(),
  7107. Ctime: time.Now().Unix(),
  7108. UserOrgId: adminUser.CurrentOrgId,
  7109. HisPatientId: his.ID,
  7110. OrderId: order.ID,
  7111. ProjectId: project_id,
  7112. Type: types,
  7113. ItemId: item_id,
  7114. }
  7115. service.CreateOrderInfoTX(info, tx)
  7116. }
  7117. his.Diagnosis = diagnosis_id
  7118. his.SickType = sick_type
  7119. his.RegisterType = reg_type
  7120. his.MedicalTreatmentType = reg_type
  7121. service.UpdataHisPateintTX(&his, tx)
  7122. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  7123. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  7124. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  7125. //判断是否使用了押金
  7126. if dec_way == "true" {
  7127. tmpstring := strconv.FormatInt(order.ID, 10)
  7128. //扣押金
  7129. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  7130. order.Decimal = decimal
  7131. service.UpDateOrderTwo(order, tx)
  7132. if errmsg != nil {
  7133. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  7134. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7135. return
  7136. }
  7137. }
  7138. if err == nil {
  7139. for _, info := range prescriptions {
  7140. if info.Type == 1 {
  7141. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  7142. }
  7143. if info.Type == 2 {
  7144. for _, sumItem := range info.HisPrescriptionProject {
  7145. if sumItem.Type == 3 {
  7146. var good models.DialysisBeforePrepareGoods
  7147. var newGood models.NewDialysisBeforePrepareGoods
  7148. var oldGood models.OldDialysisBeforePrepareGoods
  7149. good.GoodId = sumItem.GoodInfo.ID
  7150. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7151. count, _ := strconv.Atoi(sumItem.Count)
  7152. good.Count = int64(count)
  7153. good.StorehouseId = houseConfig.StorehouseOutInfo
  7154. good.ProjectId = sumItem.ID
  7155. good.PatientId = sumItem.PatientId
  7156. goods = append(goods, &good)
  7157. newGood.GoodId = sumItem.GoodInfo.ID
  7158. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7159. count2, _ := strconv.Atoi(sumItem.Count)
  7160. newGood.Count = int64(count2)
  7161. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7162. newGood.ProjectId = sumItem.ID
  7163. newGood.PatientId = sumItem.HisPatientId
  7164. newGoods = append(newGoods, &newGood)
  7165. oldGood.GoodId = sumItem.GoodInfo.ID
  7166. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7167. count3, _ := strconv.Atoi(sumItem.Count)
  7168. oldGood.Count = int64(count3)
  7169. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  7170. oldGood.ProjectId = sumItem.ID
  7171. oldGood.RecordDate = sumItem.RecordDate
  7172. oldGood.PatientId = sumItem.HisPatientId
  7173. oldGoods = append(oldGoods, &oldGood)
  7174. }
  7175. }
  7176. }
  7177. }
  7178. if settConfig.IsOpen == 1 {
  7179. for _, item := range infoList {
  7180. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7181. if medical.IsUse == 2 {
  7182. //药品出库
  7183. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  7184. //查询默认仓库
  7185. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  7186. //查询默认仓库剩余多少库存
  7187. var sum_count int64
  7188. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7189. for _, its := range stockInfo {
  7190. if its.MaxUnit == medical.MaxUnit {
  7191. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7192. }
  7193. sum_count += its.StockMaxNumber + its.StockMinNumber
  7194. }
  7195. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7196. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7197. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  7198. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  7199. }
  7200. }
  7201. orgId := c.GetAdminUserInfo().CurrentOrgId
  7202. if len(oldGoods) > 0 {
  7203. timeStr := time.Now().Format("2006-01-02")
  7204. timeArr := strings.Split(timeStr, "-")
  7205. total, _ := service.FindAllWarehouseOut(orgId)
  7206. total = total + 1
  7207. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7208. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7209. number = number + total
  7210. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7211. operation_time := time.Now().Unix()
  7212. creater := c.GetAdminUserInfo().AdminUser.Id
  7213. //查询默认出库仓库库存
  7214. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7215. recordDateStr := time.Now().Format("2006-01-02")
  7216. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  7217. nowtime := recordDate.Unix()
  7218. warehouseOut := models.WarehouseOut{
  7219. WarehouseOutOrderNumber: warehousing_out_order,
  7220. OperationTime: operation_time,
  7221. OrgId: orgId,
  7222. Creater: creater,
  7223. Ctime: time.Now().Unix(),
  7224. Status: 1,
  7225. WarehouseOutTime: nowtime,
  7226. Type: 1,
  7227. StorehouseId: storeConfig.StorehouseOutInfo,
  7228. IsCheck: 1,
  7229. OrderId: order.ID,
  7230. IsSys: 5,
  7231. }
  7232. //查询是否生成出库单
  7233. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  7234. if out.ID == 0 {
  7235. service.AddSigleWarehouseOut(&warehouseOut)
  7236. }
  7237. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  7238. for _, item := range oldGoods {
  7239. dialyPrepareOne := models.DialysisBeforePrepare{
  7240. GoodTypeId: item.GoodTypeId,
  7241. GoodId: item.GoodId,
  7242. PatientId: his.PatientId,
  7243. RecordDate: item.RecordDate,
  7244. UserOrgId: adminUser.CurrentOrgId,
  7245. Count: item.Count,
  7246. Ctime: time.Now().Unix(),
  7247. Creater: adminUser.AdminUser.Id,
  7248. CommdityCode: item.CommdityCode,
  7249. Status: 1,
  7250. StorehouseId: houseConfig.StorehouseOutInfo,
  7251. }
  7252. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  7253. //非零用
  7254. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  7255. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  7256. //查询剩余库存
  7257. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7258. var sum_count int64
  7259. for _, item := range goodList {
  7260. sum_count += item.StockCount
  7261. }
  7262. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  7263. //耗材
  7264. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  7265. }
  7266. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  7267. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  7268. //查询剩余库存
  7269. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7270. var sum_count int64
  7271. for _, item := range goodList {
  7272. sum_count += item.StockCount
  7273. }
  7274. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  7275. //耗材
  7276. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  7277. }
  7278. }
  7279. }
  7280. }
  7281. c.ServeSuccessJSON(map[string]interface{}{
  7282. "msg": "结算成功",
  7283. })
  7284. }
  7285. }
  7286. }
  7287. // 退款
  7288. func (c *HisApiController) Refund() {
  7289. order_id, _ := c.GetInt64("order_id")
  7290. order, _ := service.GetHisOrderByID(order_id)
  7291. adminUser := c.GetAdminUserInfo()
  7292. orgid := c.GetAdminUserInfo().CurrentOrgId
  7293. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  7294. if err != nil {
  7295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7296. return
  7297. }
  7298. tmp := strconv.FormatInt(order.ID, 10)
  7299. //当押金不为零时产生退费记录
  7300. if order.Decimal != 0 {
  7301. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  7302. if err != nil {
  7303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7304. return
  7305. }
  7306. }
  7307. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  7308. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  7309. var goods []*models.DialysisBeforePrepareGoods
  7310. var newGoods []*models.NewDialysisBeforePrepareGoods
  7311. var infos []*models.HisDoctorAdviceInfo
  7312. for _, info := range orders {
  7313. if info.AdviceId > 0 && info.ProjectId == 0 {
  7314. infos = append(infos, &info.HisDoctorAdviceInfo)
  7315. }
  7316. if info.ProjectId > 0 && info.AdviceId == 0 {
  7317. if info.HisPrescriptionProject.Type == 3 {
  7318. var good models.DialysisBeforePrepareGoods
  7319. var newGood models.NewDialysisBeforePrepareGoods
  7320. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  7321. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  7322. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  7323. good.Count = int64(count)
  7324. good.StorehouseId = houseConfig.StorehouseOutInfo
  7325. good.ProjectId = info.HisPrescriptionProject.ID
  7326. good.PatientId = info.PatientId
  7327. good.OrderId = order_id
  7328. goods = append(goods, &good)
  7329. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  7330. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  7331. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  7332. newGood.Count = int64(count2)
  7333. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7334. newGood.ProjectId = info.HisPrescriptionProject.ID
  7335. newGood.RecordDate = order.SettleAccountsDate
  7336. newGood.UserOrgId = order.UserOrgId
  7337. newGood.PatientId = info.PatientId
  7338. newGood.OrderId = order_id
  7339. newGoods = append(newGoods, &newGood)
  7340. }
  7341. }
  7342. }
  7343. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7344. if settConfig.IsOpen == 1 {
  7345. for _, item := range infos {
  7346. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  7347. }
  7348. for _, item := range newGoods {
  7349. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  7350. }
  7351. }
  7352. c.ServeSuccessJSON(map[string]interface{}{
  7353. "msg": "退费成功",
  7354. })
  7355. }
  7356. func (c *HisApiController) RefundNumber() {
  7357. his_patient_id, _ := c.GetInt64("id")
  7358. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7359. info.Status = 0
  7360. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  7361. if count > 0 {
  7362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  7363. return
  7364. }
  7365. err := service.SaveHisPatient(info)
  7366. if err == nil {
  7367. c.ServeSuccessJSON(map[string]interface{}{
  7368. "msg": "退号成功",
  7369. })
  7370. } else {
  7371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7372. return
  7373. }
  7374. }
  7375. func (this *HisApiController) AdditionalCharge() {
  7376. dataBody := make(map[string]interface{}, 0)
  7377. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7378. fmt.Println(err)
  7379. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  7380. patient_id := int64(dataBody["patient_id"].(float64))
  7381. medicineData, _ := dataBody["medicineData"].([]interface{})
  7382. adminUserInfo := this.GetAdminUserInfo()
  7383. orgId := adminUserInfo.CurrentOrgId
  7384. admin_user_id := adminUserInfo.AdminUser.Id
  7385. timeStr := time.Now().Format("2006-01-02")
  7386. timeLayout := "2006-01-02 15:04:05"
  7387. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  7388. timenow := timeStringToTime.Unix()
  7389. var additionalCharges []*models.HisAdditionalCharge
  7390. for _, item := range medicineData {
  7391. var randNum int
  7392. randNum = rand.Intn(10000) + 1000
  7393. timestamp := time.Now().Unix()
  7394. tempTime := time.Unix(timestamp, 0)
  7395. timeFormat := tempTime.Format("20060102150405")
  7396. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  7397. items := item.(map[string]interface{})
  7398. money := items["price"].(string)
  7399. item_id_str := items["item_id"].(string)
  7400. name := items["name"].(string)
  7401. id_str := items["id"].(string)
  7402. moneys, _ := strconv.ParseInt(money, 10, 64)
  7403. monStr := strconv.FormatInt(moneys, 10)
  7404. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  7405. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  7406. id, _ := strconv.ParseInt(id_str, 10, 64)
  7407. additionalCharge := &models.HisAdditionalCharge{
  7408. ID: id,
  7409. HisPatientId: his_patient_id,
  7410. UserOrgId: orgId,
  7411. PatientId: patient_id,
  7412. RecordDate: timenow,
  7413. Price: monneyStr,
  7414. Status: 1,
  7415. ItemName: name,
  7416. ItemId: item_id,
  7417. AdminUserId: admin_user_id,
  7418. CreatedTime: time.Now().Unix(),
  7419. OrderStatus: 0,
  7420. PrescriptionNumber: "",
  7421. BatchNumber: "",
  7422. FeedetlSn: p_number,
  7423. }
  7424. service.CreateAdditionalCharge(additionalCharge)
  7425. additionalCharges = append(additionalCharges, additionalCharge)
  7426. }
  7427. this.ServeSuccessJSON(map[string]interface{}{
  7428. "msg": "添加成功",
  7429. "additional_charges": additionalCharges,
  7430. })
  7431. }
  7432. func (this *HisApiController) DeleteAddition() {
  7433. id, _ := this.GetInt64("id")
  7434. //TODO 需要判断是否已经结算
  7435. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  7436. if err == nil {
  7437. this.ServeSuccessJSON(map[string]interface{}{
  7438. "msg": "删除成功",
  7439. })
  7440. return
  7441. } else {
  7442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7443. return
  7444. }
  7445. }
  7446. func (this *HisApiController) GetAdminUsers() {
  7447. adminUser := this.GetAdminUserInfo()
  7448. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  7449. this.ServeSuccessJSON(map[string]interface{}{
  7450. "doctors": doctors,
  7451. })
  7452. }
  7453. func (this *HisApiController) GetLastOrNextHisPrescription() {
  7454. change_type, _ := this.GetInt64("type", 0)
  7455. record_date := this.GetString("record_time")
  7456. patient_id, _ := this.GetInt64("patient_id", 0)
  7457. p_type, _ := this.GetInt64("p_type", 0)
  7458. timeLayout := "2006-01-02"
  7459. loc, _ := time.LoadLocation("Local")
  7460. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7461. record_time := theAdviceRecordTime.Unix()
  7462. adminUserInfo := this.GetAdminUserInfo()
  7463. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  7464. if err == nil {
  7465. if len(prescriptions) == 0 {
  7466. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  7467. return
  7468. } else {
  7469. this.ServeSuccessJSON(map[string]interface{}{
  7470. "prescriptions": prescriptions,
  7471. })
  7472. return
  7473. }
  7474. } else {
  7475. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7476. return
  7477. }
  7478. }
  7479. func (this *HisApiController) GetCallHisPrescription() {
  7480. patient_id, _ := this.GetInt64("patient_id", 0)
  7481. timeLayout := "2006-01-02"
  7482. loc, _ := time.LoadLocation("Local")
  7483. start_time := this.GetString("start_time")
  7484. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7485. end_time := this.GetString("end_time")
  7486. p_type, _ := this.GetInt64("p_type")
  7487. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7488. adminUserInfo := this.GetAdminUserInfo()
  7489. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  7490. if err == nil {
  7491. this.ServeSuccessJSON(map[string]interface{}{
  7492. "prescriptions": prescriptions,
  7493. })
  7494. return
  7495. } else {
  7496. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7497. return
  7498. }
  7499. }
  7500. func (this *HisApiController) GetHisDayPrescription() {
  7501. timeLayout := "2006-01-02"
  7502. loc, _ := time.LoadLocation("Local")
  7503. start_time := this.GetString("start_time")
  7504. patient_id, _ := this.GetInt64("patient_id", 0)
  7505. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7506. end_time := this.GetString("end_time")
  7507. p_type, _ := this.GetInt64("p_type")
  7508. order_status, _ := this.GetInt64("type")
  7509. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7510. adminUserInfo := this.GetAdminUserInfo()
  7511. var dayHisPrescription []*models.HisPrescription
  7512. var err error
  7513. if order_status == 1 || order_status == 0 {
  7514. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7515. } else if order_status == 2 {
  7516. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7517. }
  7518. var settle_total float64
  7519. for _, item := range dayHisPrescription {
  7520. if len(item.HisPrescriptionProject) > 0 {
  7521. for _, subItem := range item.HisPrescriptionProject {
  7522. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7523. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7524. settle_total = settle_total + total
  7525. }
  7526. }
  7527. if len(item.HisDoctorAdviceInfo) > 0 {
  7528. for _, subItem := range item.HisDoctorAdviceInfo {
  7529. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7530. settle_total = settle_total + total
  7531. }
  7532. }
  7533. }
  7534. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7535. if err == nil {
  7536. this.ServeSuccessJSON(map[string]interface{}{
  7537. "day_prescription": dayHisPrescription,
  7538. "settle_total": settle_total,
  7539. })
  7540. return
  7541. } else {
  7542. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7543. return
  7544. }
  7545. }
  7546. func (c *HisApiController) GetHisChargePatientList() {
  7547. record_date := c.GetString("record_date")
  7548. order_status, _ := c.GetInt64("type")
  7549. sch_type, _ := c.GetInt64("sch_type")
  7550. timeLayout := "2006-01-02"
  7551. loc, _ := time.LoadLocation("Local")
  7552. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7553. if err != nil {
  7554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7555. return
  7556. }
  7557. recordDateTime := theTime.Unix()
  7558. adminInfo := c.GetAdminUserInfo()
  7559. var tempPatients []*service.NewTempPatients
  7560. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7561. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7562. if order_status != 2 {
  7563. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7564. } else {
  7565. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7566. }
  7567. } else {
  7568. if order_status != 2 {
  7569. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7570. } else {
  7571. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7572. }
  7573. }
  7574. var patients []*service.NewTempPatients
  7575. var patients_two []*service.NewTempPatients
  7576. for _, item := range tempPatients {
  7577. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7578. //过滤掉没挂号的和没开处方的
  7579. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7580. patients = append(patients, item)
  7581. }
  7582. //过滤掉没挂号的
  7583. if len(item.HisPatient) > 0 {
  7584. patients_two = append(patients_two, item)
  7585. }
  7586. } else {
  7587. if len(item.HisPrescription) > 0 {
  7588. patients = append(patients, item)
  7589. }
  7590. }
  7591. }
  7592. c.ServeSuccessJSON(map[string]interface{}{
  7593. "list": patients,
  7594. "list_two": patients_two,
  7595. })
  7596. }
  7597. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7598. record_date := c.GetString("record_date")
  7599. timeLayout := "2006-01-02"
  7600. loc, _ := time.LoadLocation("Local")
  7601. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7602. if err != nil {
  7603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7604. return
  7605. }
  7606. recordDateTime := theTime.Unix()
  7607. adminUser := c.GetAdminUserInfo()
  7608. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7609. var patients []*service.Patients
  7610. for _, item := range tempPatients {
  7611. if item.HisPatient.ID == 0 {
  7612. patients = append(patients, item)
  7613. }
  7614. }
  7615. c.ServeSuccessJSON(map[string]interface{}{
  7616. "list": patients,
  7617. //"list_two": patients_two,
  7618. })
  7619. }
  7620. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7621. newArr = make([]*service.Patients, 0)
  7622. for i := 0; i < len(patient); i++ {
  7623. repeat := false
  7624. for j := i + 1; j < len(patient); j++ {
  7625. if patient[i].ID == patient[j].ID {
  7626. repeat = true
  7627. break
  7628. }
  7629. }
  7630. if !repeat {
  7631. newArr = append(newArr, patient[i])
  7632. }
  7633. }
  7634. return
  7635. }
  7636. func (c *HisApiController) GetHisChargePatientInfo() {
  7637. patient_id, _ := c.GetInt64("patient_id")
  7638. his_patient_id, _ := c.GetInt64("his_patient_id")
  7639. record_date := c.GetString("record_date")
  7640. //start_time := c.GetString("start_time")
  7641. //end_time := c.GetString("end_time")
  7642. order_status, _ := c.GetInt64("type", 0)
  7643. p_type, _ := c.GetInt64("p_type", 0)
  7644. order_id, _ := c.GetInt64("order_id", 0)
  7645. timeLayout := "2006-01-02"
  7646. loc, _ := time.LoadLocation("Local")
  7647. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7648. if err != nil {
  7649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7650. return
  7651. }
  7652. recordDateTime := theTime.Unix()
  7653. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7654. //if err != nil {
  7655. //
  7656. //}
  7657. //startRecordDateTime := startTime.Unix()
  7658. //
  7659. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7660. //if err != nil {
  7661. //
  7662. //}
  7663. //endRecordDateTime := endTime.Unix()
  7664. admin := c.GetAdminUserInfo()
  7665. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7666. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7667. var prescriptions []*models.HisPrescription
  7668. //var unChargeMonthPrescriptions []*models.HisPrescription
  7669. order, _ := service.GetHisOrderByID(order_id)
  7670. if order_status == 1 || order_status == 0 {
  7671. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7672. } else if order_status == 2 {
  7673. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7674. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7675. }
  7676. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7677. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7678. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7679. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7680. //获取所有科室信息
  7681. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7682. c.ServeSuccessJSON(map[string]interface{}{
  7683. "his_info": his_patient_info,
  7684. "xt_info": xt_patient_info,
  7685. "prescription": prescriptions,
  7686. "case_history": case_history,
  7687. "info": patientPrescriptionInfo,
  7688. "last_info": lastPatientPrescriptionInfo,
  7689. "order": order,
  7690. "doctors": doctors,
  7691. "department": department,
  7692. })
  7693. return
  7694. }
  7695. func (c *HisApiController) GetAllOrderDetail() {
  7696. order_id, _ := c.GetInt64("id", 0)
  7697. order, _ := service.GetHisOrderByID(order_id)
  7698. if order.ID == 0 {
  7699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7700. return
  7701. }
  7702. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7703. org_id := c.GetAdminUserInfo().CurrentOrgId
  7704. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7705. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7706. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7707. c.ServeSuccessJSON(map[string]interface{}{
  7708. "order": order,
  7709. "order_info": order_info,
  7710. "patient": patient,
  7711. "admin_info": adminInfo,
  7712. "hospital_record": record,
  7713. })
  7714. return
  7715. }
  7716. func (c *HisApiController) GetAllOrderDetailCollect() {
  7717. order_id, _ := c.GetInt64("id", 0)
  7718. order, _ := service.GetHisOrderByID(order_id)
  7719. if order.ID == 0 {
  7720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7721. return
  7722. }
  7723. org_id := c.GetAdminUserInfo().CurrentOrgId
  7724. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7725. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7726. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7727. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7728. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7729. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7730. var bedCostTotal float64 = 0 //床位总费
  7731. //var bedCostSelfTotal float64 = 0 //床位自费
  7732. var operationCostTotal float64 = 0 //手术费
  7733. //var operationCostSelfTotal float64 = 0 //手术费
  7734. var otherCostTotal float64 = 0 //其他费用
  7735. //var otherCostSelfTotal float64 = 0 //其他费用
  7736. var materialCostTotal float64 = 0 //材料费
  7737. //var materialCostSelfTotal float64 = 0 //材料费
  7738. var westernMedicineCostTotal float64 = 0 //西药费
  7739. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7740. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7741. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7742. var checkCostTotal float64 = 0 //检查费
  7743. //var checkCostSelfTotal float64 = 0 //检查费
  7744. var laboratoryCostTotal float64 = 0 //化验费
  7745. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7746. var treatCostTotal float64 = 0 //治疗费用
  7747. //var treatCostSelfTotal float64 = 0 //治疗费用
  7748. var zhenChaCostTotal float64 = 0 //其他费用
  7749. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7750. decimal.DivisionPrecision = 2
  7751. var BalanceAccountsType int64
  7752. if his.ID > 0 {
  7753. BalanceAccountsType = his.BalanceAccountsType
  7754. } else {
  7755. BalanceAccountsType = record.BalanceAccountsType
  7756. }
  7757. if BalanceAccountsType != 2 {
  7758. for _, item := range order_info {
  7759. if org_id == 10215 {
  7760. if item.MedChrgitmType == "01" { //床位费
  7761. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7762. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7763. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7764. }
  7765. if item.MedChrgitmType == "02" { //诊察费
  7766. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7767. //zhenChaCostSelfTotal = zhenChaCostTotal
  7768. }
  7769. if item.MedChrgitmType == "03" { //检查费
  7770. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7771. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7772. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7773. }
  7774. //if item.MedChrgitmType == "02" { //检查费
  7775. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7776. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7777. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7778. //}
  7779. if item.MedChrgitmType == "04" { //化验费
  7780. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7781. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7782. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7783. }
  7784. if item.MedChrgitmType == "05" { //治疗费
  7785. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7786. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7787. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7788. }
  7789. if item.MedChrgitmType == "06" { //手术费
  7790. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7791. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7792. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7793. }
  7794. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7795. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7796. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7797. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7798. }
  7799. if item.MedChrgitmType == "09" { //西药费
  7800. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7801. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7802. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7803. }
  7804. if item.MedChrgitmType == "11" { //中成费
  7805. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7806. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7807. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7808. }
  7809. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7810. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7811. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7812. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7813. }
  7814. } else if org_id == 10188 || org_id == 10217 {
  7815. if item.MedChrgitmType == "01" { //床位费
  7816. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7817. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7818. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7819. }
  7820. if item.MedChrgitmType == "02" { //诊察费
  7821. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7822. //zhenChaCostSelfTotal = zhenChaCostTotal
  7823. }
  7824. if item.MedChrgitmType == "03" { //检查费
  7825. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7826. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7827. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7828. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7829. }
  7830. //if item.MedChrgitmType == "02" { //检查费
  7831. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7832. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7833. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7834. //}
  7835. if item.MedChrgitmType == "04" { //化验费
  7836. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7837. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7838. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7839. }
  7840. if item.MedChrgitmType == "05" { //治疗费
  7841. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7842. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7843. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7844. }
  7845. if item.MedChrgitmType == "06" { //手术费
  7846. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7847. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7848. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7849. }
  7850. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7851. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7852. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7853. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7854. }
  7855. if item.MedChrgitmType == "09" { //西药费
  7856. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7857. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7858. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7859. }
  7860. if item.MedChrgitmType == "11" { //中成费
  7861. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7862. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7863. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7864. }
  7865. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7866. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7867. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7868. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7869. }
  7870. } else {
  7871. if item.MedChrgitmType == "01" { //床位费
  7872. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7873. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7874. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7875. }
  7876. //if item.MedChrgitmType == "02" { //诊察费
  7877. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7878. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7879. //}
  7880. if item.MedChrgitmType == "03" { //检查费
  7881. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7882. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7883. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7884. }
  7885. //if item.MedChrgitmType == "02" { //检查费
  7886. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7887. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7888. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7889. //}
  7890. if item.MedChrgitmType == "04" { //化验费
  7891. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7892. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7893. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7894. }
  7895. if item.MedChrgitmType == "05" { //治疗费
  7896. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7897. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7898. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7899. }
  7900. if item.MedChrgitmType == "06" { //手术费
  7901. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7902. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7903. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7904. }
  7905. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7906. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7907. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7908. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7909. }
  7910. if item.MedChrgitmType == "09" { //西药费
  7911. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7912. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7913. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7914. }
  7915. if item.MedChrgitmType == "11" { //中成费
  7916. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7917. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7918. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7919. }
  7920. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7921. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7922. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7923. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7924. }
  7925. }
  7926. }
  7927. c.ServeSuccessJSON(map[string]interface{}{
  7928. "order": order,
  7929. "order_info": order_info,
  7930. "patient": patient,
  7931. "admin_info": adminInfo,
  7932. "his_hospital": record,
  7933. "bedCostTotal": bedCostTotal,
  7934. "operationCostTotal": operationCostTotal,
  7935. "otherCostTotal": otherCostTotal,
  7936. "materialCostTotal": materialCostTotal,
  7937. "westernMedicineCostTotal": westernMedicineCostTotal,
  7938. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7939. "checkCostTotal": checkCostTotal,
  7940. "zhenChaCostTotal": zhenChaCostTotal,
  7941. "laboratoryCostTotal": laboratoryCostTotal,
  7942. "treatCostTotal": treatCostTotal,
  7943. })
  7944. } else {
  7945. for _, item := range order_info {
  7946. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7947. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7948. item.MedChrgitmType = "09"
  7949. }
  7950. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7951. if item.HisPrescriptionProject.Type == 2 {
  7952. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7953. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7954. case 0:
  7955. item.MedChrgitmType = "0"
  7956. break
  7957. case 1:
  7958. item.MedChrgitmType = "14"
  7959. break
  7960. case 2:
  7961. item.MedChrgitmType = "05"
  7962. break
  7963. case 3:
  7964. item.MedChrgitmType = "03"
  7965. break
  7966. case 4:
  7967. item.MedChrgitmType = "03"
  7968. break
  7969. case 5:
  7970. item.MedChrgitmType = "08"
  7971. break
  7972. case 6:
  7973. item.MedChrgitmType = "14"
  7974. break
  7975. case 7:
  7976. item.MedChrgitmType = "14"
  7977. break
  7978. case 8:
  7979. item.MedChrgitmType = "03"
  7980. break
  7981. case 9:
  7982. item.MedChrgitmType = "14"
  7983. break
  7984. case 10:
  7985. item.MedChrgitmType = "14"
  7986. break
  7987. case 11:
  7988. item.MedChrgitmType = "06"
  7989. break
  7990. case 12:
  7991. item.MedChrgitmType = "12"
  7992. break
  7993. case 13:
  7994. item.MedChrgitmType = "01"
  7995. break
  7996. case 14:
  7997. item.MedChrgitmType = "04"
  7998. break
  7999. case 15:
  8000. item.MedChrgitmType = "14"
  8001. break
  8002. }
  8003. } else {
  8004. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8005. case 1:
  8006. item.MedChrgitmType = "14"
  8007. break
  8008. case 2:
  8009. item.MedChrgitmType = "05"
  8010. break
  8011. case 3:
  8012. item.MedChrgitmType = "04"
  8013. break
  8014. case 4:
  8015. item.MedChrgitmType = "14"
  8016. break
  8017. case 5:
  8018. item.MedChrgitmType = "08"
  8019. break
  8020. case 6:
  8021. item.MedChrgitmType = "14"
  8022. break
  8023. case 7:
  8024. item.MedChrgitmType = "14"
  8025. break
  8026. case 8:
  8027. item.MedChrgitmType = "03"
  8028. break
  8029. case 9:
  8030. item.MedChrgitmType = "14"
  8031. break
  8032. }
  8033. }
  8034. } else if item.HisPrescriptionProject.Type == 3 {
  8035. item.MedChrgitmType = "08"
  8036. }
  8037. }
  8038. }
  8039. for _, item := range order_info {
  8040. if org_id == 10215 {
  8041. if item.MedChrgitmType == "01" { //床位费
  8042. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8043. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8044. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8045. }
  8046. if item.MedChrgitmType == "02" { //诊察费
  8047. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8048. //zhenChaCostSelfTotal = zhenChaCostTotal
  8049. }
  8050. if item.MedChrgitmType == "03" { //检查费
  8051. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8052. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8053. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8054. }
  8055. //if item.MedChrgitmType == "02" { //检查费
  8056. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8057. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8058. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8059. //}
  8060. if item.MedChrgitmType == "04" { //化验费
  8061. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8062. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8063. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8064. }
  8065. if item.MedChrgitmType == "05" { //治疗费
  8066. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8067. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8068. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8069. }
  8070. if item.MedChrgitmType == "06" { //手术费
  8071. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8072. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8073. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8074. }
  8075. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8076. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8077. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8078. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8079. }
  8080. if item.MedChrgitmType == "09" { //西药费
  8081. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8082. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8083. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8084. }
  8085. if item.MedChrgitmType == "11" { //中成费
  8086. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8087. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8088. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8089. }
  8090. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8091. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8092. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8093. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8094. }
  8095. } else {
  8096. if item.MedChrgitmType == "01" { //床位费
  8097. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8098. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8099. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8100. }
  8101. //if item.MedChrgitmType == "02" { //诊察费
  8102. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8103. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8104. //}
  8105. if item.MedChrgitmType == "03" { //检查费
  8106. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8107. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8108. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8109. }
  8110. //if item.MedChrgitmType == "02" { //检查费
  8111. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8112. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8113. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8114. //}
  8115. if item.MedChrgitmType == "04" { //化验费
  8116. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8117. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8118. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8119. }
  8120. if item.MedChrgitmType == "05" { //治疗费
  8121. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8122. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8123. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8124. }
  8125. if item.MedChrgitmType == "06" { //手术费
  8126. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8127. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8128. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8129. }
  8130. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8131. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8132. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8133. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8134. }
  8135. if item.MedChrgitmType == "09" { //西药费
  8136. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8137. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8138. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8139. }
  8140. if item.MedChrgitmType == "11" { //中成费
  8141. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8142. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8143. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8144. }
  8145. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8146. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8147. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8148. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8149. }
  8150. }
  8151. }
  8152. c.ServeSuccessJSON(map[string]interface{}{
  8153. "order": order,
  8154. "order_info": order_info,
  8155. "patient": patient,
  8156. "admin_info": adminInfo,
  8157. "his_hospital": record,
  8158. "bedCostTotal": bedCostTotal,
  8159. "operationCostTotal": operationCostTotal,
  8160. "otherCostTotal": otherCostTotal,
  8161. "materialCostTotal": materialCostTotal,
  8162. "westernMedicineCostTotal": westernMedicineCostTotal,
  8163. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8164. "checkCostTotal": checkCostTotal,
  8165. "zhenChaCostTotal": zhenChaCostTotal,
  8166. "laboratoryCostTotal": laboratoryCostTotal,
  8167. "treatCostTotal": treatCostTotal,
  8168. })
  8169. }
  8170. }
  8171. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  8172. page, _ := c.GetInt64("page")
  8173. limit, _ := c.GetInt64("limit")
  8174. keywords := c.GetString("keywords")
  8175. start_time := c.GetString("start_time")
  8176. end_time := c.GetString("end_time")
  8177. //clr_type := c.GetString("clr_type")
  8178. insutype := c.GetString("insutype")
  8179. timeLayout := "2006-01-02"
  8180. loc, _ := time.LoadLocation("Local")
  8181. var theStartTIme int64
  8182. if len(start_time) > 0 {
  8183. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8184. theStartTIme = theTime.Unix()
  8185. }
  8186. var theEndtTIme int64
  8187. if len(end_time) > 0 {
  8188. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8189. theEndtTIme = theTime.Unix()
  8190. }
  8191. if page <= 0 {
  8192. page = 1
  8193. }
  8194. if limit <= 0 {
  8195. limit = 10
  8196. }
  8197. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  8198. c.ServeSuccessJSON(map[string]interface{}{
  8199. "total": total,
  8200. "list": list,
  8201. })
  8202. return
  8203. }
  8204. func (c *HisApiController) GetPutOnRecordList() {
  8205. page, _ := c.GetInt64("page")
  8206. limit, _ := c.GetInt64("limit")
  8207. keywords := c.GetString("keywords")
  8208. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  8209. if page <= 0 {
  8210. page = 1
  8211. }
  8212. if limit <= 0 {
  8213. limit = 10
  8214. }
  8215. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  8216. c.ServeSuccessJSON(map[string]interface{}{
  8217. "total": total,
  8218. "list": list,
  8219. })
  8220. return
  8221. }
  8222. func (c *HisApiController) GetCompareData() {
  8223. start_time := c.GetString("start_time")
  8224. end_time := c.GetString("end_time")
  8225. insutype := c.GetString("insutype")
  8226. clr_type := c.GetString("clr_type")
  8227. timeLayout := "2006-01-02"
  8228. loc, _ := time.LoadLocation("Local")
  8229. var theStartTIme int64
  8230. if len(start_time) > 0 {
  8231. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8232. if err != nil {
  8233. theStartTIme = 0
  8234. }
  8235. theStartTIme = theTime.Unix()
  8236. }
  8237. var theEndtTIme int64
  8238. if len(end_time) > 0 {
  8239. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8240. if err != nil {
  8241. theEndtTIme = 0
  8242. }
  8243. theEndtTIme = theTime.Unix()
  8244. }
  8245. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  8246. fmt.Println(err)
  8247. if err == nil {
  8248. c.ServeSuccessJSON(map[string]interface{}{
  8249. "list": formData,
  8250. })
  8251. } else {
  8252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8253. return
  8254. }
  8255. }
  8256. func (c *HisApiController) GetFaPiaoData() {
  8257. order_id, _ := c.GetInt64("order_id")
  8258. patient_id, _ := c.GetInt64("patient_id")
  8259. //number := c.GetString("number")
  8260. adminUser := c.GetAdminUserInfo()
  8261. order, _ := service.GetHisOrderByID(order_id)
  8262. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8263. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8264. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8265. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8266. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  8267. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  8268. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8269. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8270. var bedCostTotal float64 = 0 //床位总费
  8271. var bedCostSelfTotal float64 = 0 //床位自费
  8272. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8273. var operationCostTotal float64 = 0 //手术费
  8274. var operationCostSelfTotal float64 = 0 //手术费
  8275. var operationCostPartSelfTotal float64 = 0 //手术费
  8276. var otherCostTotal float64 = 0 //其他费用
  8277. var otherCostSelfTotal float64 = 0 //其他费用
  8278. var otherCostPartSelfTotal float64 = 0 //其他费用
  8279. var materialCostTotal float64 = 0 //材料费
  8280. var materialCostSelfTotal float64 = 0 //材料费
  8281. var materialCostPartSelfTotal float64 = 0 //材料费
  8282. var westernMedicineCostTotal float64 = 0 //西药费
  8283. var westernMedicineCostSelfTotal float64 = 0 //西药费
  8284. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8285. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8286. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8287. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8288. var checkCostTotal float64 = 0 //检查费
  8289. var checkCostSelfTotal float64 = 0 //检查费
  8290. var checkCostPartSelfTotal float64 = 0 //检查费
  8291. var hiliCostTotal float64 = 0 //护理费
  8292. var hiliCostSelfTotal float64 = 0 //护理费
  8293. var hiliCostPartSelfTotal float64 = 0 //护理费
  8294. var laboratoryCostTotal float64 = 0 //化验费
  8295. var laboratoryCostSelfTotal float64 = 0 //化验费
  8296. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8297. var treatCostTotal float64 = 0 //治疗费用
  8298. var treatCostSelfTotal float64 = 0 //治疗费用
  8299. var treatCostPartSelfTotal float64 = 0 //治疗费用
  8300. var zhenChaCostTotal float64 = 0 //其他费用
  8301. var zhenChaCostSelfTotal float64 = 0 //其他费用
  8302. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8303. decimal.DivisionPrecision = 2
  8304. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8305. var balanceAccountsType int64
  8306. if his.ID > 0 {
  8307. balanceAccountsType = his.BalanceAccountsType
  8308. } else {
  8309. balanceAccountsType = his_hospital_record.BalanceAccountsType
  8310. }
  8311. if balanceAccountsType == 2 {
  8312. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8313. for _, item := range orderInfos_two {
  8314. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8315. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8316. item.MedChrgitmType = "09"
  8317. }
  8318. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8319. if item.HisPrescriptionProject.Type == 2 {
  8320. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8321. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8322. case 0:
  8323. item.MedChrgitmType = "0"
  8324. break
  8325. case 1:
  8326. item.MedChrgitmType = "14"
  8327. break
  8328. case 2:
  8329. item.MedChrgitmType = "05"
  8330. break
  8331. case 3:
  8332. item.MedChrgitmType = "03"
  8333. break
  8334. case 4:
  8335. item.MedChrgitmType = "03"
  8336. break
  8337. case 5:
  8338. item.MedChrgitmType = "08"
  8339. break
  8340. case 6:
  8341. item.MedChrgitmType = "14"
  8342. break
  8343. case 7:
  8344. item.MedChrgitmType = "14"
  8345. break
  8346. case 8:
  8347. item.MedChrgitmType = "03"
  8348. break
  8349. case 9:
  8350. item.MedChrgitmType = "14"
  8351. break
  8352. case 10:
  8353. item.MedChrgitmType = "14"
  8354. break
  8355. case 11:
  8356. item.MedChrgitmType = "06"
  8357. break
  8358. case 12:
  8359. item.MedChrgitmType = "12"
  8360. break
  8361. case 13:
  8362. item.MedChrgitmType = "01"
  8363. break
  8364. case 14:
  8365. item.MedChrgitmType = "04"
  8366. break
  8367. case 15:
  8368. item.MedChrgitmType = "02"
  8369. break
  8370. }
  8371. } else {
  8372. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8373. case 1:
  8374. item.MedChrgitmType = "14"
  8375. break
  8376. case 2:
  8377. item.MedChrgitmType = "05"
  8378. break
  8379. case 3:
  8380. item.MedChrgitmType = "03"
  8381. break
  8382. case 4:
  8383. item.MedChrgitmType = "03"
  8384. break
  8385. case 5:
  8386. item.MedChrgitmType = "08"
  8387. break
  8388. case 6:
  8389. item.MedChrgitmType = "14"
  8390. break
  8391. case 7:
  8392. item.MedChrgitmType = "14"
  8393. break
  8394. case 8:
  8395. item.MedChrgitmType = "03"
  8396. break
  8397. case 9:
  8398. item.MedChrgitmType = "14"
  8399. break
  8400. }
  8401. }
  8402. } else if item.HisPrescriptionProject.Type == 3 {
  8403. item.MedChrgitmType = "08"
  8404. }
  8405. }
  8406. }
  8407. for _, item := range orderInfos_two {
  8408. fmt.Println(item.MedChrgitmType)
  8409. if item.MedChrgitmType == "07" { //床位费
  8410. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8411. hiliCostSelfTotal = hiliCostTotal
  8412. }
  8413. if item.MedChrgitmType == "01" { //床位费
  8414. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8415. bedCostSelfTotal = bedCostTotal
  8416. }
  8417. if item.MedChrgitmType == "02" { //诊察费
  8418. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8419. zhenChaCostSelfTotal = zhenChaCostTotal
  8420. }
  8421. if item.MedChrgitmType == "03" { //检查费
  8422. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8423. checkCostSelfTotal = checkCostTotal
  8424. }
  8425. if item.MedChrgitmType == "04" { //化验费
  8426. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8427. laboratoryCostSelfTotal = laboratoryCostTotal
  8428. }
  8429. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8430. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8431. treatCostSelfTotal = treatCostTotal
  8432. }
  8433. if item.MedChrgitmType == "06" { //手术费
  8434. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8435. operationCostSelfTotal = treatCostTotal
  8436. }
  8437. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8438. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8439. materialCostSelfTotal = materialCostTotal
  8440. }
  8441. if item.MedChrgitmType == "09" { //西药费
  8442. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8443. westernMedicineCostSelfTotal = westernMedicineCostTotal
  8444. }
  8445. if item.MedChrgitmType == "11" { //中成费
  8446. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8447. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8448. }
  8449. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8450. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8452. otherCostSelfTotal = otherCostTotal
  8453. }
  8454. } else {
  8455. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8456. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8457. otherCostSelfTotal = otherCostTotal
  8458. }
  8459. }
  8460. }
  8461. } else {
  8462. for _, item := range orderInfos {
  8463. if item.MedChrgitmType == "01" { //床位费
  8464. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8465. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8466. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8467. }
  8468. if item.MedChrgitmType == "02" { //诊察费
  8469. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8470. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8471. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8472. }
  8473. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8474. if item.MedChrgitmType == "03" { //检查费
  8475. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8476. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8477. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8478. }
  8479. } else {
  8480. if item.MedChrgitmType == "03" { //检查费
  8481. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8482. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8483. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8484. }
  8485. }
  8486. if item.MedChrgitmType == "04" { //化验费
  8487. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8488. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8489. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8490. }
  8491. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8492. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8493. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8494. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8495. }
  8496. if item.MedChrgitmType == "06" { //手术费
  8497. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8498. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8499. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8500. }
  8501. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  8502. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8503. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8504. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8505. }
  8506. if item.MedChrgitmType == "07" { //西药费
  8507. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8508. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8509. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8510. }
  8511. if item.MedChrgitmType == "09" { //西药费
  8512. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8513. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8514. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8515. }
  8516. if item.MedChrgitmType == "11" { //中成费
  8517. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8518. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8519. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8520. }
  8521. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8522. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8523. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8524. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8525. }
  8526. }
  8527. }
  8528. timeLayout := "2006-01-02"
  8529. loc, _ := time.LoadLocation("Local")
  8530. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8531. if err != nil {
  8532. }
  8533. startRecordDateTime := startTime.Unix()
  8534. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8535. if err != nil {
  8536. }
  8537. endRecordDateTime := endTime.Unix()
  8538. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8539. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8540. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8541. c.ServeSuccessJSON(map[string]interface{}{
  8542. "order_number": order.Number, //业务流水号
  8543. "id_card_no": his.IdCardNo, //社会保障号
  8544. "patient": patient,
  8545. "department_name": department.Name, //科室
  8546. "number": his.Number, //门诊号
  8547. "date": order.SettleAccountsDate, //结算日期
  8548. "name": order.PsnName, //姓名
  8549. "gender": patient.Gender, //性别
  8550. "psn_cash_money": order.PsnCashPay, //个人支付
  8551. "pay_way": "门诊", //结算方式
  8552. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8553. "admin_user_name": admin.UserName, //收款员
  8554. "order": order,
  8555. "order_info": orderInfos_two,
  8556. "his": his,
  8557. "bedCostTotal": bedCostTotal,
  8558. "bedCostSelfTotal": bedCostSelfTotal,
  8559. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8560. "operationCostTotal": operationCostTotal,
  8561. "operationCostSelfTotal": operationCostSelfTotal,
  8562. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8563. "otherCostTotal": otherCostTotal,
  8564. "otherCostSelfTotal": otherCostSelfTotal,
  8565. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8566. "materialCostTotal": materialCostTotal,
  8567. "materialCostSelfTotal": materialCostSelfTotal,
  8568. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8569. "westernMedicineCostTotal": westernMedicineCostTotal,
  8570. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8571. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8572. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8573. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8574. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8575. "checkCostTotal": checkCostTotal,
  8576. "checkCostSelfTotal": checkCostSelfTotal,
  8577. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8578. "laboratoryCostTotal": laboratoryCostTotal,
  8579. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8580. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8581. "treatCostTotal": treatCostTotal,
  8582. "treatCostSelfTotal": treatCostSelfTotal,
  8583. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8584. "zhenChaCostTotal": zhenChaCostTotal,
  8585. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8586. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8587. "his_hospital_record": his_hospital_record,
  8588. "pre_pay_money": pre_pay_money,
  8589. "refund_sum": sum,
  8590. "doctor_info": doctor_info,
  8591. "hiliCostTotal": hiliCostTotal,
  8592. "hiliCostSelfTotal": hiliCostSelfTotal,
  8593. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8594. })
  8595. }
  8596. //func (c *HisApiController) GetFaPiaoDatas() {
  8597. // order_ids := c.GetString("order_ids")
  8598. // patient_id, _ := c.GetInt64("patient_id")
  8599. // adminUser := c.GetAdminUserInfo()
  8600. //
  8601. // orders := strings.Split(order_ids, ",")
  8602. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8603. //
  8604. // for _, item := range orders {
  8605. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8606. // order, _ := service.GetHisOrderByID(order_id)
  8607. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8608. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8609. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8610. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8611. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8612. //
  8613. // }
  8614. //
  8615. // var bedCostTotal float64 = 0 //床位总费
  8616. // var bedCostSelfTotal float64 = 0 //床位自费
  8617. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8618. //
  8619. // var operationCostTotal float64 = 0 //手术费
  8620. // var operationCostSelfTotal float64 = 0 //手术费
  8621. // var operationCostPartSelfTotal float64 = 0 //手术费
  8622. //
  8623. // var otherCostTotal float64 = 0 //其他费用
  8624. // var otherCostSelfTotal float64 = 0 //其他费用
  8625. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8626. //
  8627. // var materialCostTotal float64 = 0 //材料费
  8628. // var materialCostSelfTotal float64 = 0 //材料费
  8629. // var materialCostPartSelfTotal float64 = 0 //材料费
  8630. //
  8631. // var westernMedicineCostTotal float64 = 0 //西药费
  8632. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8633. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8634. //
  8635. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8636. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8637. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8638. //
  8639. // var checkCostTotal float64 = 0 //检查费
  8640. // var checkCostSelfTotal float64 = 0 //检查费
  8641. // var checkCostPartSelfTotal float64 = 0 //检查费
  8642. //
  8643. // var laboratoryCostTotal float64 = 0 //化验费
  8644. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8645. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8646. //
  8647. // var treatCostTotal float64 = 0 //治疗费用
  8648. // var treatCostSelfTotal float64 = 0 //治疗费用
  8649. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8650. //
  8651. // var zhenChaCostTotal float64 = 0 //其他费用
  8652. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8653. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8654. //
  8655. // decimal.DivisionPrecision = 2
  8656. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8657. //
  8658. // var balanceAccountsType int64
  8659. // if his.ID > 0 {
  8660. // balanceAccountsType = his.BalanceAccountsType
  8661. // } else {
  8662. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8663. // }
  8664. // if balanceAccountsType == 2 {
  8665. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8666. // for _, item := range orderInfos_two {
  8667. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8668. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8669. // item.MedChrgitmType = "09"
  8670. // }
  8671. //
  8672. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8673. // if item.HisPrescriptionProject.Type == 2 {
  8674. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8675. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8676. // case 0:
  8677. // item.MedChrgitmType = "0"
  8678. // break
  8679. // case 1:
  8680. // item.MedChrgitmType = "14"
  8681. // break
  8682. // case 2:
  8683. // item.MedChrgitmType = "05"
  8684. //
  8685. // break
  8686. // case 3:
  8687. // item.MedChrgitmType = "03"
  8688. //
  8689. // break
  8690. // case 4:
  8691. // item.MedChrgitmType = "03"
  8692. //
  8693. // break
  8694. // case 5:
  8695. // item.MedChrgitmType = "08"
  8696. //
  8697. // break
  8698. // case 6:
  8699. // item.MedChrgitmType = "14"
  8700. //
  8701. // break
  8702. // case 7:
  8703. // item.MedChrgitmType = "14"
  8704. //
  8705. // break
  8706. // case 8:
  8707. // item.MedChrgitmType = "03"
  8708. // break
  8709. // case 9:
  8710. // item.MedChrgitmType = "14"
  8711. // break
  8712. // case 10:
  8713. // item.MedChrgitmType = "14"
  8714. // break
  8715. // case 11:
  8716. // item.MedChrgitmType = "06"
  8717. // break
  8718. // case 12:
  8719. // item.MedChrgitmType = "12"
  8720. // break
  8721. // case 13:
  8722. // item.MedChrgitmType = "01"
  8723. // break
  8724. // case 14:
  8725. // item.MedChrgitmType = "04"
  8726. // break
  8727. // case 15:
  8728. // item.MedChrgitmType = "02"
  8729. // break
  8730. //
  8731. // }
  8732. //
  8733. // } else {
  8734. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8735. //
  8736. // case 1:
  8737. // item.MedChrgitmType = "14"
  8738. // break
  8739. // case 2:
  8740. // item.MedChrgitmType = "05"
  8741. //
  8742. // break
  8743. // case 3:
  8744. // item.MedChrgitmType = "03"
  8745. //
  8746. // break
  8747. // case 4:
  8748. // item.MedChrgitmType = "03"
  8749. //
  8750. // break
  8751. // case 5:
  8752. // item.MedChrgitmType = "08"
  8753. //
  8754. // break
  8755. // case 6:
  8756. // item.MedChrgitmType = "14"
  8757. //
  8758. // break
  8759. // case 7:
  8760. // item.MedChrgitmType = "14"
  8761. //
  8762. // break
  8763. // case 8:
  8764. // item.MedChrgitmType = "03"
  8765. // break
  8766. // case 9:
  8767. // item.MedChrgitmType = "14"
  8768. // break
  8769. //
  8770. // }
  8771. //
  8772. // }
  8773. //
  8774. // } else if item.HisPrescriptionProject.Type == 3 {
  8775. // item.MedChrgitmType = "08"
  8776. // }
  8777. // }
  8778. // }
  8779. //
  8780. // for _, item := range orderInfos_two {
  8781. // fmt.Println(item.MedChrgitmType)
  8782. // if item.MedChrgitmType == "01" { //床位费
  8783. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8784. // bedCostSelfTotal = bedCostTotal
  8785. // }
  8786. //
  8787. // if item.MedChrgitmType == "02" { //诊察费
  8788. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8789. // zhenChaCostSelfTotal = zhenChaCostTotal
  8790. // }
  8791. //
  8792. // if item.MedChrgitmType == "03" { //检查费
  8793. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8794. // checkCostSelfTotal = checkCostTotal
  8795. // }
  8796. //
  8797. // if item.MedChrgitmType == "04" { //化验费
  8798. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8799. // laboratoryCostSelfTotal = laboratoryCostTotal
  8800. // }
  8801. //
  8802. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8803. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8804. // treatCostSelfTotal = treatCostTotal
  8805. // }
  8806. //
  8807. // if item.MedChrgitmType == "06" { //手术费
  8808. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8809. // operationCostSelfTotal = treatCostTotal
  8810. // }
  8811. //
  8812. // if item.MedChrgitmType == "08" { //材料费
  8813. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8814. // materialCostSelfTotal = materialCostTotal
  8815. // }
  8816. //
  8817. // if item.MedChrgitmType == "09" { //西药费
  8818. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8819. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8820. // }
  8821. //
  8822. // if item.MedChrgitmType == "11" { //中成费
  8823. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8824. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8825. // }
  8826. //
  8827. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8828. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8829. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8830. // otherCostSelfTotal = otherCostTotal
  8831. // }
  8832. // } else {
  8833. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8834. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8835. // otherCostSelfTotal = otherCostTotal
  8836. // }
  8837. //
  8838. // }
  8839. //
  8840. // }
  8841. //
  8842. // } else {
  8843. // for _, item := range orderInfos {
  8844. // if item.MedChrgitmType == "01" { //床位费
  8845. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8846. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8847. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8848. // }
  8849. //
  8850. // if item.MedChrgitmType == "02" { //诊察费
  8851. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8852. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8853. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8854. // }
  8855. //
  8856. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8857. // if item.MedChrgitmType == "03" { //检查费
  8858. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8859. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8860. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8861. //
  8862. // }
  8863. // } else {
  8864. // if item.MedChrgitmType == "03" { //检查费
  8865. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8866. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8867. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8868. // }
  8869. //
  8870. // }
  8871. //
  8872. // if item.MedChrgitmType == "04" { //化验费
  8873. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8874. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8875. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8876. //
  8877. // }
  8878. //
  8879. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8880. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8881. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8882. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8883. //
  8884. // }
  8885. //
  8886. // if item.MedChrgitmType == "06" { //手术费
  8887. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8888. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8889. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8890. // }
  8891. //
  8892. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8893. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8894. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8895. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8896. // }
  8897. //
  8898. // if item.MedChrgitmType == "09" { //西药费
  8899. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8900. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8901. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8902. // }
  8903. //
  8904. // if item.MedChrgitmType == "11" { //中成费
  8905. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8906. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8907. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8908. // }
  8909. //
  8910. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8911. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8912. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8913. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8914. // }
  8915. //
  8916. // }
  8917. // }
  8918. // timeLayout := "2006-01-02"
  8919. // loc, _ := time.LoadLocation("Local")
  8920. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8921. // if err != nil {
  8922. // }
  8923. // startRecordDateTime := startTime.Unix()
  8924. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8925. // if err != nil {
  8926. // }
  8927. // endRecordDateTime := endTime.Unix()
  8928. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8929. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8930. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8931. //
  8932. // c.ServeSuccessJSON(map[string]interface{}{
  8933. // "order_number": order.Number, //业务流水号
  8934. // "id_card_no": his.IdCardNo, //社会保障号
  8935. // "department_name": department.Name, //科室
  8936. // "number": his.Number, //门诊号
  8937. // "date": order.SettleAccountsDate, //结算日期
  8938. // "name": order.PsnName, //姓名
  8939. // "gender": patient.Gender, //性别
  8940. // "psn_cash_money": order.PsnCashPay, //个人支付
  8941. // "pay_way": "门诊", //结算方式
  8942. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8943. // "admin_user_name": admin.UserName, //收款员
  8944. // "order": order,
  8945. // "order_info": orderInfos_two,
  8946. // "his": his,
  8947. // "bedCostTotal": bedCostTotal,
  8948. // "bedCostSelfTotal": bedCostSelfTotal,
  8949. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8950. // "operationCostTotal": operationCostTotal,
  8951. // "operationCostSelfTotal": operationCostSelfTotal,
  8952. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8953. // "otherCostTotal": otherCostTotal,
  8954. // "otherCostSelfTotal": otherCostSelfTotal,
  8955. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8956. // "materialCostTotal": materialCostTotal,
  8957. // "materialCostSelfTotal": materialCostSelfTotal,
  8958. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8959. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8960. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8961. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8962. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8963. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8964. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8965. // "checkCostTotal": checkCostTotal,
  8966. // "checkCostSelfTotal": checkCostSelfTotal,
  8967. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8968. // "laboratoryCostTotal": laboratoryCostTotal,
  8969. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8970. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8971. // "treatCostTotal": treatCostTotal,
  8972. // "treatCostSelfTotal": treatCostSelfTotal,
  8973. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8974. // "zhenChaCostTotal": zhenChaCostTotal,
  8975. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8976. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8977. // "his_hospital_record": his_hospital_record,
  8978. // "pre_pay_money": pre_pay_money,
  8979. // "refund_sum": sum,
  8980. // })
  8981. //
  8982. //}
  8983. func (this *HisApiController) GetIncomeStatisticsData() {
  8984. start_time := this.GetString("start_time")
  8985. end_time := this.GetString("end_time")
  8986. key_words := this.GetString("key_words")
  8987. limit, _ := this.GetInt64("limit")
  8988. page, _ := this.GetInt64("page")
  8989. if page <= 0 {
  8990. page = 1
  8991. }
  8992. if limit <= 0 {
  8993. limit = 10
  8994. }
  8995. statistics_type, _ := this.GetInt64("statistics_type")
  8996. admin := this.GetAdminUserInfo()
  8997. timeLayout := "2006-01-02"
  8998. loc, _ := time.LoadLocation("Local")
  8999. var theStartTIme int64
  9000. if len(start_time) > 0 {
  9001. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9002. if err != nil {
  9003. theStartTIme = 0
  9004. }
  9005. theStartTIme = theTime.Unix()
  9006. }
  9007. var theEndtTIme int64
  9008. if len(end_time) > 0 {
  9009. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9010. if err != nil {
  9011. theEndtTIme = 0
  9012. }
  9013. theEndtTIme = theTime.Unix()
  9014. }
  9015. if statistics_type == 1 {
  9016. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9017. this.ServeSuccessJSON(map[string]interface{}{
  9018. "list": list,
  9019. "total": total,
  9020. })
  9021. } else {
  9022. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9023. this.ServeSuccessJSON(map[string]interface{}{
  9024. "list": list,
  9025. "total": total,
  9026. })
  9027. }
  9028. }
  9029. func (c *HisApiController) PostProjectInformation() {
  9030. adminUser := c.GetAdminUserInfo()
  9031. orgId := adminUser.CurrentOrgId
  9032. dataBody := make(map[string]interface{}, 0)
  9033. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9034. if err != nil {
  9035. utils.ErrorLog(err.Error())
  9036. return
  9037. }
  9038. utils.ErrorLog("%v", dataBody)
  9039. var projectList []*models.HisProject
  9040. var total_goods []interface{}
  9041. tempProjects := dataBody["projects"].([]interface{})
  9042. total_goods = tempProjects
  9043. for index, projectMap := range tempProjects {
  9044. projectM := projectMap.(map[string]interface{})
  9045. var project models.HisProject
  9046. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9047. utils.ErrorLog("project_name")
  9048. return
  9049. }
  9050. project_name, _ := projectM["project_name"].(string)
  9051. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9052. err_log := models.ExportErrLog{
  9053. LogType: 6,
  9054. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9055. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9056. Status: 1,
  9057. CreateTime: time.Now().Unix(),
  9058. UpdateTime: time.Now().Unix(),
  9059. ExportTime: time.Now().Unix(),
  9060. }
  9061. service.CreateExportErrLog(&err_log)
  9062. continue
  9063. }
  9064. project.ProjectName = project_name
  9065. prices := projectM["price"].(string)
  9066. price, _ := strconv.ParseFloat(prices, 64)
  9067. if price <= 0 { //名字为空则生成一条导入错误日志
  9068. err_log := models.ExportErrLog{
  9069. LogType: 6,
  9070. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9071. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  9072. Status: 1,
  9073. CreateTime: time.Now().Unix(),
  9074. UpdateTime: time.Now().Unix(),
  9075. ExportTime: time.Now().Unix(),
  9076. }
  9077. service.CreateExportErrLog(&err_log)
  9078. continue
  9079. }
  9080. project.Price = price
  9081. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  9082. utils.ErrorLog("unit_id")
  9083. return
  9084. }
  9085. unit := projectM["unit"].(string)
  9086. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  9087. err_log := models.ExportErrLog{
  9088. LogType: 6,
  9089. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9090. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  9091. Status: 1,
  9092. CreateTime: time.Now().Unix(),
  9093. UpdateTime: time.Now().Unix(),
  9094. ExportTime: time.Now().Unix(),
  9095. }
  9096. service.CreateExportErrLog(&err_log)
  9097. continue
  9098. }
  9099. project.Unit = unit
  9100. cost_classify := projectM["cost_classify"].(string)
  9101. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  9102. err_log := models.ExportErrLog{
  9103. LogType: 6,
  9104. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9105. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9106. Status: 1,
  9107. CreateTime: time.Now().Unix(),
  9108. UpdateTime: time.Now().Unix(),
  9109. ExportTime: time.Now().Unix(),
  9110. }
  9111. service.CreateExportErrLog(&err_log)
  9112. continue
  9113. }
  9114. var costClassify = "费用类别"
  9115. var cost_classify_id int64
  9116. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  9117. if len(cost_classify) != 0 {
  9118. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  9119. if errcode == gorm.ErrRecordNotFound {
  9120. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  9121. dataconfig := models.DictDataconfig{
  9122. ParentId: costClassifyConfig.ID,
  9123. Module: "system",
  9124. OrgId: orgId,
  9125. Name: cost_classify,
  9126. FieldName: "",
  9127. Value: costConfig.Value + 1,
  9128. CreatedTime: "",
  9129. UpdatedTime: "",
  9130. CreateUserId: adminUser.AdminUser.Id,
  9131. Status: 1,
  9132. Remark: "",
  9133. DeleteIdSystem: 0,
  9134. Title: "",
  9135. Content: "",
  9136. Order: 0,
  9137. Code: "",
  9138. }
  9139. service.CreatedDicConfig(&dataconfig)
  9140. }
  9141. }
  9142. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  9143. for _, it := range costClassList {
  9144. if cost_classify == it.Name {
  9145. cost_classify_id = int64(it.Value)
  9146. }
  9147. }
  9148. project.CostClassify = cost_classify_id
  9149. executive_section := projectM["executive_section"].(string)
  9150. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  9151. err_log := models.ExportErrLog{
  9152. LogType: 6,
  9153. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9154. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  9155. Status: 1,
  9156. CreateTime: time.Now().Unix(),
  9157. UpdateTime: time.Now().Unix(),
  9158. ExportTime: time.Now().Unix(),
  9159. }
  9160. service.CreateExportErrLog(&err_log)
  9161. continue
  9162. }
  9163. if len(executive_section) != 0 {
  9164. //查找科室是否有内容
  9165. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  9166. if errcodedepart == gorm.ErrRecordNotFound {
  9167. department := models.XtHisDepartment{
  9168. Name: executive_section,
  9169. Status: 1,
  9170. UserOrgId: adminUser.CurrentOrgId,
  9171. CreatedTime: time.Now().Unix(),
  9172. }
  9173. service.CreateDePartment(&department)
  9174. }
  9175. }
  9176. var executive_section_id int64
  9177. departMentList, _ := service.GetAllDepartMent(orgId)
  9178. for _, it := range departMentList {
  9179. if executive_section == it.Name {
  9180. executive_section_id = it.ID
  9181. }
  9182. }
  9183. project.ExecutiveSection = executive_section_id
  9184. medical_coverage := projectM["medical_coverage"].(string)
  9185. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  9186. err_log := models.ExportErrLog{
  9187. LogType: 6,
  9188. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9189. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9190. Status: 1,
  9191. CreateTime: time.Now().Unix(),
  9192. UpdateTime: time.Now().Unix(),
  9193. ExportTime: time.Now().Unix(),
  9194. }
  9195. service.CreateExportErrLog(&err_log)
  9196. continue
  9197. }
  9198. var medicalCoverage = "医保等级"
  9199. var medical_coverage_id int64
  9200. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  9201. if len(medical_coverage) != 0 {
  9202. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  9203. if errormedicalcoverage == gorm.ErrRecordNotFound {
  9204. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  9205. dataconfig := models.DictDataconfig{
  9206. ParentId: medicalCoverageConfig.ID,
  9207. Module: "system",
  9208. OrgId: orgId,
  9209. Name: medical_coverage,
  9210. FieldName: "",
  9211. Value: medicalCoverageConfig.Value + 1,
  9212. CreatedTime: "",
  9213. UpdatedTime: "",
  9214. CreateUserId: adminUser.AdminUser.Id,
  9215. Status: 1,
  9216. Remark: "",
  9217. DeleteIdSystem: 0,
  9218. Title: "",
  9219. Content: "",
  9220. Order: 0,
  9221. Code: "",
  9222. }
  9223. service.CreatedDicConfig(&dataconfig)
  9224. }
  9225. }
  9226. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  9227. for _, it := range medicalCoverageList {
  9228. if medical_coverage == it.Name {
  9229. medical_coverage_id = int64(it.Value)
  9230. }
  9231. }
  9232. project.MedicalCoverage = medical_coverage_id
  9233. pinyin := projectM["pinyin"].(string)
  9234. project.Pinyin = pinyin
  9235. wubi := projectM["wubi"].(string)
  9236. project.Wubi = wubi
  9237. statistical_classification := projectM["statistical_classification"].(string)
  9238. var statisticalClassification = "统计分类"
  9239. var statistical_classification_id int64
  9240. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  9241. if len(statistical_classification) != 0 {
  9242. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  9243. if classificationerrcodes == gorm.ErrRecordNotFound {
  9244. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  9245. dataconfig := models.DictDataconfig{
  9246. ParentId: classiFication.ID,
  9247. Module: "system",
  9248. OrgId: orgId,
  9249. Name: statistical_classification,
  9250. FieldName: "",
  9251. Value: classiFicationConfig.Value + 1,
  9252. CreatedTime: "",
  9253. UpdatedTime: "",
  9254. CreateUserId: adminUser.AdminUser.Id,
  9255. Status: 1,
  9256. Remark: "",
  9257. DeleteIdSystem: 0,
  9258. Title: "",
  9259. Content: "",
  9260. Order: 0,
  9261. Code: "",
  9262. }
  9263. service.CreatedDicConfig(&dataconfig)
  9264. }
  9265. }
  9266. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  9267. for _, it := range classiFicationList {
  9268. if statistical_classification == it.Name {
  9269. statistical_classification_id = int64(it.Value)
  9270. }
  9271. }
  9272. project.StatisticalClassification = statistical_classification_id
  9273. disease_directory := int64(projectM["disease_directory"].(float64))
  9274. project.DiseaseDirectory = disease_directory
  9275. is_record := int64(projectM["is_record"].(float64))
  9276. project.IsRecord = is_record
  9277. medical_code := projectM["medical_code"].(string)
  9278. project.MedicalCode = medical_code
  9279. tube_color := projectM["tube_color"].(string)
  9280. var tubeColor = "试管颜色"
  9281. var tube_color_id int64
  9282. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  9283. if len(tube_color) != 0 {
  9284. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  9285. if errcodetube == gorm.ErrRecordNotFound {
  9286. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  9287. dataconfig := models.DictDataconfig{
  9288. ParentId: tubeColorConfig.ID,
  9289. Module: "system",
  9290. OrgId: orgId,
  9291. Name: tube_color,
  9292. FieldName: "",
  9293. Value: tubeConfig.Value + 1,
  9294. CreatedTime: "",
  9295. UpdatedTime: "",
  9296. CreateUserId: adminUser.AdminUser.Id,
  9297. Status: 1,
  9298. Remark: "",
  9299. DeleteIdSystem: 0,
  9300. Title: "",
  9301. Content: "",
  9302. Order: 0,
  9303. Code: "",
  9304. }
  9305. service.CreatedDicConfig(&dataconfig)
  9306. }
  9307. }
  9308. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  9309. for _, it := range tubeColorList {
  9310. if tube_color == it.Name {
  9311. tube_color_id = int64(it.Value)
  9312. }
  9313. }
  9314. project.TubeColor = tube_color_id
  9315. single_dose := projectM["single_dose"].(string)
  9316. project.SingleDose = single_dose
  9317. execution_frequency := projectM["execution_frequency"].(string)
  9318. project.ExecutionFrequency = execution_frequency
  9319. delivery_way := projectM["delivery_way"].(string)
  9320. project.DeliveryWay = delivery_way
  9321. number_days := projectM["number_days"].(string)
  9322. project.NumberDays = number_days
  9323. total := projectM["total"].(string)
  9324. project.Total = total
  9325. medical_status := int64(projectM["medical_status"].(float64))
  9326. project.MedicalStatus = medical_status
  9327. category := int64(projectM["category"].(float64))
  9328. project.Category = category
  9329. specail_project := int64(projectM["specail_project"].(float64))
  9330. project.SpecailProject = specail_project
  9331. social_security_directory_code := projectM["social_security_directory_code"].(string)
  9332. project.SocialSecurityDirectoryCode = social_security_directory_code
  9333. remark := projectM["remark"].(string)
  9334. project.Remark = remark
  9335. record_date := projectM["record_date"].(string)
  9336. timeLayout := "2006-01-02"
  9337. loc, _ := time.LoadLocation("Local")
  9338. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9339. project.RecordDate = theTime.Unix()
  9340. projectList = append(projectList, &project)
  9341. }
  9342. export_time := time.Now().Unix()
  9343. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  9344. if len(projectList) > 0 {
  9345. for _, item := range projectList {
  9346. project := models.HisProject{
  9347. ProjectName: item.ProjectName,
  9348. Price: item.Price,
  9349. Unit: item.Unit,
  9350. CostClassify: item.CostClassify,
  9351. ExecutiveSection: item.ExecutiveSection,
  9352. MedicalCoverage: item.MedicalCoverage,
  9353. UserOrgId: orgId,
  9354. Status: 1,
  9355. CreatedTime: time.Now().Unix(),
  9356. Pinyin: item.Pinyin,
  9357. Wubi: item.Wubi,
  9358. StatisticalClassification: item.StatisticalClassification,
  9359. DiseaseDirectory: item.DiseaseDirectory,
  9360. IsRecord: item.IsRecord,
  9361. MedicalCode: item.MedicalCode,
  9362. TubeColor: item.TubeColor,
  9363. SingleDose: item.SingleDose,
  9364. DeliveryWay: item.DeliveryWay,
  9365. NumberDays: item.NumberDays,
  9366. Total: item.Total,
  9367. Category: item.Category,
  9368. MedicalStatus: item.MedicalStatus,
  9369. SpecailProject: item.SpecailProject,
  9370. RecordDate: item.RecordDate,
  9371. Remark: item.Remark,
  9372. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  9373. ExecutionFrequency: item.ExecutionFrequency,
  9374. }
  9375. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  9376. if errcodeproject == gorm.ErrRecordNotFound {
  9377. service.CreateProjectInfomation(&project)
  9378. } else if errcodeproject == nil {
  9379. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  9380. }
  9381. log := models.ExportLog{
  9382. LogType: 6,
  9383. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9384. TotalNum: int64(len(total_goods)),
  9385. FailNum: int64(len(errLogs)),
  9386. SuccessNum: int64(len(projectList)),
  9387. CreateTime: time.Now().Unix(),
  9388. UpdateTime: time.Now().Unix(),
  9389. ExportTime: export_time,
  9390. Status: 1,
  9391. }
  9392. service.CreateExportLog(&log)
  9393. c.ServeSuccessJSON(map[string]interface{}{
  9394. "msg": "导入成功",
  9395. "total_num": len(total_goods),
  9396. "success_num": len(projectList),
  9397. "fail_num": int64(len(errLogs)),
  9398. })
  9399. }
  9400. } else {
  9401. log := models.ExportLog{
  9402. LogType: 6,
  9403. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9404. TotalNum: int64(len(total_goods)),
  9405. FailNum: int64(len(errLogs)),
  9406. SuccessNum: int64(len(projectList)),
  9407. CreateTime: time.Now().Unix(),
  9408. UpdateTime: time.Now().Unix(),
  9409. ExportTime: export_time,
  9410. Status: 1,
  9411. }
  9412. service.CreateExportLog(&log)
  9413. c.ServeSuccessJSON(map[string]interface{}{
  9414. "msg": "导入成功",
  9415. "total_num": len(total_goods),
  9416. "success_num": len(projectList),
  9417. "fail_num": int64(len(errLogs)),
  9418. })
  9419. }
  9420. }
  9421. //func (this *HisApiController) EditProjectInformation(){
  9422. //
  9423. // id, _ := this.GetInt64("id")
  9424. // project_team := this.GetString("project_team")
  9425. // price := this.GetString("price")
  9426. // price_float, _ := strconv.ParseFloat(price, 64)
  9427. // pinyin := this.GetString("pinyin")
  9428. // wubi := this.GetString("wubi")
  9429. // tube_color, _ := this.GetInt64("tube_color")
  9430. // team_type, _ := this.GetInt64("team_type")
  9431. // remark := this.GetString("remark")
  9432. // ids := this.GetString("ids")
  9433. // item_id := this.GetString("item_id")
  9434. // projectTeam := models.XtHisProjectTeam{
  9435. // ProjectTeam: project_team,
  9436. // Price: price_float,
  9437. // Pinyin: pinyin,
  9438. // Wubi: wubi,
  9439. // TubeColor: tube_color,
  9440. // TeamType: team_type,
  9441. // Remark: remark,
  9442. // ProjectId: ids,
  9443. // ItemId: item_id,
  9444. // }
  9445. //
  9446. //
  9447. // dataBody := make(map[string]interface{}, 0)
  9448. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9449. // if err != nil {
  9450. // utils.ErrorLog(err.Error())
  9451. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9452. // return
  9453. // }
  9454. //
  9455. // err = service.UpdatedProjectTeam(id, &projectTeam)
  9456. //
  9457. //
  9458. // if err != nil {
  9459. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  9460. // return
  9461. // }
  9462. //
  9463. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  9464. // infos, _ := dataBody["info"].([]interface{})
  9465. // if len(infos) > 0 {
  9466. // var ids []string
  9467. //
  9468. // for _, item := range infos {
  9469. // items := item.(map[string]interface{})
  9470. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  9471. // utils.ErrorLog("id")
  9472. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9473. // return
  9474. // }
  9475. // id := int64(items["id"].(float64))
  9476. //
  9477. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9478. // utils.ErrorLog("type")
  9479. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9480. // return
  9481. // }
  9482. // types := int64(items["type"].(float64))
  9483. //
  9484. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  9485. // utils.ErrorLog("number")
  9486. // }
  9487. //
  9488. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  9489. //
  9490. // projectList := models.XtHisProjectList{
  9491. // Number: number,
  9492. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  9493. // ProjectId: id,
  9494. // Status: 1,
  9495. // CreatedTime: time.Now().Unix(),
  9496. // UpdatedTime: time.Now().Unix(),
  9497. // TeamId: projectTeam.ID,
  9498. // Type: types,
  9499. // }
  9500. // list := projectList
  9501. //
  9502. // service.CreateProjectList(&list)
  9503. //
  9504. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  9505. //
  9506. // }
  9507. // ids_str := strings.Join(ids, ",")
  9508. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  9509. // service.SaveProjectTeam(&projectTeam)
  9510. // this.ServeSuccessJSON(map[string]interface{}{
  9511. // "projectTeam": projectTeam,
  9512. // })
  9513. // }
  9514. // }
  9515. //}
  9516. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  9517. name := c.GetString("name")
  9518. mode_id, _ := c.GetInt64("mode", 0)
  9519. types, _ := c.GetInt64("type", 0)
  9520. patient_id, _ := c.GetInt64("patient_id", 0)
  9521. types = 1
  9522. adminInfo := c.GetAdminUserInfo()
  9523. template := &models.HisPrescriptionTemplate{
  9524. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9525. PatientId: patient_id,
  9526. Type: types,
  9527. Status: 1,
  9528. Ctime: time.Now().Unix(),
  9529. Mtime: time.Now().Unix(),
  9530. Name: name,
  9531. Mode: mode_id,
  9532. }
  9533. dataBody := make(map[string]interface{}, 0)
  9534. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9535. if err != nil {
  9536. utils.ErrorLog(err.Error())
  9537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9538. return
  9539. }
  9540. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  9541. //如果已经存在记录则删除处方
  9542. if template_one.ID > 0 {
  9543. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9544. var ids []int64
  9545. var org_id int64
  9546. for _, item := range ps {
  9547. org_id = c.GetAdminUserInfo().CurrentOrgId
  9548. ids = append(ids, item.ID)
  9549. }
  9550. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  9551. if err2 == nil {
  9552. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9553. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9554. if len(prescriptions) > 0 {
  9555. for _, item := range prescriptions {
  9556. items := item.(map[string]interface{})
  9557. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9558. utils.ErrorLog("type")
  9559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9560. return
  9561. }
  9562. types := int64(items["type"].(float64))
  9563. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9564. utils.ErrorLog("med_type")
  9565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9566. return
  9567. }
  9568. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9569. ctime := time.Now().Unix()
  9570. prescription := &models.HisPrescriptionInfoTemplate{
  9571. PatientId: patient_id,
  9572. UserOrgId: adminInfo.CurrentOrgId,
  9573. Ctime: ctime,
  9574. Mtime: ctime,
  9575. Type: types,
  9576. Modifier: adminInfo.AdminUser.Id,
  9577. Creator: adminInfo.AdminUser.Id,
  9578. Status: 1,
  9579. PTemplateId: template_one.ID,
  9580. MedType: med_type,
  9581. }
  9582. service.CreateHisPrescriptionInfoTemplate(prescription)
  9583. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9584. advices := items["advices"].([]interface{})
  9585. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9586. ctime := time.Now().Unix()
  9587. mtime := ctime
  9588. if len(advices) > 0 {
  9589. for _, advice := range advices {
  9590. var s models.HisPrescriptionAdviceTemplate
  9591. s.PrescriptionId = prescription.ID
  9592. s.AdviceType = 2
  9593. s.StopState = 2
  9594. s.ExecutionState = 2
  9595. s.Status = 1
  9596. s.UserOrgId = adminInfo.CurrentOrgId
  9597. s.CreatedTime = ctime
  9598. s.UpdatedTime = mtime
  9599. s.PatientId = patient_id
  9600. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9601. if errcode > 0 {
  9602. c.ServeFailJSONWithSGJErrorCode(errcode)
  9603. return
  9604. }
  9605. service.CreateHisPrescriptionAdviceTemplate(&s)
  9606. }
  9607. }
  9608. }
  9609. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9610. projects := items["project"].([]interface{})
  9611. if len(projects) > 0 {
  9612. for _, project := range projects {
  9613. var p models.HisPrescriptionProjectTemplate
  9614. p.PrescriptionId = prescription.ID
  9615. p.Ctime = time.Now().Unix()
  9616. p.Mtime = time.Now().Unix()
  9617. p.PatientId = patient_id
  9618. p.UserOrgId = adminInfo.CurrentOrgId
  9619. p.Status = 1
  9620. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9621. if errcode > 0 {
  9622. c.ServeFailJSONWithSGJErrorCode(errcode)
  9623. return
  9624. }
  9625. service.CreateHisPrescriptionProjectTemplate(&p)
  9626. }
  9627. }
  9628. }
  9629. }
  9630. c.ServeSuccessJSON(map[string]interface{}{
  9631. "msg": "创建成功",
  9632. })
  9633. }
  9634. }
  9635. } else {
  9636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9637. return
  9638. }
  9639. } else {
  9640. err3 := service.CreateHisPrescriptionTemplate(template)
  9641. if err3 == nil {
  9642. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9643. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9644. if len(prescriptions) > 0 {
  9645. for _, item := range prescriptions {
  9646. items := item.(map[string]interface{})
  9647. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9648. utils.ErrorLog("type")
  9649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9650. return
  9651. }
  9652. types := int64(items["type"].(float64))
  9653. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9654. utils.ErrorLog("med_type")
  9655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9656. return
  9657. }
  9658. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9659. ctime := time.Now().Unix()
  9660. prescription := &models.HisPrescriptionInfoTemplate{
  9661. PatientId: patient_id,
  9662. UserOrgId: adminInfo.CurrentOrgId,
  9663. Ctime: ctime,
  9664. Mtime: ctime,
  9665. Type: types,
  9666. Modifier: adminInfo.AdminUser.Id,
  9667. Creator: adminInfo.AdminUser.Id,
  9668. Status: 1,
  9669. PTemplateId: template.ID,
  9670. MedType: med_type,
  9671. }
  9672. service.CreateHisPrescriptionInfoTemplate(prescription)
  9673. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9674. advices := items["advices"].([]interface{})
  9675. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9676. ctime := time.Now().Unix()
  9677. mtime := ctime
  9678. if len(advices) > 0 {
  9679. for _, advice := range advices {
  9680. var s models.HisPrescriptionAdviceTemplate
  9681. s.PrescriptionId = prescription.ID
  9682. s.AdviceType = 2
  9683. s.StopState = 2
  9684. s.ExecutionState = 2
  9685. s.Status = 1
  9686. s.UserOrgId = adminInfo.CurrentOrgId
  9687. s.CreatedTime = ctime
  9688. s.UpdatedTime = mtime
  9689. s.PatientId = patient_id
  9690. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9691. if errcode > 0 {
  9692. c.ServeFailJSONWithSGJErrorCode(errcode)
  9693. return
  9694. }
  9695. service.CreateHisPrescriptionAdviceTemplate(&s)
  9696. }
  9697. }
  9698. }
  9699. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9700. projects := items["project"].([]interface{})
  9701. if len(projects) > 0 {
  9702. for _, project := range projects {
  9703. var p models.HisPrescriptionProjectTemplate
  9704. p.PrescriptionId = prescription.ID
  9705. p.Ctime = time.Now().Unix()
  9706. p.Mtime = time.Now().Unix()
  9707. p.PatientId = patient_id
  9708. p.UserOrgId = adminInfo.CurrentOrgId
  9709. p.Status = 1
  9710. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9711. if errcode > 0 {
  9712. c.ServeFailJSONWithSGJErrorCode(errcode)
  9713. return
  9714. }
  9715. service.CreateHisPrescriptionProjectTemplate(&p)
  9716. }
  9717. }
  9718. }
  9719. }
  9720. c.ServeSuccessJSON(map[string]interface{}{
  9721. "msg": "创建成功",
  9722. })
  9723. }
  9724. }
  9725. } else {
  9726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9727. return
  9728. }
  9729. }
  9730. }
  9731. func (c *HisApiController) PreSettle() {
  9732. id, _ := c.GetInt64("id")
  9733. record_time := c.GetString("record_time")
  9734. his_patient_id, _ := c.GetInt64("his_patient_id")
  9735. timeLayout := "2006-01-02"
  9736. loc, _ := time.LoadLocation("Local")
  9737. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9738. diagnosis_id := c.GetString("diagnosis")
  9739. sick_type, _ := c.GetInt64("sick_type")
  9740. reg_type, _ := c.GetInt64("p_type")
  9741. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9742. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9743. if err != nil {
  9744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9745. return
  9746. }
  9747. recordDateTime := theTime.Unix()
  9748. adminUser := c.GetAdminUserInfo()
  9749. var prescriptions []*models.HisPrescription
  9750. var start_time int64
  9751. var end_time int64
  9752. ids_str := c.GetString("ids")
  9753. ids_arr := strings.Split(ids_str, ",")
  9754. fmt.Println(reg_type)
  9755. if settle_accounts_type == 1 { //日结
  9756. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9757. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9758. } else {
  9759. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9760. }
  9761. fmt.Println(prescriptions)
  9762. } else { //月结
  9763. start_time_str := c.GetString("start_time")
  9764. end_time_str := c.GetString("end_time")
  9765. timeLayout := "2006-01-02"
  9766. loc, _ := time.LoadLocation("Local")
  9767. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9768. if err != nil {
  9769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9770. return
  9771. }
  9772. recordStartTime := theStartTime.Unix()
  9773. start_time = recordStartTime
  9774. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9775. if err != nil {
  9776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9777. return
  9778. }
  9779. recordEndTime := theEndTime.Unix()
  9780. end_time = recordEndTime
  9781. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9782. }
  9783. if reg_type == 1111 || reg_type == 1112 {
  9784. reg_type = 11
  9785. }
  9786. timestamp := time.Now().Unix()
  9787. tempTime := time.Unix(timestamp, 0)
  9788. timeFormat := tempTime.Format("20060102150405")
  9789. chrgBchno := rand.Intn(100000) + 10000
  9790. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9791. strconv.FormatInt(his.PatientId, 10)
  9792. var ids []int64
  9793. for _, item := range prescriptions {
  9794. ids = append(ids, item.ID)
  9795. }
  9796. fmt.Println(ids)
  9797. var total float64
  9798. for _, item := range prescriptions {
  9799. fmt.Println(item)
  9800. if item.Type == 1 { //药品
  9801. for _, subItem := range item.HisDoctorAdviceInfo {
  9802. total = total + (subItem.Price * subItem.PrescribingNumber)
  9803. }
  9804. }
  9805. if item.Type == 2 { //项目
  9806. for _, subItem := range item.HisPrescriptionProject {
  9807. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9808. total = total + (subItem.Price * cnt)
  9809. }
  9810. }
  9811. for _, subItem := range item.HisAdditionalCharge {
  9812. total = total + (subItem.Price * float64(subItem.Count))
  9813. }
  9814. }
  9815. allTotal := fmt.Sprintf("%.2f", total)
  9816. totals, _ := strconv.ParseFloat(allTotal, 64)
  9817. order := &models.HisOrder{
  9818. UserOrgId: adminUser.CurrentOrgId,
  9819. HisPatientId: his.ID,
  9820. PatientId: id,
  9821. SettleAccountsDate: recordDateTime,
  9822. Ctime: time.Now().Unix(),
  9823. Mtime: time.Now().Unix(),
  9824. Status: 1,
  9825. OrderStatus: 1,
  9826. MdtrtId: his.Number,
  9827. Number: chrg_bchno,
  9828. MedfeeSumamt: totals,
  9829. SettleEndTime: end_time,
  9830. SettleStartTime: start_time,
  9831. SettleType: settle_accounts_type,
  9832. PsnPartAmt: totals,
  9833. PsnCashPay: totals,
  9834. PType: 2,
  9835. IsPre: 1,
  9836. MedType: strconv.Itoa(int(reg_type)),
  9837. Diagnosis: diagnosis_id,
  9838. }
  9839. err = service.CreateOrder(order)
  9840. if err != nil {
  9841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9842. return
  9843. }
  9844. var customs []*Custom
  9845. for _, item := range prescriptions {
  9846. fmt.Println(item.Type)
  9847. if item.Type == 1 { //药品
  9848. for _, subItem := range item.HisDoctorAdviceInfo {
  9849. cus := &Custom{
  9850. AdviceId: subItem.ID,
  9851. ProjectId: 0,
  9852. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9853. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9854. FeedetlSn: subItem.FeedetlSn,
  9855. Price: fmt.Sprintf("%.2f", subItem.Price),
  9856. MedListCodg: subItem.MedListCodg,
  9857. Type: 1,
  9858. }
  9859. customs = append(customs, cus)
  9860. }
  9861. }
  9862. if item.Type == 2 { //项目
  9863. for _, subItem := range item.HisPrescriptionProject {
  9864. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9865. cus := &Custom{
  9866. AdviceId: 0,
  9867. ProjectId: subItem.ID,
  9868. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9869. Cut: fmt.Sprintf("%.2f", cnt),
  9870. FeedetlSn: subItem.FeedetlSn,
  9871. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9872. MedListCodg: subItem.MedListCodg,
  9873. Type: 2,
  9874. }
  9875. customs = append(customs, cus)
  9876. }
  9877. }
  9878. for _, item := range item.HisAdditionalCharge {
  9879. cus := &Custom{
  9880. ItemId: item.ID,
  9881. AdviceId: 0,
  9882. ProjectId: 0,
  9883. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9884. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9885. FeedetlSn: item.FeedetlSn,
  9886. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9887. MedListCodg: item.XtHisAddtionConfig.Code,
  9888. Type: 3,
  9889. }
  9890. customs = append(customs, cus)
  9891. }
  9892. }
  9893. fmt.Println(customs)
  9894. for _, item := range customs {
  9895. var advice_id int64 = 0
  9896. var project_id int64 = 0
  9897. var item_id int64 = 0
  9898. var types int64 = 0
  9899. if item.Type == 1 {
  9900. advice_id = item.AdviceId
  9901. project_id = 0
  9902. item_id = 0
  9903. } else if item.Type == 2 {
  9904. advice_id = 0
  9905. item_id = 0
  9906. project_id = item.ProjectId
  9907. } else if item.Type == 3 {
  9908. advice_id = 0
  9909. item_id = item.ItemId
  9910. project_id = 0
  9911. }
  9912. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9913. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9914. pric, _ := strconv.ParseFloat(item.Price, 32)
  9915. info := &models.HisOrderInfo{
  9916. OrderNumber: order.Number,
  9917. UploadDate: time.Now().Unix(),
  9918. AdviceId: advice_id,
  9919. DetItemFeeSumamt: detItemFeeSumamt,
  9920. Cnt: cut,
  9921. Pric: pric,
  9922. PatientId: id,
  9923. Status: 1,
  9924. Mtime: time.Now().Unix(),
  9925. Ctime: time.Now().Unix(),
  9926. UserOrgId: adminUser.CurrentOrgId,
  9927. HisPatientId: his.ID,
  9928. OrderId: order.ID,
  9929. ProjectId: project_id,
  9930. Type: types,
  9931. ItemId: item_id,
  9932. }
  9933. service.CreateOrderInfo(info)
  9934. }
  9935. his.SickType = sick_type
  9936. service.UpdataHisPateint(&his)
  9937. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9938. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9939. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9940. if err == nil {
  9941. c.ServeSuccessJSON(map[string]interface{}{
  9942. "msg": "结算成功",
  9943. })
  9944. }
  9945. }
  9946. type CustomOrderInfo struct {
  9947. Name string
  9948. Spec string
  9949. Unit string
  9950. Count float64
  9951. Price float64
  9952. Total float64
  9953. }
  9954. func (c *HisApiController) GetPrivateExpensesInfo() {
  9955. order_id, _ := c.GetInt64("id", 0)
  9956. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9957. order, _ := service.GetHisOrderByID(order_id)
  9958. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9959. if order.ID == 0 {
  9960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9961. return
  9962. }
  9963. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9964. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9965. org_id := c.GetAdminUserInfo().CurrentOrgId
  9966. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9967. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9968. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9969. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9970. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9971. //var orderInfos_four []*models.HisOrderInfoTwo
  9972. //for _, item := range orderInfos_three {
  9973. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9974. // item.HisPrescriptionProject.IsCheckTeam = 1
  9975. // orderInfos_four = append(orderInfos_four, item)
  9976. //
  9977. // }
  9978. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9979. // item.HisPrescriptionProject.IsCheckTeam = 2
  9980. // orderInfos_two = append(orderInfos_two, item)
  9981. // }
  9982. //}
  9983. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9984. //var cus_slice []CustomOrderInfo
  9985. //for _, item := range new_order_info {
  9986. // var cus CustomOrderInfo
  9987. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9988. // cus.Unit = ""
  9989. // cus.Spec = ""
  9990. // var total float64
  9991. // for _, subItem := range orderInfos_four {
  9992. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9993. // total = total + subItem.DetItemFeeSumamt
  9994. // fmt.Println(subItem.DetItemFeeSumamt)
  9995. // }
  9996. // }
  9997. // cus.Count = 1
  9998. // cus.Total = total
  9999. // cus_slice = append(cus_slice, cus)
  10000. //}
  10001. orderInfos = append(orderInfos, orderInfos_two...)
  10002. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10003. //orderInfos = append(orderInfos, orderInfos_three...)
  10004. //}/**/
  10005. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10006. c.ServeSuccessJSON(map[string]interface{}{
  10007. "order": order,
  10008. "order_info": orderInfos,
  10009. "patient": patient,
  10010. "admin_info": adminInfo,
  10011. "his": his,
  10012. "current_admin": role,
  10013. "org_config": miConfig,
  10014. //"new_order_info": cus_slice,
  10015. })
  10016. }
  10017. func (this *HisApiController) ChangeMedType() {
  10018. med_type := this.GetString("med_type")
  10019. old_med_type := this.GetString("old_med_type")
  10020. ids := this.GetString("ids")
  10021. settle_type, _ := this.GetInt64("settle_type")
  10022. start_time := this.GetString("start_time")
  10023. end_time := this.GetString("end_time")
  10024. ids_arr := strings.Split(ids, ",")
  10025. if settle_type == 1 { //日结
  10026. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10027. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10028. prescription.MedType = med_type
  10029. err := service.SaveHisPrescription(&prescription)
  10030. if err == nil {
  10031. this.ServeSuccessJSON(map[string]interface{}{
  10032. "msg": "修改成功",
  10033. })
  10034. } else {
  10035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10036. return
  10037. }
  10038. } else if settle_type == 2 {
  10039. timeLayout := "2006-01-02"
  10040. loc, _ := time.LoadLocation("Local")
  10041. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10042. if err != nil {
  10043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10044. return
  10045. }
  10046. recordStartTime := theStartTime.Unix()
  10047. start_time_timestamp := recordStartTime
  10048. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  10049. if err != nil {
  10050. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10051. return
  10052. }
  10053. recordEndTime := theEndTime.Unix()
  10054. end_time_timestamp := recordEndTime
  10055. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  10056. if updateErr == nil {
  10057. this.ServeSuccessJSON(map[string]interface{}{
  10058. "msg": "修改成功",
  10059. })
  10060. } else {
  10061. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10062. return
  10063. }
  10064. }
  10065. }
  10066. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  10067. patient_id, _ := c.GetInt64("patient_id")
  10068. his_patient_id, _ := c.GetInt64("his_patient_id")
  10069. record_date := c.GetString("record_date")
  10070. start_time := c.GetString("start_time")
  10071. end_time := c.GetString("end_time")
  10072. order_status, _ := c.GetInt64("type", 0)
  10073. p_type, _ := c.GetInt64("p_type", 0)
  10074. order_id, _ := c.GetInt64("order_id", 0)
  10075. timeLayout := "2006-01-02"
  10076. loc, _ := time.LoadLocation("Local")
  10077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10078. if err != nil {
  10079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10080. return
  10081. }
  10082. recordDateTime := theTime.Unix()
  10083. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10084. if err != nil {
  10085. }
  10086. startRecordDateTime := startTime.Unix()
  10087. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10088. if err != nil {
  10089. }
  10090. endRecordDateTime := endTime.Unix()
  10091. admin := c.GetAdminUserInfo()
  10092. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10093. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10094. order, _ := service.GetHisOrderByID(order_id)
  10095. var monthPrescriptions []*models.HisPrescription
  10096. if order_status == 1 || order_status == 0 {
  10097. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10098. } else if order_status == 2 {
  10099. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10100. }
  10101. var settle_total float64
  10102. for _, item := range monthPrescriptions {
  10103. if len(item.HisPrescriptionProject) > 0 {
  10104. for _, subItem := range item.HisPrescriptionProject {
  10105. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10106. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10107. settle_total = settle_total + total
  10108. }
  10109. }
  10110. if len(item.HisDoctorAdviceInfo) > 0 {
  10111. for _, subItem := range item.HisDoctorAdviceInfo {
  10112. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10113. settle_total = settle_total + total
  10114. }
  10115. }
  10116. }
  10117. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10118. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10119. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10120. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10121. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10122. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10123. //获取所有科室信息
  10124. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10125. var dia string
  10126. for _, item := range month_p_info {
  10127. if len(dia) == 0 {
  10128. dia = item.Diagnosis
  10129. } else {
  10130. dia = dia + "," + item.Diagnosis
  10131. }
  10132. }
  10133. dia_arr := removeDuplicates(strings.Split(dia, ","))
  10134. dia_arr = removeEmptyStrings(dia_arr)
  10135. c.ServeSuccessJSON(map[string]interface{}{
  10136. "his_info": his_patient_info,
  10137. "xt_info": xt_patient_info,
  10138. "case_history": case_history,
  10139. "info": patientPrescriptionInfo,
  10140. "last_info": lastPatientPrescriptionInfo,
  10141. "month_prescriptions": monthPrescriptions,
  10142. "order": order,
  10143. "doctors": doctors,
  10144. "department": department,
  10145. "settle_total": settle_total,
  10146. "dia_arr": dia_arr,
  10147. })
  10148. return
  10149. }
  10150. func removeEmptyStrings(input []string) []string {
  10151. var output []string
  10152. for _, s := range input {
  10153. if s != "" {
  10154. output = append(output, s)
  10155. }
  10156. }
  10157. return output
  10158. }
  10159. func removeDuplicates(input []string) []string {
  10160. seen := make(map[string]bool)
  10161. output := []string{}
  10162. for _, s := range input {
  10163. if _, exists := seen[s]; !exists {
  10164. seen[s] = true
  10165. output = append(output, s)
  10166. }
  10167. }
  10168. return output
  10169. }
  10170. func (c *HisApiController) GetHisMonthPatientInfo() {
  10171. patient_id, _ := c.GetInt64("patient_id")
  10172. his_patient_id, _ := c.GetInt64("his_patient_id")
  10173. record_date := c.GetString("record_date")
  10174. number := c.GetString("number")
  10175. start_time := c.GetString("start_time")
  10176. end_time := c.GetString("end_time")
  10177. p_type, _ := c.GetInt64("p_type")
  10178. timeLayout := "2006-01-02"
  10179. loc, _ := time.LoadLocation("Local")
  10180. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10181. if err != nil {
  10182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10183. return
  10184. }
  10185. recordDateTime := theTime.Unix()
  10186. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10187. if err != nil {
  10188. }
  10189. startRecordDateTime := startTime.Unix()
  10190. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10191. if err != nil {
  10192. }
  10193. endRecordDateTime := endTime.Unix()
  10194. admin := c.GetAdminUserInfo()
  10195. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  10196. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10197. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  10198. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10199. var settle_total float64
  10200. for _, item := range monthPrescriptions {
  10201. if len(item.HisPrescriptionProject) > 0 {
  10202. for _, subItem := range item.HisPrescriptionProject {
  10203. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10204. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10205. settle_total = settle_total + total
  10206. }
  10207. }
  10208. if len(item.HisDoctorAdviceInfo) > 0 {
  10209. for _, subItem := range item.HisDoctorAdviceInfo {
  10210. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10211. settle_total = settle_total + total
  10212. }
  10213. }
  10214. }
  10215. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10216. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10217. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10218. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10219. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  10220. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10221. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  10222. //获取所有科室信息
  10223. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10224. c.ServeSuccessJSON(map[string]interface{}{
  10225. "his_info": his_patient_info,
  10226. "xt_info": xt_patient_info,
  10227. "case_history": case_history,
  10228. "info": patientPrescriptionInfo,
  10229. "month_prescriptions": monthPrescriptions,
  10230. "order": order,
  10231. "doctors": doctors,
  10232. "department": department,
  10233. "count": count,
  10234. "drugStockConfig": drugStockConfig,
  10235. "last_info": lastPatientPrescriptionInfo,
  10236. "settle_total": settle_total,
  10237. })
  10238. return
  10239. }
  10240. func (c *HisApiController) GetAllOrder() {
  10241. org_id := c.GetAdminUserInfo().CurrentOrgId
  10242. orders, _ := service.GetNewHisOrderList(org_id)
  10243. c.ServeSuccessJSON(map[string]interface{}{
  10244. "order": orders,
  10245. })
  10246. return
  10247. }
  10248. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  10249. newArr = make([]*models.HisOrderInfoTwo, 0)
  10250. for i := 0; i < len(arr); i++ {
  10251. repeat := false
  10252. for j := i + 1; j < len(arr); j++ {
  10253. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  10254. repeat = true
  10255. break
  10256. }
  10257. }
  10258. if !repeat {
  10259. newArr = append(newArr, arr[i])
  10260. }
  10261. }
  10262. return
  10263. }
  10264. // 修改处方退库操作 参数传修改之前的处方数据
  10265. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  10266. if advice.ExecutionState == 1 {
  10267. //查询该病人该药品是否有库存记录
  10268. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  10269. if errcode == gorm.ErrRecordNotFound {
  10270. } else {
  10271. //退库
  10272. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  10273. if advice.PrescribingNumberUnit == drug.MinUnit {
  10274. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  10275. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  10276. //退库
  10277. warehouseInfo := models.DrugWarehouseInfo{
  10278. StockMinNumber: prescribingNumber,
  10279. }
  10280. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  10281. operation_time := time.Now().Unix()
  10282. creater := advice.AdviceDoctor
  10283. ctime := time.Now().Unix()
  10284. timeStr := time.Now().Format("2006-01-02")
  10285. timeArr := strings.Split(timeStr, "-")
  10286. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  10287. total = total + 1
  10288. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  10289. cancelStock := models.DrugCancelStock{
  10290. OrderNumber: orderNumber,
  10291. OperaTime: operation_time,
  10292. OrgId: advice.UserOrgId,
  10293. Creater: creater,
  10294. Ctime: ctime,
  10295. Status: 1,
  10296. ReturnTime: advice.AdviceDate,
  10297. Dealer: info.Dealer,
  10298. Manufacturer: info.Manufacturer,
  10299. Type: 1,
  10300. }
  10301. service.AddSigleDrugCancelStock(&cancelStock)
  10302. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  10303. dealer, _ := service.GetDealerById(info.Dealer)
  10304. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  10305. cancelStockInfo := models.DrugCancelStockInfo{
  10306. OrderNumber: cancelInfo.OrderNumber,
  10307. CancelStockId: cancelInfo.ID,
  10308. DrugId: info.DrugId,
  10309. Count: info.Count,
  10310. Status: 1,
  10311. Ctime: ctime,
  10312. OrgId: advice.UserOrgId,
  10313. Type: 1,
  10314. Manufacturer: manufactureName.ManufacturerName,
  10315. Dealer: dealer.DealerName,
  10316. Total: 0,
  10317. RetailPrice: info.RetailPrice,
  10318. RetailTotalPrice: info.RetailTotalPrice,
  10319. Price: info.Price,
  10320. RegisterAccount: "",
  10321. Remark: info.Remark,
  10322. BatchNumber: info.BatchNumber,
  10323. MaxUnit: info.CountUnit,
  10324. ProductDate: info.ProductDate,
  10325. ExpiryDate: info.ExpiryDate,
  10326. BatchNumberId: info.WarehouseInfoId,
  10327. }
  10328. flow := models.DrugFlow{
  10329. WarehousingId: 0,
  10330. DrugId: info.DrugId,
  10331. Number: "",
  10332. BatchNumber: info.BatchNumber,
  10333. Count: info.Count,
  10334. UserOrgId: advice.UserOrgId,
  10335. PatientId: 0,
  10336. SystemTime: ctime,
  10337. ConsumableType: 4,
  10338. IsSys: 0,
  10339. WarehousingOrder: "",
  10340. WarehouseOutId: 0,
  10341. WarehouseOutOrderNumber: "",
  10342. IsEdit: 0,
  10343. CancelStockId: cancelStock.ID,
  10344. CancelOrderNumber: cancelStock.OrderNumber,
  10345. Manufacturer: info.Manufacturer,
  10346. Dealer: info.Dealer,
  10347. Creator: advice.UserOrgId,
  10348. UpdateCreator: 0,
  10349. Status: 1,
  10350. Ctime: time.Now().Unix(),
  10351. Mtime: 0,
  10352. Price: info.Price,
  10353. WarehousingDetailId: 0,
  10354. WarehouseOutDetailId: 0,
  10355. CancelOutDetailId: 0,
  10356. ExpireDate: info.ExpiryDate,
  10357. ProductDate: info.ProductDate,
  10358. MaxUnit: info.CountUnit,
  10359. MinUnit: "",
  10360. }
  10361. service.CreatedCancelStock(cancelStockInfo)
  10362. service.CreateDrugFlowOne(flow)
  10363. } else {
  10364. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  10365. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  10366. if advice.PrescribingNumberUnit == drug.MaxUnit {
  10367. warehouseInfo := models.DrugWarehouseInfo{
  10368. StockMinNumber: prescribingNumber,
  10369. }
  10370. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  10371. }
  10372. operation_time := time.Now().Unix()
  10373. creater := advice.AdviceDoctor
  10374. ctime := time.Now().Unix()
  10375. timeStr := time.Now().Format("2006-01-02")
  10376. timeArr := strings.Split(timeStr, "-")
  10377. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  10378. total = total + 1
  10379. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  10380. cancelStock := models.DrugCancelStock{
  10381. OrderNumber: orderNumber,
  10382. OperaTime: operation_time,
  10383. OrgId: advice.UserOrgId,
  10384. Creater: creater,
  10385. Ctime: ctime,
  10386. Status: 1,
  10387. ReturnTime: advice.AdviceDate,
  10388. Dealer: info.Dealer,
  10389. Manufacturer: info.Manufacturer,
  10390. Type: 1,
  10391. }
  10392. service.AddSigleDrugCancelStock(&cancelStock)
  10393. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  10394. dealer, _ := service.GetDealerById(info.Dealer)
  10395. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  10396. cancelStockInfo := models.DrugCancelStockInfo{
  10397. OrderNumber: cancelInfo.OrderNumber,
  10398. CancelStockId: cancelInfo.ID,
  10399. DrugId: info.DrugId,
  10400. Count: info.Count,
  10401. Status: 1,
  10402. Ctime: ctime,
  10403. OrgId: advice.UserOrgId,
  10404. Type: 1,
  10405. Manufacturer: manufactureName.ManufacturerName,
  10406. Dealer: dealer.DealerName,
  10407. Total: 0,
  10408. RetailPrice: info.RetailPrice,
  10409. RetailTotalPrice: info.RetailTotalPrice,
  10410. Price: info.Price,
  10411. RegisterAccount: "",
  10412. Remark: info.Remark,
  10413. BatchNumber: info.BatchNumber,
  10414. MaxUnit: info.CountUnit,
  10415. ProductDate: info.ProductDate,
  10416. ExpiryDate: info.ExpiryDate,
  10417. BatchNumberId: info.WarehouseInfoId,
  10418. }
  10419. flow := models.DrugFlow{
  10420. WarehousingId: 0,
  10421. DrugId: info.DrugId,
  10422. Number: "",
  10423. BatchNumber: info.BatchNumber,
  10424. Count: info.Count,
  10425. UserOrgId: advice.UserOrgId,
  10426. PatientId: 0,
  10427. SystemTime: ctime,
  10428. ConsumableType: 4,
  10429. IsSys: 0,
  10430. WarehousingOrder: "",
  10431. WarehouseOutId: 0,
  10432. WarehouseOutOrderNumber: "",
  10433. IsEdit: 0,
  10434. CancelStockId: cancelStock.ID,
  10435. CancelOrderNumber: cancelStock.OrderNumber,
  10436. Manufacturer: info.Manufacturer,
  10437. Dealer: info.Dealer,
  10438. Creator: advice.AdviceDoctor,
  10439. UpdateCreator: 0,
  10440. Status: 1,
  10441. Ctime: time.Now().Unix(),
  10442. Mtime: 0,
  10443. Price: info.Price,
  10444. WarehousingDetailId: 0,
  10445. WarehouseOutDetailId: 0,
  10446. CancelOutDetailId: 0,
  10447. ExpireDate: info.ExpiryDate,
  10448. ProductDate: info.ProductDate,
  10449. MaxUnit: info.CountUnit,
  10450. MinUnit: "",
  10451. }
  10452. service.CreatedCancelStock(cancelStockInfo)
  10453. service.CreateDrugFlowOne(flow)
  10454. }
  10455. }
  10456. }
  10457. return err
  10458. }
  10459. func (this *HisApiController) DeleteNCDS() {
  10460. id, _ := this.GetInt64("id", 0)
  10461. if id > 0 {
  10462. service.DeletePsnNCDSRecordById(id)
  10463. this.ServeSuccessJSON(map[string]interface{}{
  10464. "msg": "删除成功",
  10465. })
  10466. } else {
  10467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  10468. return
  10469. }
  10470. }
  10471. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  10472. id, _ := c.GetInt64("id")
  10473. advice, _ := service.GetHisDoctorAdviceInfo(id)
  10474. c.ServeSuccessJSON(map[string]interface{}{
  10475. "advice": advice,
  10476. })
  10477. return
  10478. }
  10479. func (c *HisApiController) GetHisMonthChargePatientList() {
  10480. record_date := c.GetString("record_date")
  10481. start_time := c.GetString("start_time")
  10482. end_time := c.GetString("end_time")
  10483. timeLayout := "2006-01-02"
  10484. loc, _ := time.LoadLocation("Local")
  10485. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10486. if err != nil {
  10487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10488. return
  10489. }
  10490. if err != nil {
  10491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10492. return
  10493. }
  10494. recordDateTime := theTime.Unix()
  10495. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10496. if err != nil {
  10497. }
  10498. startRecordDateTime := startTime.Unix()
  10499. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10500. if err != nil {
  10501. }
  10502. endRecordDateTime := endTime.Unix()
  10503. adminInfo := c.GetAdminUserInfo()
  10504. var tempMonthChargePatients []*service.MonthChargePatients
  10505. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  10506. for _, item := range tempPatients {
  10507. //过滤没有处方的
  10508. if len(item.HisPrescription) == 0 {
  10509. tempMonthChargePatients = append(tempMonthChargePatients, item)
  10510. }
  10511. }
  10512. c.ServeSuccessJSON(map[string]interface{}{
  10513. "list": tempMonthChargePatients,
  10514. })
  10515. }
  10516. // PrescriptionDifference 医嘱数量差值结构体
  10517. type PrescriptionDrugDifference struct {
  10518. DrugID int64 //基础库药品id
  10519. ID int64 //医嘱id
  10520. Difference float64 //差值
  10521. Unit string //单位
  10522. }
  10523. type PrescriptionGoodDifference struct {
  10524. GoodID int64 //基础库项目耗材id
  10525. ID int64 //医嘱id
  10526. Difference int64 //差值
  10527. Unit string //单位
  10528. Type int64 //类型
  10529. }
  10530. type EditCustomData struct {
  10531. adviceList []*models.HisDoctorAdviceInfo
  10532. projectList []*models.HisPrescriptionProject
  10533. }
  10534. type SrcCustomData struct {
  10535. adviceList []*models.HisDoctorAdviceInfo
  10536. projectList []*models.HisPrescriptionProject
  10537. }
  10538. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  10539. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  10540. differences := make([]*PrescriptionDrugDifference, 0)
  10541. // 创建一个 map 来存储第一个切片中的药品信息
  10542. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  10543. for _, advice := range firstPrescription {
  10544. firstMap[advice.DrugId] = advice
  10545. }
  10546. // 遍历第二个切片中的药品信息,并比较数量差值
  10547. for _, advice := range secondPrescription {
  10548. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  10549. diff := &PrescriptionDrugDifference{
  10550. DrugID: advice.DrugId,
  10551. ID: firstAdvice.ID,
  10552. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  10553. Unit: firstAdvice.PrescribingNumberUnit,
  10554. }
  10555. differences = append(differences, diff)
  10556. }
  10557. }
  10558. return differences
  10559. }
  10560. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  10561. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  10562. differences := make([]*PrescriptionGoodDifference, 0)
  10563. // 创建一个 map 来存储第一个切片中的耗材信息
  10564. firstMap := make(map[int64]*models.HisPrescriptionProject)
  10565. for _, good := range firstPrescription {
  10566. firstMap[good.ProjectId] = good
  10567. }
  10568. // 遍历第二个切片中的耗材信息,并比较数量差值
  10569. for _, good := range secondPrescription {
  10570. if firstGood, ok := firstMap[good.ProjectId]; ok {
  10571. count, _ := strconv.ParseInt(good.Count, 10, 64)
  10572. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  10573. diff := &PrescriptionGoodDifference{
  10574. GoodID: good.ProjectId,
  10575. ID: firstGood.ID,
  10576. Difference: count - firstCount,
  10577. Unit: firstGood.Unit,
  10578. Type: firstGood.Type,
  10579. }
  10580. differences = append(differences, diff)
  10581. }
  10582. }
  10583. return differences
  10584. }
  10585. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  10586. var adviceList []*models.HisDoctorAdviceInfo
  10587. var projectList []*models.HisPrescriptionProject
  10588. var advice_ids []int64
  10589. var project_ids []int64
  10590. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10591. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10592. //var tempPrescription *models.HisPrescriptionProjectscription
  10593. if len(prescriptions) > 0 {
  10594. for _, item := range prescriptions {
  10595. items := item.(map[string]interface{})
  10596. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10597. advices := items["advices"].([]interface{})
  10598. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10599. groupNo := int64(0)
  10600. ctime := time.Now().Unix()
  10601. mtime := ctime
  10602. if len(advices) > 0 {
  10603. for _, advice := range advices {
  10604. var s models.HisDoctorAdviceInfo
  10605. s.AdviceType = 2
  10606. s.StopState = 2
  10607. s.ExecutionState = 2
  10608. s.Status = 1
  10609. s.Groupno = groupNo
  10610. s.CreatedTime = ctime
  10611. s.UpdatedTime = mtime
  10612. s.IsSettle = 2
  10613. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  10614. //存储切片中
  10615. if s.ID > 0 {
  10616. advice_ids = append(advice_ids, s.ID)
  10617. adviceList = append(adviceList, &s)
  10618. }
  10619. }
  10620. }
  10621. }
  10622. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10623. projects := items["project"].([]interface{})
  10624. if len(projects) > 0 {
  10625. for _, project := range projects {
  10626. var p models.HisPrescriptionProject
  10627. p.Ctime = time.Now().Unix()
  10628. p.Mtime = time.Now().Unix()
  10629. p.Status = 1
  10630. SetProjectWithJSON(&p, project.(map[string]interface{}))
  10631. if p.ID > 0 {
  10632. project_ids = append(project_ids, p.ID)
  10633. projectList = append(projectList, &p)
  10634. }
  10635. }
  10636. }
  10637. }
  10638. }
  10639. }
  10640. }
  10641. editCustomData.projectList = projectList
  10642. editCustomData.adviceList = adviceList
  10643. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  10644. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  10645. srcCustomData.adviceList = list
  10646. srcCustomData.projectList = list2
  10647. return
  10648. }