his_api_controller.go 369KB

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