his_api_controller.go 513KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. //if number >= 1000 {
  188. // zero = "0000" + strconv.FormatInt(number, 10)
  189. //} else if number >= 10000 {
  190. // zero = "000" + strconv.FormatInt(number, 10)
  191. //} else if number >= 100000 {
  192. // zero = "00" + strconv.FormatInt(number, 10)
  193. //} else if number >= 1000000 {
  194. // zero = "0" + strconv.FormatInt(number, 10)
  195. //} else {
  196. zero = "0" + strconv.FormatInt(number, 10)
  197. //}
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. if order.IsMedicineInsurance != 1 {
  1022. order.PsnCashPay = order.MedfeeSumamt
  1023. }
  1024. for _, item := range orderInfos {
  1025. if item.MedChrgitmType == "01" { //床位费
  1026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //诊察费
  1031. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //zhenChaCostSelfTotal = zhenChaCostTotal
  1033. }
  1034. if item.MedChrgitmType == "03" { //检查费
  1035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //检查费
  1040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1042. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1043. }
  1044. if item.MedChrgitmType == "04" { //化验费
  1045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1048. }
  1049. if item.MedChrgitmType == "05" { //治疗费
  1050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1053. }
  1054. if item.MedChrgitmType == "06" { //手术费
  1055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. }
  1059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1063. }
  1064. if item.MedChrgitmType == "09" { //西药费
  1065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1068. }
  1069. if item.MedChrgitmType == "11" { //中成费
  1070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1073. }
  1074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1078. }
  1079. }
  1080. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1081. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1083. var dia_config []*models.HisXtDiagnoseConfig
  1084. var diagnosis_ids []string
  1085. if his.ID > 0 {
  1086. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1087. } else {
  1088. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1089. }
  1090. for _, item := range diagnosis_ids {
  1091. id, _ := strconv.ParseInt(item, 10, 64)
  1092. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1093. dia_config = append(dia_config, diagnosisConfig)
  1094. }
  1095. var rf []CustomFundPay
  1096. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1097. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "patient": patient,
  1100. "order_infos": orderInfos,
  1101. "diagnosis": name,
  1102. "bedCostTotal": bedCostTotal,
  1103. "bedCostSelfTotal": bedCostTotal,
  1104. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1105. "operationCostTotal": operationCostTotal,
  1106. "operationCostSelfTotal": operationCostTotal,
  1107. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1108. "otherCostTotal": otherCostTotal,
  1109. "otherCostSelfTotal": otherCostTotal,
  1110. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1111. "materialCostTotal": materialCostTotal,
  1112. "materialCostSelfTotal": materialCostTotal,
  1113. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1114. "westernMedicineCostTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1116. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1117. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1119. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1120. "checkCostTotal": checkCostTotal,
  1121. "checkCostSelfTotal": checkCostTotal,
  1122. "zhenChaCostTotal": zhenChaCostTotal,
  1123. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1124. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1125. "laboratoryCostTotal": laboratoryCostTotal,
  1126. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1127. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1128. "treatCostTotal": treatCostTotal,
  1129. "treatCostSelfTotal": treatCostTotal,
  1130. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1131. "charge_admin": charge_admin,
  1132. "printor_admin": printor_admin,
  1133. "org_name": org.OrgName,
  1134. "org_code": miConfig.Code,
  1135. "name": patient.Name,
  1136. "number": order.MdtrtId,
  1137. "date": order.SettleAccountsDate,
  1138. "info": order,
  1139. "new_order": order,
  1140. "his_hospital": his_hospital,
  1141. "his": his,
  1142. "funds": rf,
  1143. "dia_config": dia_config,
  1144. })
  1145. }
  1146. func (c *HisApiController) RefudDetail() {
  1147. order_id, _ := c.GetInt64("order_id")
  1148. order, _ := service.GetHisOrderByID(order_id)
  1149. adminUser := c.GetAdminUserInfo()
  1150. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "撤销成功",
  1153. })
  1154. }
  1155. func (c *HisApiController) Sscard() {
  1156. //r := CardInit()
  1157. //if r == 0 {
  1158. // GetBaseInfo()
  1159. //}
  1160. //c.ServeSuccessJSON(map[string]interface{}{
  1161. // "list": "11",
  1162. //})
  1163. }
  1164. func GetBaseInfo() error {
  1165. //handle := syscall.MustLoadDLL("SSCard.dll")
  1166. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1167. //
  1168. //str := make([]byte, 256)
  1169. //str1 := make([]byte, 256)
  1170. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1171. //if ferr != nil {
  1172. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1173. // return ferr
  1174. //}
  1175. //
  1176. //fmt.Println(string(str))
  1177. //
  1178. //fmt.Println(r)
  1179. return nil
  1180. }
  1181. func CardInit() int {
  1182. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1183. //add := DllTestDef.MustFindProc("Init")
  1184. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1185. //if err != nil {
  1186. // fmt.Println("SSCard的运算结果为:", ret)
  1187. //}
  1188. //result := int(ret)
  1189. return 0
  1190. }
  1191. func IntPtr(n int) uintptr {
  1192. return uintptr(n)
  1193. }
  1194. func StrPtr(s string) uintptr {
  1195. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1196. }
  1197. func (c *HisApiController) GetHisPatientList() {
  1198. //types, _ := c.GetInt64("type", 0)
  1199. record_date := c.GetString("record_date")
  1200. sch_type, _ := c.GetInt64("sch_type")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1204. if err != nil {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. recordDateTime := theTime.Unix()
  1209. adminInfo := c.GetAdminUserInfo()
  1210. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1211. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1212. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1213. //获取当前用户的信息
  1214. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1215. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1216. //获取所有科室信息
  1217. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1218. c.ServeSuccessJSON(map[string]interface{}{
  1219. "list": patients,
  1220. "list_two": patients_two,
  1221. "info": adminUserInfo,
  1222. "doctors": doctors,
  1223. "department": department,
  1224. })
  1225. }
  1226. type CustomTemplate struct {
  1227. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1228. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1229. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1230. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1231. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1232. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1233. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1234. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1235. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1236. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1237. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1238. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1239. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1240. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1241. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1242. }
  1243. func (c *HisApiController) GetHisPatientInfo() {
  1244. patient_id, _ := c.GetInt64("patient_id")
  1245. his_patient_id, _ := c.GetInt64("his_patient_id")
  1246. record_date := c.GetString("record_date")
  1247. number := c.GetString("number")
  1248. //start_time := c.GetString("start_time")
  1249. //end_time := c.GetString("end_time")
  1250. p_type, _ := c.GetInt64("p_type")
  1251. timeLayout := "2006-01-02"
  1252. loc, _ := time.LoadLocation("Local")
  1253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1254. if err != nil {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. recordDateTime := theTime.Unix()
  1259. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1260. //if err != nil {
  1261. //
  1262. //}
  1263. //startRecordDateTime := startTime.Unix()
  1264. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //endRecordDateTime := endTime.Unix()
  1269. admin := c.GetAdminUserInfo()
  1270. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1271. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1272. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1273. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1274. var prescriptions []*models.HisPrescription
  1275. var last_prescriptions []*models.HisPrescription
  1276. var sch_prescriptions []CustomTemplate
  1277. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. if p_type == 1 { //住院
  1279. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1280. for _, item := range prescriptions {
  1281. for _, subItem := range item.HisDoctorAdviceInfo {
  1282. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1283. if info.RetailPrice > 0 {
  1284. subItem.Drug.MinPrice = info.RetailPrice
  1285. }
  1286. }
  1287. }
  1288. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1289. } else { //门诊
  1290. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1291. for _, item := range prescriptions {
  1292. for _, subItem := range item.HisDoctorAdviceInfo {
  1293. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1294. if info.RetailPrice > 0 {
  1295. subItem.Drug.MinPrice = info.RetailPrice
  1296. }
  1297. }
  1298. }
  1299. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1300. }
  1301. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1302. if sch.ID > 0 {
  1303. var week string
  1304. t := time.Now()
  1305. switch t.Weekday().String() {
  1306. case "Monday":
  1307. week = "周一"
  1308. break
  1309. case "Tuesday":
  1310. week = "周二"
  1311. break
  1312. case "Wednesday":
  1313. week = "周三"
  1314. break
  1315. case "Thursday":
  1316. week = "周四"
  1317. break
  1318. case "Friday":
  1319. week = "周五"
  1320. break
  1321. case "Saturday":
  1322. week = "周六"
  1323. break
  1324. case "Sunday":
  1325. week = "周日"
  1326. break
  1327. }
  1328. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1329. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1330. //根据推送频率组装新的数组
  1331. for _, item := range temp_sch_prescriptions {
  1332. var cus CustomTemplate
  1333. cus.ID = item.ID
  1334. cus.UserOrgId = item.UserOrgId
  1335. cus.PatientId = item.PatientId
  1336. cus.MedType = item.MedType
  1337. cus.RecordDate = item.RecordDate
  1338. cus.Type = item.Type
  1339. cus.PType = item.PType
  1340. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1341. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1342. if subItem.FrequencyType == 1 { //每次必推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1346. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1347. }
  1348. if subItem.FrequencyType == 2 { //按照天数频率
  1349. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1350. now := p.Unix()
  1351. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1352. dayStr2 := "-" + dayStr
  1353. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1354. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1355. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1356. if len(advices) == 0 {
  1357. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1358. }
  1359. }
  1360. }
  1361. }
  1362. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1363. if subItem.Type == 2 {
  1364. if subItem.XtHisProject.MedicalStatus != 1 {
  1365. if subItem.FrequencyType == 1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1369. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1370. }
  1371. if subItem.FrequencyType == 2 {
  1372. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1373. now := p.Unix()
  1374. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1375. dayStr2 := "-" + dayStr
  1376. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1377. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1378. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1379. if len(projects) == 0 {
  1380. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1381. }
  1382. }
  1383. }
  1384. } else if subItem.Type == 3 {
  1385. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1386. if subItem.FrequencyType == 1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1390. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1391. }
  1392. if subItem.FrequencyType == 2 {
  1393. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1394. now := p.Unix()
  1395. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1396. dayStr2 := "-" + dayStr
  1397. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1398. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1399. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1400. if len(projects) == 0 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. sch_prescriptions = append(sch_prescriptions, cus)
  1408. }
  1409. for _, item := range sch_prescriptions {
  1410. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1411. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1412. }
  1413. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1414. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1415. }
  1416. }
  1417. }
  1418. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1419. if config.ID > 0 && config.IsOpen == 1 {
  1420. for _, item := range sch_prescriptions {
  1421. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1422. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1423. if info.RetailPrice > 0 {
  1424. subItem.Drug.MinPrice = info.RetailPrice
  1425. if admin.CurrentOrgId != 10598 {
  1426. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1427. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. if config.ID > 0 && config.IsOpen == 1 {
  1434. for _, item := range sch_prescriptions {
  1435. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1436. if subItem.Type == 3 {
  1437. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1438. if info.Price > 0 {
  1439. subItem.GoodInfo.PackingPrice = info.Price
  1440. if admin.CurrentOrgId != 10598 {
  1441. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1442. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1450. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1451. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1452. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1453. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1454. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1455. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1456. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1457. //获取所有科室信息
  1458. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1459. c.ServeSuccessJSON(map[string]interface{}{
  1460. "his_info": his_patient_info,
  1461. "xt_info": xt_patient_info,
  1462. "prescription": prescriptions,
  1463. "case_history": case_history,
  1464. "info": patientPrescriptionInfo,
  1465. //"month_prescriptions": monthPrescriptions,
  1466. "order": order,
  1467. "doctors": doctors,
  1468. "department": department,
  1469. "sch_prescriptions": sch_prescriptions,
  1470. "last_prescriptions": last_prescriptions,
  1471. "schedule": sch,
  1472. "count": count,
  1473. "drugStockConfig": drugStockConfig,
  1474. "last_info": lastPatientPrescriptionInfo,
  1475. })
  1476. return
  1477. }
  1478. func (c *HisApiController) GetHisPrescriptionConfig() {
  1479. adminInfo := c.GetAdminUserInfo()
  1480. //获取医嘱模版
  1481. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1482. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1483. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1484. //获取所有基础药
  1485. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1486. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1487. if config.ID > 0 && config.IsOpen == 1 {
  1488. for _, item := range drugs {
  1489. var index = 0
  1490. for _, subItem := range item.OtherDrugWarehouseInfo {
  1491. if index == 0 {
  1492. index = index + 1
  1493. if subItem.RetailPrice > 0 {
  1494. item.MinPrice = subItem.RetailPrice
  1495. }
  1496. }
  1497. }
  1498. }
  1499. }
  1500. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1501. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1502. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1503. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1504. //获取所有科室信息
  1505. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1506. //获取诊断信息
  1507. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1508. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1509. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1510. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1511. //获取是否开启保存耗材出库的开关
  1512. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1513. c.ServeSuccessJSON(map[string]interface{}{
  1514. "drugs": drugs,
  1515. "advices_template": advices,
  1516. "drugways": drugways,
  1517. "efs": efs,
  1518. "doctors": doctors,
  1519. "department": department,
  1520. "sick": sick,
  1521. "additions": additions,
  1522. "diagnose": diagnose,
  1523. "manufacturers": manufacturers,
  1524. "goodOutOpen": goodOutOpen,
  1525. "patientDiagnose": patientDiagnose,
  1526. })
  1527. }
  1528. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1529. //获取所有基础药
  1530. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1531. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1532. if config.ID > 0 && config.IsOpen == 1 {
  1533. for _, item := range drugs {
  1534. var index = 0
  1535. for _, subItem := range item.OtherDrugWarehouseInfo {
  1536. if index == 0 {
  1537. index = index + 1
  1538. if subItem.RetailPrice > 0 {
  1539. item.MinPrice = subItem.RetailPrice
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1546. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1547. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1548. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1551. //获取诊断信息
  1552. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1553. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1554. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1555. //获取是否开启保存耗材出库的开关
  1556. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1557. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1558. c.ServeSuccessJSON(map[string]interface{}{
  1559. "drugs": drugs,
  1560. "advices_template": advices,
  1561. "drugways": drugways,
  1562. "efs": efs,
  1563. "doctors": doctors,
  1564. "department": department,
  1565. "sick": sick,
  1566. "additions": additions,
  1567. "diagnose": diagnose,
  1568. "manufacturers": manufacturers,
  1569. "goodOutOpen": goodOutOpen,
  1570. "patientDiagnose": patientDiagnose,
  1571. })
  1572. }
  1573. }
  1574. func (c *HisApiController) CreateHisPrescription() {
  1575. record_date := c.GetString("record_date")
  1576. patient_id, _ := c.GetInt64("patient_id")
  1577. reg_type, _ := c.GetInt64("reg_type")
  1578. diagnose := c.GetString("diagnose")
  1579. sick_type, _ := c.GetInt64("sick_type")
  1580. sick_history := c.GetString("sick_history")
  1581. doctor_id, _ := c.GetInt64("doctor", 0)
  1582. department, _ := c.GetInt64("department", 0)
  1583. his_patient_id, _ := c.GetInt64("his_patient_id")
  1584. p_type, _ := c.GetInt64("p_type")
  1585. patient_diagnose := c.GetString("patient_diagnose")
  1586. dataBody := make(map[string]interface{}, 0)
  1587. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1588. if err != nil {
  1589. utils.ErrorLog(err.Error())
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. //edit, src := GetCompareData(dataBody)
  1594. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1595. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1596. //fmt.Println(drugResult)
  1597. //fmt.Println(goodResult)
  1598. timeLayout := "2006-01-02"
  1599. loc, _ := time.LoadLocation("Local")
  1600. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1601. if err != nil {
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. adminInfo := c.GetAdminUserInfo()
  1606. recordDateTime := theTime.Unix()
  1607. //查询默认出库仓库库存
  1608. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1609. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1610. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1611. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1612. if len(lists) == 1 {
  1613. his_patient_id = lists[0].ID
  1614. }
  1615. }
  1616. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1617. //自动出库的开关开启
  1618. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1619. //自动出库
  1620. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1621. //耗材保存处方出库
  1622. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1623. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1624. //已发药和已收费限制逻辑
  1625. isMidicine := false
  1626. isCharge := false
  1627. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1628. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1629. if len(prescriptions) > 0 {
  1630. for _, item := range prescriptions {
  1631. items := item.(map[string]interface{})
  1632. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1633. utils.ErrorLog("id")
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1635. return
  1636. }
  1637. id := int64(items["id"].(float64))
  1638. if id > 0 {
  1639. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1640. if err != nil {
  1641. if new_prescription.OrderStatus == 4 {
  1642. isCharge = true
  1643. }
  1644. }
  1645. }
  1646. //if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1647. // advices := items["advices"].([]interface{})
  1648. //
  1649. // if len(advices) > 0 {
  1650. // for _, advice := range advices {
  1651. //
  1652. // var adviceId int64
  1653. // if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1654. // adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1655. // }
  1656. // if adviceId > 0 {
  1657. // his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1658. //
  1659. // if err == nil {
  1660. // if his_advice_info.IsMedicine == 1 {
  1661. //
  1662. // isMidicine = true
  1663. // }
  1664. // }
  1665. // }
  1666. // }
  1667. // }
  1668. //}
  1669. }
  1670. }
  1671. }
  1672. if isMidicine == true {
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1674. return
  1675. }
  1676. if isCharge == true {
  1677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1678. return
  1679. }
  1680. // 开始主事务
  1681. db := service.XTWriteDB()
  1682. tx := db.Begin()
  1683. // 在函数结束时处理事务回滚
  1684. defer func() {
  1685. if r := recover(); r != nil {
  1686. tx.Rollback()
  1687. }
  1688. }()
  1689. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1690. //药品发药出库
  1691. if pharmacyConfig.IsOpen == 1 {
  1692. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1693. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1694. if len(prescriptions) > 0 {
  1695. for _, item := range prescriptions {
  1696. items := item.(map[string]interface{})
  1697. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1698. advices := items["advices"].([]interface{})
  1699. if len(advices) > 0 {
  1700. for _, advice := range advices {
  1701. var drug_id int64
  1702. var prescribing_number float64
  1703. var prescribingNumberUnit string
  1704. var adviceId int64
  1705. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1706. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1707. }
  1708. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1709. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1710. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1711. }
  1712. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1713. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1714. }
  1715. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1716. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1717. }
  1718. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1719. if drug.ID == 0 {
  1720. tx.Rollback()
  1721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1722. return
  1723. }
  1724. //查询药品的所有库存
  1725. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1726. var total_count int64
  1727. for _, it := range list {
  1728. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1729. }
  1730. totals := strconv.FormatInt(total_count, 10)
  1731. //查询该药品是否存在开药记录
  1732. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1733. //新增处方盘点库存是否充足
  1734. if advicelist.ID == 0 {
  1735. all_count, _ := strconv.ParseFloat(totals, 64)
  1736. if prescribingNumberUnit == drug.MinUnit {
  1737. if drug.IsUse != 1 {
  1738. if drug.IsProject == 0 || drug.IsProject == 2 {
  1739. if all_count == 0 {
  1740. tx.Rollback()
  1741. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1742. return
  1743. }
  1744. if prescribing_number > all_count {
  1745. tx.Rollback()
  1746. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1747. return
  1748. }
  1749. }
  1750. }
  1751. }
  1752. if prescribingNumberUnit == drug.MaxUnit {
  1753. num := prescribing_number * float64(drug.MinNumber)
  1754. if drug.IsUse != 1 {
  1755. if drug.IsProject == 0 || drug.IsProject == 2 {
  1756. if all_count == 0 {
  1757. tx.Rollback()
  1758. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1759. return
  1760. }
  1761. if num > all_count {
  1762. tx.Rollback()
  1763. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1764. return
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1771. //不使用保存处方出库
  1772. if drugOutConfig.IsOpen != 1 {
  1773. //修改处方
  1774. for _, advice := range advices {
  1775. var drug_id int64
  1776. var prescribing_number float64
  1777. var prescribingNumberUnit string
  1778. var prescribingNumber string
  1779. var adviceId int64
  1780. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1781. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1782. }
  1783. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1784. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1785. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1786. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1787. }
  1788. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1789. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1790. }
  1791. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1792. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1793. }
  1794. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1795. if drug.ID == 0 {
  1796. tx.Rollback()
  1797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1798. return
  1799. }
  1800. //查询药品的所有库存
  1801. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1802. var total_count int64
  1803. for _, it := range list {
  1804. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1805. }
  1806. totals := strconv.FormatInt(total_count, 10)
  1807. //查询该药品是否存在开药记录
  1808. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1809. //新增处方
  1810. if advicelist.ID == 0 {
  1811. all_count, _ := strconv.ParseFloat(totals, 64)
  1812. if prescribingNumberUnit == drug.MinUnit {
  1813. if drug.IsUse != 1 {
  1814. if drug.IsProject == 0 || drug.IsProject == 2 {
  1815. if all_count == 0 {
  1816. tx.Rollback()
  1817. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1818. return
  1819. }
  1820. if prescribing_number > all_count {
  1821. tx.Rollback()
  1822. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1823. return
  1824. }
  1825. }
  1826. }
  1827. } else {
  1828. if prescribingNumberUnit == drug.MaxUnit {
  1829. num := prescribing_number * float64(drug.MinNumber)
  1830. if drug.IsUse != 1 {
  1831. if drug.IsProject == 0 || drug.IsProject == 2 {
  1832. if all_count == 0 {
  1833. tx.Rollback()
  1834. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1835. return
  1836. }
  1837. if num > all_count {
  1838. tx.Rollback()
  1839. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1840. return
  1841. }
  1842. }
  1843. }
  1844. }
  1845. }
  1846. }
  1847. //修改处方
  1848. if advicelist.ID > 0 {
  1849. var device_number int64
  1850. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1851. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1852. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1853. device_number = prescribingNumberInt * drug.MinNumber
  1854. }
  1855. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1856. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1857. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1858. device_number = prescribingNumberInt
  1859. }
  1860. var number_count int64
  1861. if prescribingNumberUnit == drug.MaxUnit {
  1862. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1863. number_count = prescribingNumberInt * drug.MinNumber
  1864. }
  1865. if prescribingNumberUnit == drug.MinUnit {
  1866. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1867. number_count = prescribingNumberInt
  1868. }
  1869. //如果修改的数量大于之前修改的数量
  1870. if (number_count - device_number) > 0 {
  1871. //如果修改的差数量 大于库存数量
  1872. if drug.IsUse != 1 {
  1873. if (number_count - device_number) > total_count {
  1874. tx.Rollback()
  1875. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1876. return
  1877. }
  1878. }
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. }
  1887. }
  1888. }
  1889. }
  1890. //已发药和已收费限制逻辑
  1891. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1892. //校验库存总量
  1893. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1894. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1895. if len(prescriptions) > 0 {
  1896. for _, item := range prescriptions {
  1897. items := item.(map[string]interface{})
  1898. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1899. advices := items["advices"].([]interface{})
  1900. if len(advices) > 0 {
  1901. for _, advice := range advices {
  1902. var drug_id int64
  1903. var prescribing_number float64
  1904. var prescribingNumberUnit string
  1905. var adviceId int64
  1906. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1907. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1908. }
  1909. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1910. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1911. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1912. }
  1913. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1914. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1915. }
  1916. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1917. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1918. }
  1919. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1920. if drug.ID == 0 {
  1921. tx.Rollback()
  1922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1923. return
  1924. }
  1925. //查询药品的所有库存
  1926. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1927. var total_count int64
  1928. for _, it := range list {
  1929. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1930. }
  1931. totals := strconv.FormatInt(total_count, 10)
  1932. //查询该药品是否存在开药记录
  1933. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1934. //查询最新批次库存
  1935. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1936. var batch_number_count int64
  1937. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1938. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1939. //新增处方
  1940. if advicelist.ID == 0 {
  1941. all_count, _ := strconv.ParseFloat(totals, 64)
  1942. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1943. if prescribingNumberUnit == drug.MinUnit {
  1944. if drug.IsUse != 1 {
  1945. if drug.IsProject == 0 || drug.IsProject == 2 {
  1946. if all_count == 0 {
  1947. tx.Rollback()
  1948. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1949. return
  1950. }
  1951. if prescribing_number > all_count {
  1952. tx.Rollback()
  1953. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1954. return
  1955. }
  1956. }
  1957. if adminInfo.CurrentOrgId == 10215 {
  1958. if prescribing_number > batch_number_all_count {
  1959. tx.Rollback()
  1960. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1961. return
  1962. }
  1963. }
  1964. }
  1965. }
  1966. if prescribingNumberUnit == drug.MaxUnit {
  1967. num := prescribing_number * float64(drug.MinNumber)
  1968. if drug.IsUse != 1 {
  1969. if drug.IsProject == 0 || drug.IsProject == 2 {
  1970. if all_count == 0 {
  1971. tx.Rollback()
  1972. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1973. return
  1974. }
  1975. if num > all_count {
  1976. tx.Rollback()
  1977. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1978. return
  1979. }
  1980. }
  1981. if adminInfo.CurrentOrgId == 10215 {
  1982. if num > batch_number_all_count {
  1983. tx.Rollback()
  1984. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1985. return
  1986. }
  1987. }
  1988. }
  1989. }
  1990. }
  1991. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1992. if drugOutConfig.IsOpen != 1 {
  1993. //修改处方
  1994. for _, advice := range advices {
  1995. var drug_id int64
  1996. var prescribing_number float64
  1997. var prescribingNumberUnit string
  1998. var prescribingNumber string
  1999. var adviceId int64
  2000. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2001. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2002. }
  2003. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2004. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2005. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2006. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2007. }
  2008. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2009. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2010. }
  2011. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2012. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2013. }
  2014. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2015. if drug.ID == 0 {
  2016. tx.Rollback()
  2017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2018. return
  2019. }
  2020. //查询药品的所有库存
  2021. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2022. var total_count int64
  2023. for _, it := range list {
  2024. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2025. }
  2026. totals := strconv.FormatInt(total_count, 10)
  2027. //查询该药品是否存在开药记录
  2028. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2029. //新增处方
  2030. if advicelist.ID == 0 {
  2031. //查询最新批次库存
  2032. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2033. var batch_number_count int64
  2034. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2035. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2036. all_count, _ := strconv.ParseFloat(totals, 64)
  2037. if prescribingNumberUnit == drug.MinUnit {
  2038. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2039. if drug.IsUse != 1 {
  2040. if drug.IsProject == 0 || drug.IsProject == 2 {
  2041. if all_count == 0 {
  2042. tx.Rollback()
  2043. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2044. return
  2045. }
  2046. if prescribing_number > all_count {
  2047. tx.Rollback()
  2048. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2049. return
  2050. }
  2051. }
  2052. if adminInfo.CurrentOrgId == 10215 {
  2053. if prescribing_number > batch_number_all_count {
  2054. tx.Rollback()
  2055. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2056. return
  2057. }
  2058. }
  2059. }
  2060. } else {
  2061. if prescribingNumberUnit == drug.MaxUnit {
  2062. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2063. num := prescribing_number * float64(drug.MinNumber)
  2064. if drug.IsUse != 1 {
  2065. if drug.IsProject == 0 || drug.IsProject == 2 {
  2066. if all_count == 0 {
  2067. tx.Rollback()
  2068. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2069. return
  2070. }
  2071. if num > all_count {
  2072. tx.Rollback()
  2073. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2074. return
  2075. }
  2076. }
  2077. if adminInfo.CurrentOrgId == 10215 {
  2078. if prescribing_number > batch_number_all_count {
  2079. tx.Rollback()
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2081. return
  2082. }
  2083. }
  2084. }
  2085. }
  2086. }
  2087. }
  2088. //修改处方
  2089. if advicelist.ID > 0 {
  2090. //查询最新批次库存
  2091. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2092. var batch_number_count int64
  2093. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2094. var device_number int64
  2095. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2096. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2097. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2098. device_number = prescribingNumberInt * drug.MinNumber
  2099. }
  2100. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2101. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2102. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2103. device_number = prescribingNumberInt
  2104. }
  2105. var number_count int64
  2106. if prescribingNumberUnit == drug.MaxUnit {
  2107. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2108. number_count = prescribingNumberInt * drug.MinNumber
  2109. }
  2110. if prescribingNumberUnit == drug.MinUnit {
  2111. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2112. number_count = prescribingNumberInt
  2113. }
  2114. //如果修改的数量大于之前修改的数量
  2115. if (number_count - device_number) > 0 {
  2116. //如果修改的差数量 大于库存数量
  2117. if drug.IsUse != 1 {
  2118. if drug.IsProject == 0 || drug.IsProject == 2 {
  2119. if total_count == 0 {
  2120. tx.Rollback()
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2122. return
  2123. }
  2124. if (number_count - device_number) > total_count {
  2125. tx.Rollback()
  2126. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2127. return
  2128. }
  2129. if (number_count - device_number) > batch_number_count {
  2130. tx.Rollback()
  2131. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2132. return
  2133. }
  2134. }
  2135. if adminInfo.CurrentOrgId == 10215 {
  2136. // 查询该药品最后一次出库记录
  2137. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2138. var out_count int64
  2139. var in_count int64
  2140. var stock_max_number int64
  2141. var stock_min_number int64
  2142. for _, it := range outInfo {
  2143. if it.CountUnit == drug.MaxUnit {
  2144. it.Count = it.Count * drug.MinNumber
  2145. }
  2146. out_count += it.Count
  2147. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2148. stock_max_number = warehouseInfoList.StockMaxNumber
  2149. stock_min_number = warehouseInfoList.StockMinNumber
  2150. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2151. }
  2152. if out_count > 0 {
  2153. if (number_count - device_number) > in_count {
  2154. tx.Rollback()
  2155. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2156. return
  2157. }
  2158. }
  2159. // 未出库
  2160. if out_count == 0 {
  2161. var sum_in_count int64
  2162. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2163. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2164. fmt.Println("sum_in_count", sum_in_count)
  2165. //如果修改的数量大于有库存的第一个批次
  2166. if number_count > sum_in_count {
  2167. tx.Rollback()
  2168. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2169. return
  2170. }
  2171. }
  2172. }
  2173. }
  2174. }
  2175. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2176. if pharmacyConfig.IsOpen != 1 {
  2177. if device_number != number_count {
  2178. // 查询该药品最后一次出库记录
  2179. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2180. //回退库存
  2181. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2182. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2183. }
  2184. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2185. var stock_max_number int64
  2186. var stock_min_number int64
  2187. if number_count >= drug.MinNumber {
  2188. stock_max_number = device_number / drug.MinNumber
  2189. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2190. stock_min_number = device_number % drug.MinNumber
  2191. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2192. } else {
  2193. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2194. }
  2195. }
  2196. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2197. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2198. }
  2199. //删除记录
  2200. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2201. //查询默认仓库剩余多少库存
  2202. var sum_count int64
  2203. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2204. for _, its := range stockInfo {
  2205. if its.MaxUnit == drug.MaxUnit {
  2206. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2207. }
  2208. sum_count += its.StockMaxNumber + its.StockMinNumber
  2209. }
  2210. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2211. }
  2212. }
  2213. }
  2214. }
  2215. }
  2216. //保存处方开药
  2217. if drugOutConfig.IsOpen == 1 {
  2218. //修改处方
  2219. for _, advice := range advices {
  2220. var drug_id int64
  2221. var prescribing_number float64
  2222. var prescribingNumberUnit string
  2223. var prescribingNumber string
  2224. var adviceId int64
  2225. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2226. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2227. }
  2228. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2229. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2230. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2231. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2232. }
  2233. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2234. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2235. }
  2236. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2237. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2238. }
  2239. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2240. if drug.ID == 0 {
  2241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2242. return
  2243. }
  2244. //查询药品的所有库存
  2245. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2246. var total_count int64
  2247. for _, it := range list {
  2248. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2249. }
  2250. totals := strconv.FormatInt(total_count, 10)
  2251. //查询该药品是否存在开药记录
  2252. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2253. //新增处方
  2254. if advicelist.ID == 0 {
  2255. //查询最新批次库存
  2256. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2257. var batch_number_count int64
  2258. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2259. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2260. all_count, _ := strconv.ParseFloat(totals, 64)
  2261. if prescribingNumberUnit == drug.MinUnit {
  2262. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2263. if drug.IsUse != 1 {
  2264. if drug.IsProject == 0 || drug.IsProject == 2 {
  2265. if all_count == 0 {
  2266. tx.Rollback()
  2267. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2268. return
  2269. }
  2270. if prescribing_number > all_count {
  2271. tx.Rollback()
  2272. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2273. return
  2274. }
  2275. }
  2276. if adminInfo.CurrentOrgId == 10215 {
  2277. if prescribing_number > batch_number_all_count {
  2278. tx.Rollback()
  2279. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2280. return
  2281. }
  2282. }
  2283. }
  2284. } else {
  2285. if prescribingNumberUnit == drug.MaxUnit {
  2286. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2287. num := prescribing_number * float64(drug.MinNumber)
  2288. if drug.IsUse != 1 {
  2289. if drug.IsProject == 0 || drug.IsProject == 2 {
  2290. if all_count == 0 {
  2291. tx.Rollback()
  2292. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2293. return
  2294. }
  2295. if num > all_count {
  2296. tx.Rollback()
  2297. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2298. return
  2299. }
  2300. }
  2301. if adminInfo.CurrentOrgId == 10215 {
  2302. if prescribing_number > batch_number_all_count {
  2303. tx.Rollback()
  2304. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2305. return
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. }
  2312. //修改处方
  2313. if advicelist.ID > 0 {
  2314. //查询最新批次库存
  2315. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2316. var batch_number_count int64
  2317. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2318. var device_number int64
  2319. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2320. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2321. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2322. device_number = prescribingNumberInt * drug.MinNumber
  2323. }
  2324. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2325. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2326. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2327. device_number = prescribingNumberInt
  2328. }
  2329. var number_count int64
  2330. if prescribingNumberUnit == drug.MaxUnit {
  2331. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2332. number_count = prescribingNumberInt * drug.MinNumber
  2333. }
  2334. if prescribingNumberUnit == drug.MinUnit {
  2335. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2336. number_count = prescribingNumberInt
  2337. }
  2338. fmt.Println("number_count--------------", number_count)
  2339. fmt.Println("device_number--------------", device_number)
  2340. fmt.Println("batch_number_count", batch_number_count)
  2341. //如果修改的数量大于之前修改的数量
  2342. if (number_count - device_number) > 0 {
  2343. //如果修改的差数量 大于库存数量
  2344. if drug.IsUse != 1 {
  2345. if drug.IsProject == 0 || drug.IsProject == 2 {
  2346. if total_count == 0 {
  2347. tx.Rollback()
  2348. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2349. return
  2350. }
  2351. if (number_count - device_number) > total_count {
  2352. tx.Rollback()
  2353. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2354. return
  2355. }
  2356. }
  2357. if adminInfo.CurrentOrgId == 10215 {
  2358. if (number_count - device_number) > batch_number_count {
  2359. tx.Rollback()
  2360. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2361. return
  2362. }
  2363. }
  2364. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2365. //查询历史出库数据总批次
  2366. // 查询该药品最后一次出库记录
  2367. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2368. var out_count int64
  2369. var in_count int64
  2370. var stock_max_number int64
  2371. var stock_min_number int64
  2372. for _, it := range outInfo {
  2373. if it.CountUnit == drug.MaxUnit {
  2374. it.Count = it.Count * drug.MinNumber
  2375. }
  2376. out_count += it.Count
  2377. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2378. stock_max_number = warehouseInfoList.StockMaxNumber
  2379. stock_min_number = warehouseInfoList.StockMinNumber
  2380. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2381. }
  2382. if out_count > 0 {
  2383. if (number_count - device_number) > in_count {
  2384. tx.Rollback()
  2385. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2386. return
  2387. }
  2388. }
  2389. // 未出库
  2390. if out_count == 0 {
  2391. var sum_in_count int64
  2392. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2393. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2394. if sum_in_count == 0 {
  2395. tx.Rollback()
  2396. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2397. return
  2398. }
  2399. //如果修改的数量大于有库存的第一个批次
  2400. if number_count > sum_in_count {
  2401. tx.Rollback()
  2402. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2403. return
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. }
  2415. }
  2416. }
  2417. }
  2418. }
  2419. //校验耗材库存
  2420. if goodOutConfig.IsOpen == 1 {
  2421. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2422. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2423. if len(prescriptions) > 0 {
  2424. for _, item := range prescriptions {
  2425. items := item.(map[string]interface{})
  2426. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2427. projects := items["project"].([]interface{})
  2428. if len(projects) > 0 {
  2429. for _, project := range projects {
  2430. var project_id int64
  2431. var project_type int64
  2432. var totals float64
  2433. var project_name string
  2434. var parsetotal int64
  2435. var id int64
  2436. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2437. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2438. }
  2439. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2440. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2441. }
  2442. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2443. total, _ := project.(map[string]interface{})["total"].(string)
  2444. totals, _ = strconv.ParseFloat(total, 64)
  2445. }
  2446. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2447. project_name = project.(map[string]interface{})["project_name"].(string)
  2448. }
  2449. if project_type == 3 {
  2450. //查找该耗材的出库记录
  2451. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2452. if len(goodWarehouseInfo) == 0 {
  2453. //查询耗材库存
  2454. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2455. var stock_count int64
  2456. for _, it := range list {
  2457. stock_count += it.StockCount
  2458. }
  2459. stock_counts := strconv.FormatInt(stock_count, 10)
  2460. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2461. if stock_total_count == 0 {
  2462. tx.Rollback()
  2463. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2464. return
  2465. }
  2466. if totals > stock_total_count {
  2467. tx.Rollback()
  2468. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2469. return
  2470. }
  2471. }
  2472. if len(goodWarehouseInfo) > 0 {
  2473. //查询该患者耗材的历史数据
  2474. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2475. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2476. //数量发生改变
  2477. if parsetotal != count {
  2478. //如果现在的数量大于历史数量,就要看库存是否足够
  2479. if parsetotal > count {
  2480. //查询耗材所有库存
  2481. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2482. var stock_count int64
  2483. for _, it := range list {
  2484. stock_count += it.StockCount
  2485. }
  2486. //库存不足
  2487. if stock_count == 0 {
  2488. tx.Rollback()
  2489. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2490. return
  2491. }
  2492. if (parsetotal - count) > stock_count {
  2493. tx.Rollback()
  2494. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2495. return
  2496. }
  2497. }
  2498. }
  2499. }
  2500. }
  2501. }
  2502. }
  2503. }
  2504. }
  2505. }
  2506. }
  2507. }
  2508. //不使用耗材保存处方出库
  2509. if goodOutConfig.IsOpen != 1 {
  2510. if stockConfig.IsOpen == 1 {
  2511. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2512. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2513. if len(prescriptions) > 0 {
  2514. for _, item := range prescriptions {
  2515. items := item.(map[string]interface{})
  2516. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2517. projects := items["project"].([]interface{})
  2518. if len(projects) > 0 {
  2519. for _, project := range projects {
  2520. var project_id int64
  2521. var project_type int64
  2522. var totals float64
  2523. var project_name string
  2524. var parsetotal int64
  2525. var id int64
  2526. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2527. id = int64(project.(map[string]interface{})["id"].(float64))
  2528. }
  2529. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2530. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2531. }
  2532. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2533. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2534. }
  2535. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2536. total, _ := project.(map[string]interface{})["total"].(string)
  2537. totals, _ = strconv.ParseFloat(total, 64)
  2538. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2539. }
  2540. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2541. project_name = project.(map[string]interface{})["project_name"].(string)
  2542. }
  2543. if project_type == 3 {
  2544. //查找该耗材的出库记录
  2545. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2546. //没有出库记录
  2547. if len(goodWarehouseInfo) == 0 {
  2548. //查询耗材库存
  2549. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2550. var stock_count int64
  2551. for _, it := range list {
  2552. stock_count += it.StockCount
  2553. }
  2554. stock_counts := strconv.FormatInt(stock_count, 10)
  2555. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2556. if stock_total_count == 0 {
  2557. tx.Rollback()
  2558. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2559. return
  2560. }
  2561. if totals > stock_total_count {
  2562. tx.Rollback()
  2563. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2564. return
  2565. }
  2566. //查找今日该患者已经出库的所有耗材
  2567. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2568. for _, item := range goodList {
  2569. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2570. var flush_count int64
  2571. for _, it := range goodListSix {
  2572. flush_count += it.StockCount
  2573. }
  2574. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2575. creater := adminInfo.AdminUser.Id
  2576. if errs != nil {
  2577. goodErrcode := models.XtGoodErrcode{
  2578. UserOrgId: item.OrgId,
  2579. Errcode: "手动出库更新剩余出库失败",
  2580. GoodId: item.GoodId,
  2581. Status: 1,
  2582. Ctime: time.Now().Unix(),
  2583. Mtime: 0,
  2584. Count: 0,
  2585. StockCount: 0,
  2586. Creater: creater,
  2587. BatchNumberId: 0,
  2588. WarehouseOutId: 0,
  2589. }
  2590. service.CreateGoodErrcode(goodErrcode)
  2591. }
  2592. }
  2593. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2594. }
  2595. //有出库记录
  2596. if len(goodWarehouseInfo) > 0 {
  2597. //查询该患者耗材的历史数据
  2598. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2599. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2600. //数量发生改变
  2601. if parsetotal != count {
  2602. //查找今日该患者已经出库的所有耗材
  2603. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2604. for _, item := range goodList {
  2605. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2606. var flush_count int64
  2607. for _, it := range goodListSix {
  2608. flush_count += it.StockCount
  2609. }
  2610. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2611. //减少出库数量
  2612. creater := adminInfo.AdminUser.Id
  2613. if errs != nil {
  2614. goodErrcode := models.XtGoodErrcode{
  2615. UserOrgId: item.OrgId,
  2616. Errcode: "手动出库更新剩余出库失败",
  2617. GoodId: item.GoodId,
  2618. Status: 1,
  2619. Ctime: time.Now().Unix(),
  2620. Mtime: 0,
  2621. Count: 0,
  2622. StockCount: 0,
  2623. Creater: creater,
  2624. BatchNumberId: 0,
  2625. WarehouseOutId: 0,
  2626. }
  2627. service.CreateGoodErrcode(goodErrcode)
  2628. }
  2629. //查询默认仓库
  2630. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2631. var total_count int64
  2632. for _, it := range stockList {
  2633. total_count += it.StockCount
  2634. }
  2635. //基础库插入数据
  2636. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2637. }
  2638. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. }
  2645. }
  2646. }
  2647. }
  2648. }
  2649. }
  2650. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2651. var hpInfo models.HisPrescriptionInfo
  2652. if info.ID == 0 {
  2653. var randNum int
  2654. randNum = rand.Intn(10000) + 1000
  2655. timestamp := time.Now().Unix()
  2656. tempTime := time.Unix(timestamp, 0)
  2657. timeFormat := tempTime.Format("20060102150405")
  2658. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2659. hpInfo = models.HisPrescriptionInfo{
  2660. HisPatientId: his_patient_id,
  2661. UserOrgId: adminInfo.CurrentOrgId,
  2662. RecordDate: theTime.Unix(),
  2663. PatientId: patient_id,
  2664. Status: 1,
  2665. Ctime: time.Now().Unix(),
  2666. Mtime: time.Now().Unix(),
  2667. Creator: adminInfo.AdminUser.Id,
  2668. Modifier: adminInfo.AdminUser.Id,
  2669. Diagnosis: diagnose,
  2670. SickHistory: sick_history,
  2671. Departments: department,
  2672. RegisterType: reg_type,
  2673. PrescriptionNumber: p_number,
  2674. PrescriptionStatus: 1,
  2675. Doctor: role.UserName,
  2676. DoctorId: doctor_id,
  2677. SickType: sick_type,
  2678. PType: p_type,
  2679. PatientDiagnosis: patient_diagnose,
  2680. }
  2681. service.SavePatientPrescriptionInfo(hpInfo)
  2682. //创建步骤表
  2683. finish := models.XtDialysisFinish{
  2684. IsFinish: 1,
  2685. UserOrgId: adminInfo.CurrentOrgId,
  2686. Status: 1,
  2687. Ctime: time.Now().Unix(),
  2688. Mtime: 0,
  2689. Module: 4,
  2690. RecordDate: theTime.Unix(),
  2691. Sourse: 1,
  2692. PatientId: patient_id,
  2693. }
  2694. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2695. if dialysisFinish.ID == 0 {
  2696. service.CreateDialysisFinish(finish)
  2697. }
  2698. redis := service.RedisClient()
  2699. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2700. redis.Set(key, "", time.Second)
  2701. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2702. redis.Set(keyOne, "", time.Second)
  2703. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2704. redis.Set(keySeven, "", time.Second)
  2705. defer redis.Close()
  2706. } else {
  2707. hpInfo = models.HisPrescriptionInfo{
  2708. ID: info.ID,
  2709. UserOrgId: adminInfo.CurrentOrgId,
  2710. RecordDate: info.RecordDate,
  2711. PatientId: info.PatientId,
  2712. Status: 1,
  2713. Ctime: info.Ctime,
  2714. Mtime: time.Now().Unix(),
  2715. Creator: info.Creator,
  2716. Modifier: adminInfo.AdminUser.Id,
  2717. Diagnosis: diagnose,
  2718. SickHistory: sick_history,
  2719. Departments: department,
  2720. RegisterType: reg_type,
  2721. PrescriptionNumber: info.PrescriptionNumber,
  2722. Doctor: role.UserName,
  2723. PrescriptionStatus: info.PrescriptionStatus,
  2724. DoctorId: doctor_id,
  2725. SickType: sick_type,
  2726. PType: info.PType,
  2727. HisPatientId: info.HisPatientId,
  2728. PatientDiagnosis: patient_diagnose,
  2729. }
  2730. service.SavePatientPrescriptionInfo(hpInfo)
  2731. //创建步骤表
  2732. finish := models.XtDialysisFinish{
  2733. IsFinish: 1,
  2734. UserOrgId: adminInfo.CurrentOrgId,
  2735. Status: 1,
  2736. Ctime: time.Now().Unix(),
  2737. Mtime: 0,
  2738. Module: 4,
  2739. RecordDate: info.RecordDate,
  2740. Sourse: 1,
  2741. PatientId: info.PatientId,
  2742. }
  2743. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2744. if dialysisFinish.ID == 0 {
  2745. service.CreateDialysisFinish(finish)
  2746. }
  2747. redis := service.RedisClient()
  2748. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2749. redis.Set(key, "", time.Second)
  2750. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2751. redis.Set(keyOne, "", time.Second)
  2752. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2753. redis.Set(keySeven, "", time.Second)
  2754. defer redis.Close()
  2755. }
  2756. //定义切片
  2757. var adviceList []models.HisDoctorAdviceInfo
  2758. var projectList []models.HisPrescriptionProject
  2759. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10610 {
  2760. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2761. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2762. var tempPrescription *models.HisPrescription
  2763. if len(prescriptions) > 0 {
  2764. for _, item := range prescriptions {
  2765. // 开始外部循环的事务
  2766. tx := db.Begin()
  2767. // 在函数结束时处理事务回滚
  2768. defer func() {
  2769. if r := recover(); r != nil {
  2770. tx.Rollback()
  2771. }
  2772. }()
  2773. items := item.(map[string]interface{})
  2774. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2775. utils.ErrorLog("id")
  2776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2777. return
  2778. }
  2779. id := int64(items["id"].(float64))
  2780. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2781. tempPrescription = &new_prescription
  2782. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2783. utils.ErrorLog("type")
  2784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2785. return
  2786. }
  2787. types := int64(items["type"].(float64))
  2788. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2789. utils.ErrorLog("med_type")
  2790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2791. return
  2792. }
  2793. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2794. if med_type == "0" {
  2795. med_type = "14"
  2796. }
  2797. //if order_status == 0 {
  2798. // order_status = 1
  2799. //}
  2800. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2801. utils.ErrorLog("pre_time")
  2802. }
  2803. preTime, _ := items["pre_time"].(string)
  2804. fmt.Println("preTime", preTime)
  2805. timeLayout := "2006-01-02"
  2806. loc, _ := time.LoadLocation("Local")
  2807. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2808. result := strings.Split(preTime, " ")
  2809. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2810. if err != nil {
  2811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2812. return
  2813. }
  2814. pTime := theTime2.Unix()
  2815. ctime := time.Now().Unix()
  2816. if tempPrescription.ID == 0 {
  2817. prescription := &models.HisPrescription{
  2818. ID: 0,
  2819. PatientId: patient_id,
  2820. UserOrgId: adminInfo.CurrentOrgId,
  2821. RecordDate: recordDateTime,
  2822. Ctime: ctime,
  2823. Mtime: ctime,
  2824. Type: types,
  2825. Modifier: adminInfo.AdminUser.Id,
  2826. Creator: adminInfo.AdminUser.Id,
  2827. Status: 1,
  2828. Doctor: role.UserName,
  2829. HisPatientId: his_patient_id,
  2830. OrderStatus: 1,
  2831. BatchNumber: "",
  2832. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2833. PreTime: pTime,
  2834. PType: p_type,
  2835. MedType: med_type,
  2836. }
  2837. tempPrescription = prescription
  2838. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2839. redis := service.RedisClient()
  2840. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2841. redis.Set(key, "", time.Second)
  2842. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2843. redis.Set(keyOne, "", time.Second)
  2844. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2845. redis.Set(keySeven, "", time.Second)
  2846. defer redis.Close()
  2847. } else {
  2848. tempPrescription.ID = id
  2849. tempPrescription.Type = types
  2850. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2851. tempPrescription.Mtime = time.Now().Unix()
  2852. tempPrescription.Doctor = role.UserName
  2853. //tempPrescription.OrderStatus = order_status
  2854. tempPrescription.PreTime = pTime
  2855. tempPrescription.MedType = med_type
  2856. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2857. redis := service.RedisClient()
  2858. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2859. redis.Set(key, "", time.Second)
  2860. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2861. redis.Set(keyOne, "", time.Second)
  2862. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2863. redis.Set(keySeven, "", time.Second)
  2864. defer redis.Close()
  2865. }
  2866. //service.SaveHisPrescription(prescription)
  2867. //更改患者挂号状态
  2868. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2869. fmt.Println("更改失败", err2)
  2870. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2871. advices := items["advices"].([]interface{})
  2872. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2873. groupNo := int64(0)
  2874. if len(advices) > 0 {
  2875. for _, advice := range advices {
  2876. tx := db.Begin()
  2877. // 在函数结束时处理事务回滚
  2878. defer func() {
  2879. if r := recover(); r != nil {
  2880. tx.Rollback()
  2881. }
  2882. }()
  2883. var s models.HisDoctorAdviceInfo
  2884. s.PrescriptionId = tempPrescription.ID
  2885. s.AdviceType = 2
  2886. s.AdviceDoctor = doctor_id
  2887. s.StopState = 2
  2888. s.ExecutionState = 2
  2889. s.AdviceDate = theTime3.Unix()
  2890. s.Status = 1
  2891. s.UserOrgId = adminInfo.CurrentOrgId
  2892. s.RecordDate = theTime3.Unix()
  2893. s.StartTime = tempPrescription.PreTime
  2894. s.Groupno = groupNo
  2895. s.PatientId = patient_id
  2896. s.HisPatientId = his_patient_id
  2897. s.StartTime = pTime
  2898. s.IsSettle = 2
  2899. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2900. if errcode > 0 {
  2901. c.ServeFailJSONWithSGJErrorCode(errcode)
  2902. return
  2903. }
  2904. s.StartTime = pTime
  2905. var total_count int64 //处方总库存
  2906. //查询改药品信息
  2907. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2908. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2909. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2910. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2911. total_count += prescribingNumberSeven * medical.MinNumber
  2912. }
  2913. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2914. total_count += prescribingNumberSeven
  2915. }
  2916. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2917. total_count += prescribingNumberSeven
  2918. }
  2919. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2920. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2921. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2922. if s.Price != lastWarehouse.RetailPrice {
  2923. s.Price = lastWarehouse.RetailPrice
  2924. }
  2925. if s.Price == 0 {
  2926. if lastWarehouse.ID == 0 {
  2927. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2928. s.Price = lastWarehouseTwo.RetailPrice
  2929. }
  2930. }
  2931. }
  2932. //查询保存处方出库开关是否打开
  2933. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2934. if s.PatientId != 30038 {
  2935. if drugOutConfig.IsOpen == 1 {
  2936. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2937. // 查询该药品最后一次出库记录
  2938. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2939. var is_user_total int64
  2940. var no_user_total int64
  2941. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2942. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2943. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2944. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2945. }
  2946. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2947. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2948. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2949. no_user_total += prescribingNumberSevenTy
  2950. }
  2951. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2952. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2953. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2954. no_user_total += prescribingNumberSevenTy
  2955. }
  2956. if len(druginfo) > 0 {
  2957. for _, it := range druginfo {
  2958. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2959. it.Count = it.Count * drug.MinNumber
  2960. is_user_total += it.Count
  2961. }
  2962. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2963. is_user_total += it.Count
  2964. }
  2965. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2966. is_user_total += it.Count
  2967. }
  2968. }
  2969. }
  2970. if is_user_total != no_user_total {
  2971. //出库
  2972. if drug.IsUse == 2 {
  2973. creater := adminInfo.AdminUser.Id
  2974. newadviceInfo := &models.HisDoctorAdviceInfo{
  2975. ID: s.ID,
  2976. UserOrgId: s.UserOrgId,
  2977. PatientId: s.PatientId,
  2978. HisPatientId: s.HisPatientId,
  2979. AdviceType: s.AdviceType,
  2980. AdviceDate: s.AdviceDate,
  2981. StartTime: s.StartTime,
  2982. AdviceName: s.AdviceName,
  2983. AdviceDesc: s.AdviceDesc,
  2984. ReminderDate: s.ReminderDate,
  2985. SingleDose: s.SingleDose,
  2986. SingleDoseUnit: s.SingleDoseUnit,
  2987. PrescribingNumber: s.PrescribingNumber,
  2988. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2989. DeliveryWay: s.DeliveryWay,
  2990. ExecutionFrequency: s.ExecutionFrequency,
  2991. AdviceDoctor: s.AdviceDoctor,
  2992. Status: s.Status,
  2993. CreatedTime: s.CreatedTime,
  2994. UpdatedTime: s.UpdatedTime,
  2995. AdviceAffirm: s.AdviceAffirm,
  2996. Remark: s.Remark,
  2997. StopTime: s.StopTime,
  2998. StopReason: s.StopReason,
  2999. StopDoctor: s.StopDoctor,
  3000. StopState: s.StopState,
  3001. ParentId: s.ParentId,
  3002. ExecutionTime: s.ExecutionTime,
  3003. ExecutionStaff: s.ExecutionStaff,
  3004. ExecutionState: s.ExecutionState,
  3005. Checker: s.Checker,
  3006. RecordDate: s.RecordDate,
  3007. DialysisOrderId: s.DialysisOrderId,
  3008. CheckTime: s.CheckTime,
  3009. CheckState: s.CheckState,
  3010. DrugSpec: s.DrugSpec,
  3011. DrugSpecUnit: s.DrugSpecUnit,
  3012. Groupno: s.Groupno,
  3013. RemindType: s.RemindType,
  3014. FrequencyType: s.FrequencyType,
  3015. DayCount: s.DayCount,
  3016. WeekDay: s.WeekDay,
  3017. TemplateId: s.TemplateId,
  3018. Modifier: s.Modifier,
  3019. DrugId: s.DrugId,
  3020. Price: s.Price,
  3021. PrescriptionId: s.PrescriptionId,
  3022. MedListCodg: s.MedListCodg,
  3023. FeedetlSn: s.FeedetlSn,
  3024. Day: s.DayCount,
  3025. ChildDoctorAdvice: nil,
  3026. Drug: models.Drug{},
  3027. Diagnosis: s.Diagnosis,
  3028. Way: s.Way,
  3029. HospApprFlag: s.HospApprFlag,
  3030. LmtUsedFlag: s.LmtUsedFlag,
  3031. HisOrderInfo: models.HisOrderInfo{},
  3032. IsMedicine: s.IsMedicine,
  3033. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3034. Child: nil,
  3035. IsSettle: s.IsSettle,
  3036. IsMobile: s.IsMobile,
  3037. IsSelfDrug: s.IsSelfDrug,
  3038. DrugWayCount: s.DrugWayCount,
  3039. }
  3040. var history_count int64
  3041. var local_count int64
  3042. //查找已经开过的医嘱信息
  3043. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3044. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3045. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3046. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3047. local_count += prescribingNumberSevenTy * drug.MinNumber
  3048. }
  3049. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3050. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3051. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3052. local_count += prescribingNumberSevenTy
  3053. }
  3054. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3055. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3056. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3057. local_count += prescribingNumberSevenTy
  3058. }
  3059. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3060. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3061. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3062. history_count += prescribingNumberSevenTy * drug.MinNumber
  3063. }
  3064. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3065. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3066. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3067. history_count += prescribingNumberSevenTy
  3068. }
  3069. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3070. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3071. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3072. history_count += prescribingNumberSevenTy
  3073. }
  3074. //fmt.Println("local_count0000000000000000000000000000000000000000000", local_count)
  3075. //
  3076. //fmt.Println("history_count999999999999999999999999999999999999999", history_count)
  3077. //如果当前出库数量大于历史出库数量则需要出库
  3078. if local_count > history_count {
  3079. //按最小单位出库
  3080. var cha_count = local_count - history_count
  3081. //fmt.Println("cha_count000000000000000000000000000", cha_count)
  3082. newadviceInfo.PrescribingNumber = float64(cha_count)
  3083. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3084. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3085. }
  3086. //如果当前出库数量小于历史出库数量则需要退库
  3087. if local_count < history_count {
  3088. var cha_count = history_count - local_count
  3089. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3090. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3091. }
  3092. }
  3093. //更新字典里面的库存
  3094. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3095. var sum_count int64
  3096. for _, its := range stockInfo {
  3097. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3098. if its.MaxUnit == baseDrug.MaxUnit {
  3099. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3100. }
  3101. sum_count += its.StockMaxNumber + its.StockMinNumber
  3102. }
  3103. //更新基础库存
  3104. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3105. //剩余库存
  3106. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3107. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3108. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3109. //创建医嘱
  3110. service.CreateHisDoctorAdviceOne(&s, tx)
  3111. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3112. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3113. if len(outInfoTwo) > 0 {
  3114. for _, item := range outInfoTwo {
  3115. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3116. }
  3117. }
  3118. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3119. if len(drugAutoDetail) > 0 {
  3120. for _, item := range drugAutoDetail {
  3121. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3122. }
  3123. }
  3124. }
  3125. }
  3126. }
  3127. //记录日志
  3128. byterequest, _ := json.Marshal(s)
  3129. adviceLog := models.XtDoctorAdviceLog{
  3130. UserOrgId: s.UserOrgId,
  3131. PatientId: s.PatientId,
  3132. AdminUserId: adminInfo.AdminUser.Id,
  3133. Module: 1,
  3134. ErrLog: string(byterequest),
  3135. Status: 1,
  3136. Ctime: time.Now().Unix(),
  3137. Mtime: 0,
  3138. Source: "电脑端新建his医嘱",
  3139. RecordDate: s.AdviceDate,
  3140. }
  3141. service.CreateDoctorAdviceLog(adviceLog)
  3142. //存储切片中
  3143. adviceList = append(adviceList, s)
  3144. redis := service.RedisClient()
  3145. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3146. redis.Set(key, "", time.Second)
  3147. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3148. redis.Set(keyOne, "", time.Second)
  3149. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3150. redis.Set(keySeven, "", time.Second)
  3151. var randNum int
  3152. randNum = rand.Intn(10000) + 1000
  3153. timestamp := time.Now().Unix()
  3154. tempTime := time.Unix(timestamp, 0)
  3155. timeFormat := tempTime.Format("20060102150405")
  3156. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3157. //查询改药品是否已经停用
  3158. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3159. if base.ID > 0 {
  3160. tx.Rollback()
  3161. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3162. return
  3163. }
  3164. service.CreateHisDoctorAdviceOne(&s, tx)
  3165. tx.Commit()
  3166. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3167. redis.Set(keySix, "", time.Second)
  3168. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3169. redis.Set(keyFive, "", time.Second)
  3170. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3171. redis.Set(keyEight, "", time.Second)
  3172. defer redis.Close()
  3173. }
  3174. }
  3175. }
  3176. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3177. projects := items["project"].([]interface{})
  3178. if len(projects) > 0 {
  3179. for _, project := range projects {
  3180. tx := db.Begin()
  3181. // 在函数结束时处理事务回滚
  3182. defer func() {
  3183. if r := recover(); r != nil {
  3184. tx.Rollback()
  3185. }
  3186. }()
  3187. var p models.HisPrescriptionProject
  3188. p.PrescriptionId = tempPrescription.ID
  3189. p.PatientId = patient_id
  3190. p.RecordDate = theTime3.Unix()
  3191. p.Doctor = doctor_id
  3192. p.UserOrgId = adminInfo.CurrentOrgId
  3193. p.HisPatientId = his_patient_id
  3194. p.Status = 1
  3195. p.StartTime = pTime
  3196. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3197. if errcode > 0 {
  3198. c.ServeFailJSONWithSGJErrorCode(errcode)
  3199. return
  3200. }
  3201. if p.ID == 0 {
  3202. p.IsOut = 2
  3203. }
  3204. if p.ID > 0 {
  3205. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3206. p.IsOut = projectDetail.IsOut
  3207. }
  3208. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3209. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3210. if p.Type == 3 {
  3211. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3212. if p.Price != lastWarehouse.PackingPrice {
  3213. p.Price = lastWarehouse.PackingPrice
  3214. }
  3215. if p.Unit == "" {
  3216. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3217. p.Unit = goodInfoOne.PackingUnit
  3218. }
  3219. }
  3220. }
  3221. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3222. //
  3223. // if p.Type == 3 {
  3224. // //查询该耗材是否停用
  3225. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3226. // //表示该耗材已经停用,不能保存
  3227. // if goodInfoSeven.ID == 0 {
  3228. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3229. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3230. // return
  3231. // }
  3232. // }
  3233. //
  3234. //}
  3235. //查询保存耗材出库开关是否打开
  3236. if p.PatientId != 30038 {
  3237. if goodOutConfig.IsOpen == 1 {
  3238. //耗材出库
  3239. if p.Type == 3 {
  3240. //对比当前数据和历史出库数据
  3241. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3242. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3243. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3244. //如果当前处方数量大于历史数据,则需要出库
  3245. if nowCount > historyCount {
  3246. var cha_count int64
  3247. cha_count = nowCount - historyCount
  3248. timeStr := time.Now().Format("2006-01-02")
  3249. timeArr := strings.Split(timeStr, "-")
  3250. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3251. total = total + 1
  3252. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3253. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3254. number = number + total
  3255. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3256. operation_time := time.Now().Unix()
  3257. creater := c.GetAdminUserInfo().AdminUser.Id
  3258. recordDateStr := time.Now().Format("2006-01-02")
  3259. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3260. nowtime := recordDate.Unix()
  3261. warehouseOut := models.WarehouseOut{
  3262. WarehouseOutOrderNumber: warehousing_out_order,
  3263. OperationTime: operation_time,
  3264. OrgId: adminInfo.CurrentOrgId,
  3265. Creater: creater,
  3266. Ctime: time.Now().Unix(),
  3267. Status: 1,
  3268. WarehouseOutTime: nowtime,
  3269. Type: 1,
  3270. StorehouseId: storeConfig.StorehouseOutInfo,
  3271. IsCheck: 1,
  3272. IsSys: 1,
  3273. }
  3274. //查询是否生成出库单
  3275. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3276. if out.ID == 0 {
  3277. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3278. }
  3279. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3280. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3281. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3282. dialyPrepareOne := models.DialysisBeforePrepare{
  3283. GoodTypeId: goodObj.GoodTypeId,
  3284. GoodId: p.ProjectId,
  3285. PatientId: p.PatientId,
  3286. RecordDate: p.RecordDate,
  3287. UserOrgId: adminInfo.CurrentOrgId,
  3288. Count: cha_count,
  3289. Ctime: time.Now().Unix(),
  3290. Creater: creater,
  3291. Status: 1,
  3292. StorehouseId: houseConfig.StorehouseOutInfo,
  3293. ProjectId: p.ID,
  3294. }
  3295. //出库
  3296. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3297. }
  3298. //如果当前处方数量小于历史数据,怎需要退库
  3299. if nowCount < historyCount {
  3300. var cha_count int64
  3301. cha_count = historyCount - nowCount
  3302. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3303. creater := c.GetAdminUserInfo().AdminUser.Id
  3304. newPrescriptionProject := &models.HisPrescriptionProject{
  3305. ID: p.ID,
  3306. ProjectId: p.ProjectId,
  3307. Price: p.Price,
  3308. UserOrgId: p.UserOrgId,
  3309. Status: 1,
  3310. Ctime: time.Now().Unix(),
  3311. Mtime: time.Now().Unix(),
  3312. PatientId: p.PatientId,
  3313. HisPatientId: p.HisPatientId,
  3314. RecordDate: p.RecordDate,
  3315. PrescriptionId: p.PrescriptionId,
  3316. Count: p.Count,
  3317. FeedetlSn: p.FeedetlSn,
  3318. MedListCodg: p.MedListCodg,
  3319. SingleDose: p.SingleDose,
  3320. DeliveryWay: p.DeliveryWay,
  3321. ExecutionFrequency: p.ExecutionFrequency,
  3322. Day: p.Day,
  3323. HisProject: models.HisProject{},
  3324. GoodInfo: models.GoodInfo{},
  3325. Remark: p.Remark,
  3326. Unit: p.Unit,
  3327. Type: p.Type,
  3328. Doctor: p.Doctor,
  3329. ExecutionTime: p.ExecutionTime,
  3330. ExecutionStaff: p.ExecutionStaff,
  3331. ExecutionState: p.ExecutionState,
  3332. CheckTime: p.CheckTime,
  3333. CheckState: p.CheckState,
  3334. Checker: p.Checker,
  3335. StartTime: p.StartTime,
  3336. TeamId: p.TeamId,
  3337. XtHisProjectTeam: models.XtHisProjectTeam{},
  3338. FrequencyType: p.FrequencyType,
  3339. DayCount: p.DayCount,
  3340. WeekDay: p.WeekDay,
  3341. IsCheckTeam: p.IsCheckTeam,
  3342. HisOrderInfo: models.HisOrderInfo{},
  3343. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3344. IsOut: p.IsOut,
  3345. YbSyncStatus: p.YbSyncStatus,
  3346. }
  3347. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3348. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3349. }
  3350. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3351. ////查询历史出库数据
  3352. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3353. //
  3354. //var out_count_five int64
  3355. //for _, item := range flowGood {
  3356. // out_count_five += item.Count
  3357. //}
  3358. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3359. //
  3360. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3361. //if out_count_five != parseIntCount {
  3362. // //查询耗材最后一次出库记录
  3363. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3364. // //查询默认出库仓库库存
  3365. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3366. // if len(wareOut) > 0 {
  3367. //
  3368. // for _, it := range wareOut {
  3369. // //回退库存
  3370. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3371. //
  3372. // //删除出库记录
  3373. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3374. //
  3375. // }
  3376. // }
  3377. //
  3378. // timeStr := time.Now().Format("2006-01-02")
  3379. // timeArr := strings.Split(timeStr, "-")
  3380. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3381. //
  3382. // total = total + 1
  3383. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3384. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3385. // number = number + total
  3386. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3387. //
  3388. // operation_time := time.Now().Unix()
  3389. // creater := c.GetAdminUserInfo().AdminUser.Id
  3390. //
  3391. // recordDateStr := time.Now().Format("2006-01-02")
  3392. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3393. // nowtime := recordDate.Unix()
  3394. // warehouseOut := models.WarehouseOut{
  3395. // WarehouseOutOrderNumber: warehousing_out_order,
  3396. // OperationTime: operation_time,
  3397. // OrgId: adminInfo.CurrentOrgId,
  3398. // Creater: creater,
  3399. // Ctime: time.Now().Unix(),
  3400. // Status: 1,
  3401. // WarehouseOutTime: nowtime,
  3402. // Type: 1,
  3403. // StorehouseId: storeConfig.StorehouseOutInfo,
  3404. // IsCheck: 1,
  3405. // IsSys: 1,
  3406. // }
  3407. // //查询是否生成出库单
  3408. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3409. // if out.ID == 0 {
  3410. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3411. // }
  3412. //
  3413. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3414. //
  3415. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3416. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3417. //
  3418. // dialyPrepareOne := models.DialysisBeforePrepare{
  3419. // GoodTypeId: goodObj.GoodTypeId,
  3420. // GoodId: p.ProjectId,
  3421. // PatientId: p.PatientId,
  3422. // RecordDate: p.RecordDate,
  3423. // UserOrgId: adminInfo.CurrentOrgId,
  3424. // Count: parseIntCount,
  3425. // Ctime: time.Now().Unix(),
  3426. // Creater: creater,
  3427. // Status: 1,
  3428. // StorehouseId: houseConfig.StorehouseOutInfo,
  3429. // ProjectId: lastHisProject.ID,
  3430. // }
  3431. // //判断是否是零用耗材(非零用)
  3432. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3433. //
  3434. // //查询历史出库数据
  3435. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3436. // var out_count int64
  3437. // for _, item := range flowGood {
  3438. // out_count += item.Count
  3439. // }
  3440. // //如果历史数和当前数据不想等才进行退库出库
  3441. // if out_count != parseIntCount {
  3442. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3443. //
  3444. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3445. // detail := models.AutomaticReduceDetail{
  3446. // WarehouseOutId: 0,
  3447. // WarehouseOutOrderNumber: "",
  3448. // PatientId: p.PatientId,
  3449. // Ctime: time.Now().Unix(),
  3450. // Mtime: 0,
  3451. // Status: 1,
  3452. // RecordTime: p.RecordDate,
  3453. // OrgId: p.UserOrgId,
  3454. // GoodId: p.ProjectId,
  3455. // GoodTypeId: 0,
  3456. // Count: parseIntCount,
  3457. // Type: 0,
  3458. // ProjectId: lastHisProject.ID,
  3459. // StorehouseId: 0,
  3460. // }
  3461. //
  3462. // service.CreateNewAutoDetail(detail, tx)
  3463. //
  3464. // //查询剩余库存
  3465. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3466. // var sum_count int64
  3467. // for _, item := range goodList {
  3468. // sum_count += item.StockCount
  3469. // }
  3470. //
  3471. // //更新剩余库存
  3472. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3473. //
  3474. // //耗材
  3475. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3476. //
  3477. // }
  3478. // //判断是否是零用耗材(零用但是是出库耗材)
  3479. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3480. //
  3481. // //查询历史出库数据
  3482. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3483. // var out_count int64
  3484. // for _, item := range flowGood {
  3485. // out_count += item.Count
  3486. // }
  3487. // //如果历史数和当前数据不想等才进行退库出库
  3488. // if out_count != parseIntCount {
  3489. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3490. //
  3491. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3492. // detail := models.AutomaticReduceDetail{
  3493. // WarehouseOutId: 0,
  3494. // WarehouseOutOrderNumber: "",
  3495. // PatientId: p.PatientId,
  3496. // Ctime: time.Now().Unix(),
  3497. // Mtime: 0,
  3498. // Status: 1,
  3499. // RecordTime: p.RecordDate,
  3500. // OrgId: p.UserOrgId,
  3501. // GoodId: p.ProjectId,
  3502. // GoodTypeId: 0,
  3503. // Count: parseIntCount,
  3504. // Type: 0,
  3505. // ProjectId: p.ID,
  3506. // StorehouseId: 0,
  3507. // }
  3508. //
  3509. // service.CreateNewAutoDetail(detail, tx)
  3510. //
  3511. // //查询剩余库存
  3512. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3513. // var sum_count int64
  3514. // for _, item := range goodList {
  3515. // sum_count += item.StockCount
  3516. // }
  3517. //
  3518. // //更新剩余库存
  3519. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3520. //
  3521. // //耗材
  3522. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3523. // }
  3524. //
  3525. // }
  3526. //
  3527. // }
  3528. //
  3529. //}
  3530. //记录日志
  3531. byterequest, _ := json.Marshal(p)
  3532. adviceLog := models.XtDoctorAdviceLog{
  3533. UserOrgId: p.UserOrgId,
  3534. PatientId: p.PatientId,
  3535. AdminUserId: adminInfo.AdminUser.Id,
  3536. Module: 1,
  3537. ErrLog: string(byterequest),
  3538. Status: 1,
  3539. Ctime: time.Now().Unix(),
  3540. Mtime: 0,
  3541. Source: "电脑端新建his项目",
  3542. RecordDate: p.RecordDate,
  3543. }
  3544. service.CreateDoctorAdviceLog(adviceLog)
  3545. projectList = append(projectList, p)
  3546. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3547. //新增或者编辑项目,修改对应的标签数据
  3548. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3549. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3550. var label models.HisLabelPrintInfo
  3551. project, _ := service.GetProjectDetail(p.ProjectId)
  3552. if project.CostClassify == 3 { //类别为检验检查
  3553. if p.TeamId > 0 { //检验检查组套
  3554. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3555. if tempLabel.ID == 0 {
  3556. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3557. label.Number = tempPrescription.PrescriptionNumber
  3558. label.ProjectId = project.ID
  3559. label.Status = 1
  3560. label.IsPrint = 2
  3561. label.DoctorId = info.DoctorId
  3562. label.UserOrgId = p.UserOrgId
  3563. label.PatientId = patient_id
  3564. label.RecordDate = recordDateTime
  3565. label.Ctime = time.Now().Unix()
  3566. label.Mtime = time.Now().Unix()
  3567. label.ItemId = p.TeamId
  3568. label.FeedetlSn = p.FeedetlSn
  3569. label.PProjectId = p.ID
  3570. label.ProjectName = team.ProjectTeam
  3571. label.PatientName = patient.Name
  3572. service.CreateNewHisLabelRecord(&label, tx)
  3573. }
  3574. } else { //单条检验检查项目
  3575. label.Number = tempPrescription.PrescriptionNumber
  3576. label.ProjectId = project.ID
  3577. label.Status = 1
  3578. label.DoctorId = info.DoctorId
  3579. label.UserOrgId = p.UserOrgId
  3580. label.PatientId = patient_id
  3581. label.RecordDate = recordDateTime
  3582. label.IsPrint = 2
  3583. label.Ctime = time.Now().Unix()
  3584. label.Mtime = time.Now().Unix()
  3585. label.FeedetlSn = p.FeedetlSn
  3586. label.PProjectId = p.ID
  3587. label.ItemId = p.TeamId
  3588. label.ProjectName = project.ProjectName
  3589. label.PatientName = patient.Name
  3590. service.CreateNewHisLabelRecord(&label, tx)
  3591. }
  3592. }
  3593. }
  3594. }
  3595. }
  3596. }
  3597. }
  3598. service.CreateNewHisProjectTwo(&p, tx)
  3599. var randNum int
  3600. randNum = rand.Intn(10000) + 1000
  3601. timestamp := time.Now().Unix()
  3602. tempTime := time.Unix(timestamp, 0)
  3603. timeFormat := tempTime.Format("20060102150405")
  3604. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3605. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3606. if goodBase.ID > 0 {
  3607. tx.Rollback()
  3608. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3609. return
  3610. }
  3611. service.CreateNewHisProjectTwo(&p, tx)
  3612. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3613. //查询剩余库存
  3614. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3615. var sum_count int64
  3616. for _, item := range goodList {
  3617. sum_count += item.StockCount
  3618. }
  3619. //更新剩余库存
  3620. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3621. //耗材
  3622. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3623. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3624. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3625. if len(outInfoTwo) > 0 {
  3626. for _, item := range outInfoTwo {
  3627. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3628. }
  3629. }
  3630. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3631. if len(drugAutoDetail) > 0 {
  3632. for _, item := range drugAutoDetail {
  3633. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3634. }
  3635. }
  3636. tx.Commit()
  3637. }
  3638. }
  3639. }
  3640. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3641. // addition := items["addition"].([]interface{})
  3642. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3643. // ctime := time.Now().Unix()
  3644. // mtime := ctime
  3645. // if len(addition) > 0 {
  3646. // for _, item := range addition {
  3647. // var s models.HisAdditionalCharge
  3648. // s.PrescriptionId = tempPrescription.ID
  3649. // s.Status = 1
  3650. // s.UserOrgId = adminInfo.CurrentOrgId
  3651. // s.RecordDate = recordDateTime
  3652. // s.CreatedTime = ctime
  3653. // s.UpdatedTime = mtime
  3654. // s.PatientId = patient_id
  3655. // s.HisPatientId = his_patient_id
  3656. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3657. // if errcode > 0 {
  3658. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3659. // return
  3660. // }
  3661. // service.CreateAdditionalCharge(&s)
  3662. // var randNum int
  3663. // randNum = rand.Intn(10000) + 1000
  3664. // timestamp := time.Now().Unix()
  3665. // tempTime := time.Unix(timestamp, 0)
  3666. // timeFormat := tempTime.Format("20060102150405")
  3667. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3668. // service.CreateAdditionalCharge(&s)
  3669. //
  3670. // }
  3671. // }
  3672. //}
  3673. }
  3674. }
  3675. }
  3676. tx.Commit()
  3677. if err == nil {
  3678. c.ServeSuccessJSON(map[string]interface{}{
  3679. "msg": "保存成功",
  3680. })
  3681. return
  3682. } else {
  3683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3684. return
  3685. }
  3686. } else {
  3687. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3688. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3689. var tempPrescription *models.HisPrescription
  3690. if len(prescriptions) > 0 {
  3691. for _, item := range prescriptions {
  3692. items := item.(map[string]interface{})
  3693. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3694. utils.ErrorLog("id")
  3695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3696. return
  3697. }
  3698. id := int64(items["id"].(float64))
  3699. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3700. tempPrescription = &new_prescription
  3701. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3702. utils.ErrorLog("type")
  3703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3704. return
  3705. }
  3706. types := int64(items["type"].(float64))
  3707. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3708. utils.ErrorLog("med_type")
  3709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3710. return
  3711. }
  3712. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3713. if med_type == "0" {
  3714. med_type = "14"
  3715. }
  3716. //if order_status == 0 {
  3717. // order_status = 1
  3718. //}
  3719. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3720. utils.ErrorLog("pre_time")
  3721. }
  3722. preTime, _ := items["pre_time"].(string)
  3723. timeLayout := "2006-01-02"
  3724. loc, _ := time.LoadLocation("Local")
  3725. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3726. result := strings.Split(preTime, " ")
  3727. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3728. if err != nil {
  3729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3730. return
  3731. }
  3732. pTime := theTime2.Unix()
  3733. ctime := time.Now().Unix()
  3734. if tempPrescription.ID == 0 {
  3735. prescription := &models.HisPrescription{
  3736. ID: 0,
  3737. PatientId: patient_id,
  3738. UserOrgId: adminInfo.CurrentOrgId,
  3739. RecordDate: recordDateTime,
  3740. Ctime: ctime,
  3741. Mtime: ctime,
  3742. Type: types,
  3743. Modifier: adminInfo.AdminUser.Id,
  3744. Creator: adminInfo.AdminUser.Id,
  3745. Status: 1,
  3746. Doctor: role.UserName,
  3747. HisPatientId: his_patient_id,
  3748. OrderStatus: 1,
  3749. BatchNumber: "",
  3750. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3751. PreTime: pTime,
  3752. PType: p_type,
  3753. MedType: med_type,
  3754. }
  3755. tempPrescription = prescription
  3756. service.SaveHisPrescription(tempPrescription)
  3757. redis := service.RedisClient()
  3758. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3759. redis.Set(key, "", time.Second)
  3760. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3761. redis.Set(keyOne, "", time.Second)
  3762. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3763. redis.Set(keySeven, "", time.Second)
  3764. defer redis.Close()
  3765. } else {
  3766. tempPrescription.ID = id
  3767. tempPrescription.Type = types
  3768. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3769. tempPrescription.Mtime = time.Now().Unix()
  3770. tempPrescription.Doctor = role.UserName
  3771. //tempPrescription.OrderStatus = order_status
  3772. tempPrescription.PreTime = pTime
  3773. tempPrescription.MedType = med_type
  3774. service.SaveHisPrescription(tempPrescription)
  3775. redis := service.RedisClient()
  3776. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3777. redis.Set(key, "", time.Second)
  3778. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3779. redis.Set(keyOne, "", time.Second)
  3780. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3781. redis.Set(keySeven, "", time.Second)
  3782. defer redis.Close()
  3783. }
  3784. //service.SaveHisPrescription(prescription)
  3785. //更改患者挂号状态
  3786. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3787. fmt.Println("更改失败", err2)
  3788. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3789. advices := items["advices"].([]interface{})
  3790. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3791. groupNo := int64(0)
  3792. if len(advices) > 0 {
  3793. for _, advice := range advices {
  3794. var s models.HisDoctorAdviceInfo
  3795. s.PrescriptionId = tempPrescription.ID
  3796. s.AdviceType = 2
  3797. s.AdviceDoctor = doctor_id
  3798. s.StopState = 2
  3799. s.ExecutionState = 2
  3800. s.AdviceDate = theTime3.Unix()
  3801. s.Status = 1
  3802. s.UserOrgId = adminInfo.CurrentOrgId
  3803. s.RecordDate = theTime3.Unix()
  3804. s.StartTime = tempPrescription.PreTime
  3805. s.Groupno = groupNo
  3806. s.PatientId = patient_id
  3807. s.HisPatientId = his_patient_id
  3808. s.StartTime = pTime
  3809. s.IsSettle = 2
  3810. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3811. if errcode > 0 {
  3812. c.ServeFailJSONWithSGJErrorCode(errcode)
  3813. return
  3814. }
  3815. s.StartTime = pTime
  3816. var total_count int64 //处方总库存
  3817. //查询改药品信息
  3818. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3819. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3820. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3821. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3822. total_count += prescribingNumberSeven * medical.MinNumber
  3823. }
  3824. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3825. total_count += prescribingNumberSeven
  3826. }
  3827. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3828. total_count += prescribingNumberSeven
  3829. }
  3830. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3831. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3832. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3833. if s.Price != lastWarehouse.RetailPrice {
  3834. s.Price = lastWarehouse.RetailPrice
  3835. }
  3836. if s.Price == 0 {
  3837. s.Price = lastWarehouse.RetailPrice
  3838. }
  3839. }
  3840. service.CreateHisDoctorAdvice(&s)
  3841. //记录日志
  3842. byterequest, _ := json.Marshal(s)
  3843. adviceLog := models.XtDoctorAdviceLog{
  3844. UserOrgId: s.UserOrgId,
  3845. PatientId: s.PatientId,
  3846. AdminUserId: adminInfo.AdminUser.Id,
  3847. Module: 1,
  3848. ErrLog: string(byterequest),
  3849. Status: 1,
  3850. Ctime: time.Now().Unix(),
  3851. Mtime: 0,
  3852. Source: "电脑端新建his医嘱",
  3853. RecordDate: s.AdviceDate,
  3854. }
  3855. service.CreateDoctorAdviceLog(adviceLog)
  3856. //存储切片中
  3857. adviceList = append(adviceList, s)
  3858. redis := service.RedisClient()
  3859. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3860. redis.Set(key, "", time.Second)
  3861. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3862. redis.Set(keyOne, "", time.Second)
  3863. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3864. redis.Set(keySeven, "", time.Second)
  3865. var randNum int
  3866. randNum = rand.Intn(10000) + 1000
  3867. timestamp := time.Now().Unix()
  3868. tempTime := time.Unix(timestamp, 0)
  3869. timeFormat := tempTime.Format("20060102150405")
  3870. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3871. service.CreateHisDoctorAdvice(&s)
  3872. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3873. redis.Set(keySix, "", time.Second)
  3874. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3875. redis.Set(keyFive, "", time.Second)
  3876. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3877. redis.Set(keyEight, "", time.Second)
  3878. defer redis.Close()
  3879. }
  3880. }
  3881. }
  3882. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3883. projects := items["project"].([]interface{})
  3884. if len(projects) > 0 {
  3885. for _, project := range projects {
  3886. var p models.HisPrescriptionProject
  3887. p.PrescriptionId = tempPrescription.ID
  3888. p.PatientId = patient_id
  3889. p.RecordDate = theTime3.Unix()
  3890. p.Doctor = doctor_id
  3891. p.UserOrgId = adminInfo.CurrentOrgId
  3892. p.HisPatientId = his_patient_id
  3893. p.Status = 1
  3894. p.StartTime = pTime
  3895. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3896. if errcode > 0 {
  3897. c.ServeFailJSONWithSGJErrorCode(errcode)
  3898. return
  3899. }
  3900. if p.ID == 0 {
  3901. p.IsOut = 2
  3902. }
  3903. if p.ID > 0 {
  3904. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3905. p.IsOut = projectDetail.IsOut
  3906. }
  3907. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3908. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3909. if p.Type == 3 {
  3910. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3911. if p.Price != lastWarehouse.PackingPrice {
  3912. p.Price = lastWarehouse.PackingPrice
  3913. }
  3914. if p.Unit == "" {
  3915. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3916. p.Unit = goodInfoOne.PackingUnit
  3917. }
  3918. }
  3919. }
  3920. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3921. //
  3922. // if p.Type == 3 {
  3923. // //查询该耗材是否停用
  3924. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3925. // //表示该耗材已经停用,不能保存
  3926. // if goodInfoSeven.ID == 0 {
  3927. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3928. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3929. // return
  3930. // }
  3931. // }
  3932. //
  3933. //}
  3934. service.CreateHisProjectTwo(&p)
  3935. //记录日志
  3936. byterequest, _ := json.Marshal(p)
  3937. adviceLog := models.XtDoctorAdviceLog{
  3938. UserOrgId: p.UserOrgId,
  3939. PatientId: p.PatientId,
  3940. AdminUserId: adminInfo.AdminUser.Id,
  3941. Module: 1,
  3942. ErrLog: string(byterequest),
  3943. Status: 1,
  3944. Ctime: time.Now().Unix(),
  3945. Mtime: 0,
  3946. Source: "电脑端新建his项目",
  3947. RecordDate: p.RecordDate,
  3948. }
  3949. service.CreateDoctorAdviceLog(adviceLog)
  3950. projectList = append(projectList, p)
  3951. var randNum int
  3952. randNum = rand.Intn(10000) + 1000
  3953. timestamp := time.Now().Unix()
  3954. tempTime := time.Unix(timestamp, 0)
  3955. timeFormat := tempTime.Format("20060102150405")
  3956. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3957. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3958. //新增或者编辑项目,修改对应的标签数据
  3959. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3960. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3961. var label models.HisLabelPrintInfo
  3962. project, _ := service.GetProjectDetail(p.ProjectId)
  3963. if project.CostClassify == 3 { //类别为检验检查
  3964. if p.TeamId > 0 { //检验检查组套
  3965. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3966. if tempLabel.ID == 0 {
  3967. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3968. label.Number = tempPrescription.PrescriptionNumber
  3969. label.ProjectId = project.ID
  3970. label.Status = 1
  3971. label.IsPrint = 2
  3972. label.DoctorId = info.DoctorId
  3973. label.UserOrgId = p.UserOrgId
  3974. label.PatientId = patient_id
  3975. label.RecordDate = recordDateTime
  3976. label.Ctime = time.Now().Unix()
  3977. label.Mtime = time.Now().Unix()
  3978. label.ItemId = p.TeamId
  3979. label.FeedetlSn = p.FeedetlSn
  3980. label.PProjectId = p.ID
  3981. label.ProjectName = team.ProjectTeam
  3982. label.PatientName = patient.Name
  3983. service.CreateHisLabelRecord(&label)
  3984. }
  3985. } else { //单条检验检查项目
  3986. label.Number = tempPrescription.PrescriptionNumber
  3987. label.ProjectId = project.ID
  3988. label.Status = 1
  3989. label.DoctorId = info.DoctorId
  3990. label.UserOrgId = p.UserOrgId
  3991. label.PatientId = patient_id
  3992. label.RecordDate = recordDateTime
  3993. label.IsPrint = 2
  3994. label.Ctime = time.Now().Unix()
  3995. label.Mtime = time.Now().Unix()
  3996. label.FeedetlSn = p.FeedetlSn
  3997. label.PProjectId = p.ID
  3998. label.ItemId = p.TeamId
  3999. label.ProjectName = project.ProjectName
  4000. label.PatientName = patient.Name
  4001. service.CreateHisLabelRecord(&label)
  4002. }
  4003. }
  4004. }
  4005. }
  4006. service.SaveHisProjectTwo(&p)
  4007. }
  4008. }
  4009. }
  4010. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4011. // addition := items["addition"].([]interface{})
  4012. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4013. // ctime := time.Now().Unix()
  4014. // mtime := ctime
  4015. // if len(addition) > 0 {
  4016. // for _, item := range addition {
  4017. // var s models.HisAdditionalCharge
  4018. // s.PrescriptionId = tempPrescription.ID
  4019. // s.Status = 1
  4020. // s.UserOrgId = adminInfo.CurrentOrgId
  4021. // s.RecordDate = recordDateTime
  4022. // s.CreatedTime = ctime
  4023. // s.UpdatedTime = mtime
  4024. // s.PatientId = patient_id
  4025. // s.HisPatientId = his_patient_id
  4026. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4027. // if errcode > 0 {
  4028. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4029. // return
  4030. // }
  4031. // service.CreateAdditionalCharge(&s)
  4032. // var randNum int
  4033. // randNum = rand.Intn(10000) + 1000
  4034. // timestamp := time.Now().Unix()
  4035. // tempTime := time.Unix(timestamp, 0)
  4036. // timeFormat := tempTime.Format("20060102150405")
  4037. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4038. // service.CreateAdditionalCharge(&s)
  4039. //
  4040. // }
  4041. // }
  4042. //}
  4043. }
  4044. }
  4045. //查询今日该患者开的药品处方
  4046. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4047. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4048. //药品出库
  4049. if drugOutConfig.IsOpen == 1 {
  4050. for _, item := range hisdoctorlist {
  4051. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4052. // 查询该药品最后一次出库记录
  4053. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4054. if len(druginfo) > 0 {
  4055. //回退库存
  4056. for _, it := range druginfo {
  4057. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4058. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4059. }
  4060. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4061. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4062. }
  4063. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4064. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4065. }
  4066. }
  4067. }
  4068. //删除记录
  4069. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4070. //查询最后一次数据
  4071. if drugOutConfig.IsOpen == 1 {
  4072. //出库
  4073. if drug.IsUse == 2 {
  4074. creater := adminInfo.AdminUser.Id
  4075. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4076. }
  4077. //更新字典里面的库存
  4078. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4079. var sum_count int64
  4080. for _, its := range stockInfo {
  4081. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4082. if its.MaxUnit == baseDrug.MaxUnit {
  4083. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4084. }
  4085. sum_count += its.StockMaxNumber + its.StockMinNumber
  4086. }
  4087. //更新基础库存
  4088. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4089. //剩余库存
  4090. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4091. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4092. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4093. }
  4094. }
  4095. }
  4096. //耗材保存处方出库
  4097. if goodOutConfig.IsOpen == 1 {
  4098. //查询今日耗材出库数量
  4099. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4100. for _, item := range hisgoodlist {
  4101. //查询历史出库数据
  4102. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4103. var out_count_five int64
  4104. for _, item := range flowGood {
  4105. out_count_five += item.Count
  4106. }
  4107. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4108. if out_count_five != parseIntCount {
  4109. //查询耗材最后一次出库记录
  4110. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4111. //查询默认出库仓库库存
  4112. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4113. if len(wareOut) > 0 {
  4114. for _, it := range wareOut {
  4115. //回退库存
  4116. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4117. //删除出库记录
  4118. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4119. }
  4120. }
  4121. timeStr := time.Now().Format("2006-01-02")
  4122. timeArr := strings.Split(timeStr, "-")
  4123. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4124. total = total + 1
  4125. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4126. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4127. number = number + total
  4128. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4129. operation_time := time.Now().Unix()
  4130. creater := c.GetAdminUserInfo().AdminUser.Id
  4131. recordDateStr := time.Now().Format("2006-01-02")
  4132. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4133. nowtime := recordDate.Unix()
  4134. warehouseOut := models.WarehouseOut{
  4135. WarehouseOutOrderNumber: warehousing_out_order,
  4136. OperationTime: operation_time,
  4137. OrgId: adminInfo.CurrentOrgId,
  4138. Creater: creater,
  4139. Ctime: time.Now().Unix(),
  4140. Status: 1,
  4141. WarehouseOutTime: nowtime,
  4142. Type: 1,
  4143. StorehouseId: storeConfig.StorehouseOutInfo,
  4144. IsCheck: 1,
  4145. IsSys: 1,
  4146. }
  4147. //查询是否生成出库单
  4148. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4149. if out.ID == 0 {
  4150. service.AddSigleWarehouseOut(&warehouseOut)
  4151. }
  4152. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4153. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4154. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4155. dialyPrepareOne := models.DialysisBeforePrepare{
  4156. GoodTypeId: goodObj.GoodTypeId,
  4157. GoodId: item.ProjectId,
  4158. PatientId: item.PatientId,
  4159. RecordDate: item.RecordDate,
  4160. UserOrgId: adminInfo.CurrentOrgId,
  4161. Count: parseIntCount,
  4162. Ctime: time.Now().Unix(),
  4163. Creater: creater,
  4164. Status: 1,
  4165. StorehouseId: houseConfig.StorehouseOutInfo,
  4166. ProjectId: item.ID,
  4167. }
  4168. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4169. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4170. //查询历史出库数据
  4171. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4172. var out_count int64
  4173. for _, item := range flowGood {
  4174. out_count += item.Count
  4175. }
  4176. //如果历史数和当前数据不想等才进行退库出库
  4177. if out_count != parseIntCount {
  4178. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4179. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4180. detail := models.AutomaticReduceDetail{
  4181. WarehouseOutId: 0,
  4182. WarehouseOutOrderNumber: "",
  4183. PatientId: item.PatientId,
  4184. Ctime: time.Now().Unix(),
  4185. Mtime: 0,
  4186. Status: 1,
  4187. RecordTime: item.RecordDate,
  4188. OrgId: item.UserOrgId,
  4189. GoodId: item.ProjectId,
  4190. GoodTypeId: 0,
  4191. Count: parseIntCount,
  4192. Type: 0,
  4193. ProjectId: item.ID,
  4194. StorehouseId: 0,
  4195. }
  4196. service.CreateAutoDetail(detail)
  4197. //查询剩余库存
  4198. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4199. var sum_count int64
  4200. for _, item := range goodList {
  4201. sum_count += item.StockCount
  4202. }
  4203. //更新剩余库存
  4204. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4205. //耗材
  4206. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4207. }
  4208. }
  4209. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4210. //查询历史出库数据
  4211. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4212. var out_count int64
  4213. for _, item := range flowGood {
  4214. out_count += item.Count
  4215. }
  4216. //如果历史数和当前数据不想等才进行退库出库
  4217. if out_count != parseIntCount {
  4218. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4219. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4220. detail := models.AutomaticReduceDetail{
  4221. WarehouseOutId: 0,
  4222. WarehouseOutOrderNumber: "",
  4223. PatientId: item.PatientId,
  4224. Ctime: time.Now().Unix(),
  4225. Mtime: 0,
  4226. Status: 1,
  4227. RecordTime: item.RecordDate,
  4228. OrgId: item.UserOrgId,
  4229. GoodId: item.ProjectId,
  4230. GoodTypeId: 0,
  4231. Count: parseIntCount,
  4232. Type: 0,
  4233. ProjectId: item.ID,
  4234. StorehouseId: 0,
  4235. }
  4236. service.CreateAutoDetail(detail)
  4237. //查询剩余库存
  4238. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4239. var sum_count int64
  4240. for _, item := range goodList {
  4241. sum_count += item.StockCount
  4242. }
  4243. //更新剩余库存
  4244. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4245. //耗材
  4246. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4247. }
  4248. }
  4249. }
  4250. }
  4251. }
  4252. }
  4253. tx.Commit()
  4254. if err == nil {
  4255. c.ServeSuccessJSON(map[string]interface{}{
  4256. "msg": "保存成功",
  4257. })
  4258. return
  4259. } else {
  4260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4261. return
  4262. }
  4263. }
  4264. }
  4265. //func (c *HisApiController) EditHisPrescription() {
  4266. // record_date := c.GetString("record_date")
  4267. // patient_id, _ := c.GetInt64("patient_id")
  4268. // reg_type, _ := c.GetInt64("reg_type")
  4269. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4270. // diagnose := c.GetString("diagnose")
  4271. // sick_type, _ := c.GetInt64("sick_type")
  4272. // sick_history := c.GetString("sick_history")
  4273. // doctor_id, _ := c.GetInt64("doctor", 0)
  4274. // department, _ := c.GetInt64("department", 0)
  4275. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4276. // p_type, _ := c.GetInt64("p_type")
  4277. //
  4278. // dataBody := make(map[string]interface{}, 0)
  4279. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4280. // if err != nil {
  4281. // utils.ErrorLog(err.Error())
  4282. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4283. // return
  4284. // }
  4285. //
  4286. // timeLayout := "2006-01-02"
  4287. // loc, _ := time.LoadLocation("Local")
  4288. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4289. // if err != nil {
  4290. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4291. // return
  4292. // }
  4293. // adminInfo := c.GetAdminUserInfo()
  4294. // recordDateTime := theTime.Unix()
  4295. //
  4296. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4297. //
  4298. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4299. // var hpInfo models.HisPrescriptionInfo
  4300. // if info.ID == 0 {
  4301. // var randNum int
  4302. // randNum = rand.Intn(10000) + 1000
  4303. // timestamp := time.Now().Unix()
  4304. // tempTime := time.Unix(timestamp, 0)
  4305. // timeFormat := tempTime.Format("20060102150405")
  4306. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4307. //
  4308. // hpInfo = models.HisPrescriptionInfo{
  4309. // UserOrgId: adminInfo.CurrentOrgId,
  4310. // RecordDate: theTime.Unix(),
  4311. // PatientId: patient_id,
  4312. // Status: 1,
  4313. // Ctime: time.Now().Unix(),
  4314. // Mtime: time.Now().Unix(),
  4315. // Creator: adminInfo.AdminUser.Id,
  4316. // Modifier: adminInfo.AdminUser.Id,
  4317. // Diagnosis: diagnose,
  4318. // SickHistory: sick_history,
  4319. // Departments: department,
  4320. // RegisterType: reg_type,
  4321. // PrescriptionNumber: p_number,
  4322. // PrescriptionStatus: 1,
  4323. // Doctor: role.UserName,
  4324. // DoctorId: doctor_id,
  4325. // SickType: sick_type,
  4326. // PType: p_type,
  4327. // }
  4328. // service.SavePatientPrescriptionInfo(hpInfo)
  4329. //
  4330. // } else {
  4331. // hpInfo = models.HisPrescriptionInfo{
  4332. // ID: info.ID,
  4333. // UserOrgId: adminInfo.CurrentOrgId,
  4334. // RecordDate: info.RecordDate,
  4335. // PatientId: info.PatientId,
  4336. // Status: 1,
  4337. // Ctime: info.Ctime,
  4338. // Mtime: time.Now().Unix(),
  4339. // Creator: info.Creator,
  4340. // Modifier: adminInfo.AdminUser.Id,
  4341. // Diagnosis: diagnose,
  4342. // SickHistory: sick_history,
  4343. // Departments: department,
  4344. // RegisterType: reg_type,
  4345. // PrescriptionNumber: info.PrescriptionNumber,
  4346. // Doctor: role.UserName,
  4347. // PrescriptionStatus: info.PrescriptionStatus,
  4348. // DoctorId: doctor_id,
  4349. // SickType: sick_type,
  4350. // PType: info.PType,
  4351. // }
  4352. // service.SavePatientPrescriptionInfo(hpInfo)
  4353. // }
  4354. //
  4355. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4356. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4357. //
  4358. // if len(prescriptions) > 0 {
  4359. // for _, item := range prescriptions {
  4360. // items := item.(map[string]interface{})
  4361. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4362. // utils.ErrorLog("id")
  4363. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4364. // return
  4365. // }
  4366. // id := int64(items["id"].(float64))
  4367. //
  4368. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4369. // utils.ErrorLog("type")
  4370. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4371. // return
  4372. // }
  4373. // types := int64(items["type"].(float64))
  4374. //
  4375. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4376. // utils.ErrorLog("med_type")
  4377. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4378. // return
  4379. // }
  4380. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4381. //
  4382. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4383. //
  4384. // ctime := time.Now().Unix()
  4385. //
  4386. // prescription := &models.HisPrescription{
  4387. // ID: id,
  4388. // PatientId: patient_id,
  4389. // UserOrgId: adminInfo.CurrentOrgId,
  4390. // RecordDate: recordDateTime,
  4391. // Ctime: ctime,
  4392. // Mtime: ctime,
  4393. // Type: types,
  4394. // Modifier: adminInfo.AdminUser.Id,
  4395. // Creator: adminInfo.AdminUser.Id,
  4396. // Status: 1,
  4397. // Doctor: role.UserName,
  4398. // HisPatientId: his_patient_id,
  4399. // OrderStatus: 1,
  4400. // BatchNumber: "",
  4401. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4402. // PType: hpInfo.PType,
  4403. // MedType: med_type,
  4404. // }
  4405. //
  4406. // if historyPrescription.ID > 0 {
  4407. // prescription.PreTime = historyPrescription.PreTime
  4408. //
  4409. // }
  4410. //
  4411. // service.SaveHisPrescription(prescription)
  4412. //
  4413. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4414. // advices := items["advices"].([]interface{})
  4415. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4416. // groupNo := int64(0)
  4417. // ctime := time.Now().Unix()
  4418. // mtime := ctime
  4419. // if len(advices) > 0 {
  4420. // for _, advice := range advices {
  4421. // var s models.HisDoctorAdviceInfo
  4422. // s.PrescriptionId = prescription.ID
  4423. // s.AdviceType = 2
  4424. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4425. // s.StopState = 2
  4426. // s.ExecutionState = 2
  4427. // s.AdviceDate = recordDateTime
  4428. // s.Status = 1
  4429. // s.UserOrgId = adminInfo.CurrentOrgId
  4430. // s.RecordDate = recordDateTime
  4431. // s.StartTime = prescription.PreTime
  4432. // s.Groupno = groupNo
  4433. // s.CreatedTime = ctime
  4434. // s.UpdatedTime = mtime
  4435. // s.PatientId = patient_id
  4436. // s.HisPatientId = his_patient_id
  4437. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4438. // if errcode > 0 {
  4439. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4440. // return
  4441. // }
  4442. //
  4443. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4444. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4445. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4446. // if s.Price == 0 {
  4447. // s.Price = lastWarehouse.RetailPrice
  4448. // }
  4449. // }
  4450. //
  4451. // service.CreateHisDoctorAdvice(&s)
  4452. // //记录日志
  4453. // byterequest, _ := json.Marshal(s)
  4454. // adviceLog := models.XtDoctorAdviceLog{
  4455. // UserOrgId: s.UserOrgId,
  4456. // PatientId: s.PatientId,
  4457. // AdminUserId: adminInfo.AdminUser.Id,
  4458. // Module: 1,
  4459. // ErrLog: string(byterequest),
  4460. // Status: 1,
  4461. // Ctime: time.Now().Unix(),
  4462. // Mtime: 0,
  4463. // Source: "电脑端his医嘱修改",
  4464. // RecordDate: s.AdviceDate,
  4465. // }
  4466. // service.CreateDoctorAdviceLog(adviceLog)
  4467. // redis := service.RedisClient()
  4468. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4469. // redis.Set(key, "", time.Second)
  4470. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4471. // fmt.Println("keyOne", keyOne)
  4472. // redis.Set(keyOne, "", time.Second)
  4473. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4474. // redis.Set(keySeven, "", time.Second)
  4475. // redis.Close()
  4476. //
  4477. // }
  4478. // }
  4479. // }
  4480. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4481. // projects := items["project"].([]interface{})
  4482. // if len(projects) > 0 {
  4483. // for _, project := range projects {
  4484. // var p models.HisPrescriptionProject
  4485. // p.PrescriptionId = prescription.ID
  4486. // p.Ctime = time.Now().Unix()
  4487. // p.Mtime = time.Now().Unix()
  4488. // p.PatientId = patient_id
  4489. // p.RecordDate = recordDateTime
  4490. // p.UserOrgId = adminInfo.CurrentOrgId
  4491. // p.HisPatientId = his_patient_id
  4492. // p.Status = 1
  4493. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4494. // if errcode > 0 {
  4495. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4496. // return
  4497. // }
  4498. // service.CreateHisProjectTwo(&p)
  4499. //
  4500. // //记录日志
  4501. // byterequest, _ := json.Marshal(p)
  4502. // adviceLog := models.XtDoctorAdviceLog{
  4503. // UserOrgId: p.UserOrgId,
  4504. // PatientId: p.PatientId,
  4505. // AdminUserId: adminInfo.AdminUser.Id,
  4506. // Module: 1,
  4507. // ErrLog: string(byterequest),
  4508. // Status: 1,
  4509. // Ctime: time.Now().Unix(),
  4510. // Mtime: 0,
  4511. // Source: "电脑端his项目修改",
  4512. // RecordDate: p.RecordDate,
  4513. // }
  4514. // service.CreateDoctorAdviceLog(adviceLog)
  4515. // }
  4516. // }
  4517. // }
  4518. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4519. // addition := items["addition"].([]interface{})
  4520. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4521. // ctime := time.Now().Unix()
  4522. // mtime := ctime
  4523. // if len(addition) > 0 {
  4524. // for _, item := range addition {
  4525. // var s models.HisAdditionalCharge
  4526. // s.PrescriptionId = prescription.ID
  4527. // s.Status = 1
  4528. // s.UserOrgId = adminInfo.CurrentOrgId
  4529. // s.RecordDate = recordDateTime
  4530. // s.CreatedTime = ctime
  4531. // s.UpdatedTime = mtime
  4532. // s.PatientId = patient_id
  4533. // s.HisPatientId = his_patient_id
  4534. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4535. // if errcode > 0 {
  4536. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4537. // return
  4538. // }
  4539. // service.CreateAdditionalCharge(&s)
  4540. // }
  4541. // }
  4542. // }
  4543. //
  4544. // }
  4545. // }
  4546. // }
  4547. // if err == nil {
  4548. // c.ServeSuccessJSON(map[string]interface{}{
  4549. // "msg": "保存成功",
  4550. // })
  4551. // return
  4552. //
  4553. // } else {
  4554. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4555. // return
  4556. // }
  4557. //}
  4558. func (c *HisApiController) DeletePrescription() {
  4559. prescription_id, _ := c.GetInt64("id")
  4560. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4561. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4562. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4563. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4564. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4565. //耗材保存处方出库
  4566. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4567. //已收费和已发药限制逻辑
  4568. isCharge := false
  4569. isMedicine := false
  4570. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4571. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4572. for _, item := range new_prescriptions {
  4573. if item.IsMedicine == 1 {
  4574. isMedicine = true
  4575. }
  4576. }
  4577. for _, item := range new_prescriptions {
  4578. if item.OrderStatus == 4 {
  4579. isCharge = true
  4580. }
  4581. }
  4582. if p_err != nil {
  4583. if new_prescription.ID > 0 {
  4584. if new_prescription.OrderStatus == 2 {
  4585. isCharge = true
  4586. }
  4587. }
  4588. }
  4589. for _, item := range advices {
  4590. if item.IsMedicine == 1 {
  4591. isMedicine = true
  4592. }
  4593. }
  4594. if isCharge {
  4595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4596. return
  4597. }
  4598. if isMedicine {
  4599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4600. return
  4601. }
  4602. //已收费和已发药限制逻辑
  4603. if len(projects) > 0 {
  4604. for _, item := range projects {
  4605. service.DeletePrintInfo(item.ID) //删除打印信息
  4606. if goodOutConfig.IsOpen != 1 {
  4607. if stockConfig.IsOpen == 1 {
  4608. if item.Type == 3 && item.IsOut == 1 {
  4609. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4610. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4611. good.Total = good.Total + f_count
  4612. service.UpdateGoodInfo(&good)
  4613. operation_time := time.Now().Unix()
  4614. creater := c.GetAdminUserInfo().AdminUser.Id
  4615. //创建退库单
  4616. timeStr := time.Now().Format("2006-01-02")
  4617. timeArr := strings.Split(timeStr, "-")
  4618. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4619. total = total + 1
  4620. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4621. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4622. cancelStock := models.CancelStock{
  4623. OrderNumber: orderNumber,
  4624. OperaTime: operation_time,
  4625. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4626. Creater: creater,
  4627. Ctime: time.Now().Unix(),
  4628. Status: 1,
  4629. ReturnTime: item.RecordDate,
  4630. Type: 1,
  4631. StorehouseId: houseConfig.StorehouseOutInfo,
  4632. IsCheck: 1,
  4633. }
  4634. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4635. if msgerrkonde == gorm.ErrRecordNotFound {
  4636. service.AddSigleCancelStock(&cancelStock)
  4637. }
  4638. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4639. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4640. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4641. //查询该耗材是否出库
  4642. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4643. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4644. deaerler, _ := service.GetDealerById(info.Dealer)
  4645. var total_count int64
  4646. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4647. total_count += count
  4648. if info.ID > 0 {
  4649. if info.Count >= total_count {
  4650. //回退库存
  4651. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4652. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4653. var flush_count int64
  4654. for _, it := range goodList {
  4655. flush_count += it.StockCount
  4656. }
  4657. cancelStockInfo := models.CancelStockInfo{
  4658. GoodId: item.ProjectId,
  4659. CancelStockId: cancel.ID,
  4660. GoodTypeId: good.GoodTypeId,
  4661. Count: prescribingNumber,
  4662. Price: info.Price,
  4663. Total: 0,
  4664. ProductDate: info.ProductDate,
  4665. ExpiryDate: info.ExpiryDate,
  4666. Ctime: time.Now().Unix(),
  4667. Status: 1,
  4668. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4669. OrderNumber: cancel.OrderNumber,
  4670. Type: 0,
  4671. Dealer: deaerler.DealerName,
  4672. Manufacturer: manufacturer.ManufacturerName,
  4673. Number: info.Number,
  4674. RegisterAccount: "",
  4675. Remark: "",
  4676. WarehouseInfoId: info.WarehouseInfotId,
  4677. PatientId: info.PatientId,
  4678. RecordDate: info.SysRecordTime,
  4679. StorehouseId: houseConfig.StorehouseOutInfo,
  4680. IsCheck: 1,
  4681. }
  4682. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4683. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4684. flow := models.VmStockFlow{
  4685. WarehousingId: info.WarehouseInfotId,
  4686. GoodId: item.ProjectId,
  4687. Number: info.Number,
  4688. LicenseNumber: info.LicenseNumber,
  4689. Count: prescribingNumber,
  4690. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4691. PatientId: item.PatientId,
  4692. SystemTime: info.SysRecordTime,
  4693. ConsumableType: 7,
  4694. IsSys: 0,
  4695. WarehousingOrder: "",
  4696. WarehouseOutId: info.WarehouseOutId,
  4697. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4698. IsEdit: 0,
  4699. CancelStockId: cancel.ID,
  4700. CancelOrderNumber: cancel.OrderNumber,
  4701. Manufacturer: manufacturer.ID,
  4702. Dealer: 0,
  4703. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4704. UpdateCreator: 0,
  4705. Status: 1,
  4706. Ctime: time.Now().Unix(),
  4707. Mtime: 0,
  4708. Price: info.Price,
  4709. WarehousingDetailId: info.WarehouseInfotId,
  4710. WarehouseOutDetailId: info.ID,
  4711. CancelOutDetailId: cancelInfo.ID,
  4712. ProductDate: info.ProductDate,
  4713. ExpireDate: info.ExpiryDate,
  4714. StorehouseId: houseConfig.StorehouseOutInfo,
  4715. OverCount: flush_count,
  4716. OperateTime: time.Now().Unix(),
  4717. }
  4718. service.CreateStockFlowOne(flow)
  4719. //退库数量增加
  4720. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4721. //出库数量减少
  4722. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4723. }
  4724. if info.Count < total_count {
  4725. //回退库存
  4726. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4727. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4728. var flush_count int64
  4729. for _, it := range goodList {
  4730. flush_count += it.StockCount
  4731. }
  4732. cancelStockInfo := models.CancelStockInfo{
  4733. GoodId: item.ProjectId,
  4734. CancelStockId: cancel.ID,
  4735. GoodTypeId: good.GoodTypeId,
  4736. Count: info.Count,
  4737. Price: info.Price,
  4738. Total: 0,
  4739. ProductDate: info.ProductDate,
  4740. ExpiryDate: info.ExpiryDate,
  4741. Ctime: time.Now().Unix(),
  4742. Status: 1,
  4743. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4744. OrderNumber: cancel.OrderNumber,
  4745. Type: 0,
  4746. Dealer: deaerler.DealerName,
  4747. Manufacturer: manufacturer.ManufacturerName,
  4748. Number: info.Number,
  4749. RegisterAccount: "",
  4750. Remark: "",
  4751. WarehouseInfoId: info.WarehouseInfotId,
  4752. PatientId: info.PatientId,
  4753. RecordDate: info.SysRecordTime,
  4754. StorehouseId: houseConfig.StorehouseOutInfo,
  4755. IsCheck: 1,
  4756. }
  4757. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4758. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4759. flow := models.VmStockFlow{
  4760. WarehousingId: info.WarehouseInfotId,
  4761. GoodId: item.ProjectId,
  4762. Number: info.Number,
  4763. LicenseNumber: info.LicenseNumber,
  4764. Count: info.Count,
  4765. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4766. PatientId: item.PatientId,
  4767. SystemTime: info.SysRecordTime,
  4768. ConsumableType: 7,
  4769. IsSys: 0,
  4770. WarehousingOrder: "",
  4771. WarehouseOutId: info.WarehouseOutId,
  4772. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4773. IsEdit: 0,
  4774. CancelStockId: cancel.ID,
  4775. CancelOrderNumber: cancel.OrderNumber,
  4776. Manufacturer: manufacturer.ID,
  4777. Dealer: 0,
  4778. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4779. UpdateCreator: 0,
  4780. Status: 1,
  4781. Ctime: time.Now().Unix(),
  4782. Mtime: 0,
  4783. Price: info.Price,
  4784. WarehousingDetailId: info.WarehouseInfotId,
  4785. WarehouseOutDetailId: info.ID,
  4786. CancelOutDetailId: cancelInfo.ID,
  4787. ProductDate: info.ProductDate,
  4788. ExpireDate: info.ExpiryDate,
  4789. StorehouseId: houseConfig.StorehouseOutInfo,
  4790. OverCount: flush_count,
  4791. OperateTime: time.Now().Unix(),
  4792. }
  4793. service.CreateStockFlowOne(flow)
  4794. //退库数量增加
  4795. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4796. //出库数量减少
  4797. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4798. }
  4799. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4800. var flush_count int64
  4801. for _, it := range goodList {
  4802. flush_count += it.StockCount
  4803. }
  4804. //查询已出库数量
  4805. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4806. if prescribingNumber < dialysisInfo.Count {
  4807. //改变数量
  4808. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4809. }
  4810. if prescribingNumber >= dialysisInfo.Count {
  4811. //删除出库表
  4812. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4813. }
  4814. //更新库存
  4815. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4816. //更新基础库库存
  4817. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4818. }
  4819. }
  4820. }
  4821. }
  4822. //保存耗材出库
  4823. if goodOutConfig.IsOpen == 1 {
  4824. if item.Type == 3 {
  4825. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4826. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4827. good.Total = good.Total + f_count
  4828. service.UpdateGoodInfo(&good)
  4829. operation_time := time.Now().Unix()
  4830. creater := c.GetAdminUserInfo().AdminUser.Id
  4831. //创建退库单
  4832. timeStr := time.Now().Format("2006-01-02")
  4833. timeArr := strings.Split(timeStr, "-")
  4834. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4835. total = total + 1
  4836. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4837. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4838. cancelStock := models.CancelStock{
  4839. OrderNumber: orderNumber,
  4840. OperaTime: operation_time,
  4841. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4842. Creater: creater,
  4843. Ctime: time.Now().Unix(),
  4844. Status: 1,
  4845. ReturnTime: item.RecordDate,
  4846. Type: 1,
  4847. StorehouseId: houseConfig.StorehouseOutInfo,
  4848. IsCheck: 1,
  4849. }
  4850. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4851. if msgerrkonde == gorm.ErrRecordNotFound {
  4852. service.AddSigleCancelStock(&cancelStock)
  4853. }
  4854. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4855. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4856. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4857. //查询该耗材是否出库
  4858. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4859. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4860. deaerler, _ := service.GetDealerById(info.Dealer)
  4861. var total_count int64
  4862. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4863. total_count += count
  4864. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4865. var flush_count int64
  4866. for _, it := range goodList {
  4867. flush_count += it.StockCount
  4868. }
  4869. fmt.Println("历史出库数据", info.Count)
  4870. fmt.Println("出库数量", total_count)
  4871. if info.ID > 0 {
  4872. cancelStockInfo := models.CancelStockInfo{
  4873. GoodId: item.ProjectId,
  4874. CancelStockId: cancel.ID,
  4875. GoodTypeId: good.GoodTypeId,
  4876. Count: prescribingNumber,
  4877. Price: info.Price,
  4878. Total: 0,
  4879. ProductDate: info.ProductDate,
  4880. ExpiryDate: info.ExpiryDate,
  4881. Ctime: time.Now().Unix(),
  4882. Status: 1,
  4883. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4884. OrderNumber: cancel.OrderNumber,
  4885. Type: 0,
  4886. Dealer: deaerler.DealerName,
  4887. Manufacturer: manufacturer.ManufacturerName,
  4888. Number: info.Number,
  4889. RegisterAccount: "",
  4890. Remark: "",
  4891. WarehouseInfoId: info.WarehouseInfotId,
  4892. PatientId: info.PatientId,
  4893. RecordDate: info.SysRecordTime,
  4894. StorehouseId: houseConfig.StorehouseOutInfo,
  4895. IsCheck: 1,
  4896. }
  4897. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4898. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4899. //查询出库数量
  4900. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4901. //出库数据 大于 退库数量
  4902. if len(list) > 0 {
  4903. for _, it := range list {
  4904. //回退库存
  4905. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4906. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4907. var flush_count_one int64
  4908. for _, it := range goodList {
  4909. flush_count_one += it.StockCount
  4910. }
  4911. //查询该批次是否有退库数据
  4912. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4913. creater := c.GetAdminUserInfo().AdminUser.Id
  4914. flow := models.VmStockFlow{
  4915. WarehousingId: it.WarehouseInfotId,
  4916. GoodId: it.GoodId,
  4917. Number: it.Number,
  4918. LicenseNumber: it.LicenseNumber,
  4919. Count: it.Count,
  4920. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4921. PatientId: it.PatientId,
  4922. SystemTime: it.SysRecordTime,
  4923. ConsumableType: 7,
  4924. IsSys: 0,
  4925. WarehousingOrder: "",
  4926. WarehouseOutId: it.WarehouseOutId,
  4927. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4928. IsEdit: 0,
  4929. CancelStockId: cancel.ID,
  4930. CancelOrderNumber: cancel.OrderNumber,
  4931. Manufacturer: manufacturer.ID,
  4932. Dealer: 0,
  4933. Creator: creater,
  4934. UpdateCreator: 0,
  4935. Status: 1,
  4936. Ctime: time.Now().Unix(),
  4937. Mtime: 0,
  4938. Price: it.Price,
  4939. WarehousingDetailId: it.WarehouseInfotId,
  4940. WarehouseOutDetailId: it.ID,
  4941. CancelOutDetailId: cancelInfo.ID,
  4942. ProductDate: it.ProductDate,
  4943. ExpireDate: it.ExpiryDate,
  4944. StorehouseId: houseConfig.StorehouseOutInfo,
  4945. OverCount: flush_count_one,
  4946. }
  4947. service.CreateStockFlowOne(flow)
  4948. //if flow.ID > 0 {
  4949. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4950. //}
  4951. }
  4952. }
  4953. //flow := models.VmStockFlow{
  4954. // WarehousingId: info.WarehouseInfotId,
  4955. // GoodId: item.ProjectId,
  4956. // Number: info.Number,
  4957. // LicenseNumber: info.LicenseNumber,
  4958. // Count: prescribingNumber,
  4959. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4960. // PatientId: item.PatientId,
  4961. // SystemTime: info.SysRecordTime,
  4962. // ConsumableType: 7,
  4963. // IsSys: 0,
  4964. // WarehousingOrder: "",
  4965. // WarehouseOutId: info.WarehouseOutId,
  4966. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4967. // IsEdit: 0,
  4968. // CancelStockId: cancel.ID,
  4969. // CancelOrderNumber: cancel.OrderNumber,
  4970. // Manufacturer: manufacturer.ID,
  4971. // Dealer: 0,
  4972. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4973. // UpdateCreator: 0,
  4974. // Status: 1,
  4975. // Ctime: time.Now().Unix(),
  4976. // Mtime: 0,
  4977. // Price: info.Price,
  4978. // WarehousingDetailId: info.WarehouseInfotId,
  4979. // WarehouseOutDetailId: info.ID,
  4980. // CancelOutDetailId: cancelInfo.ID,
  4981. // ProductDate: info.ProductDate,
  4982. // ExpireDate: info.ExpiryDate,
  4983. // StorehouseId: houseConfig.StorehouseOutInfo,
  4984. // OverCount: flush_count,
  4985. //}
  4986. //service.CreateStockFlowOne(flow)
  4987. //退库数量增加
  4988. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4989. //出库数量减少
  4990. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4991. //查询已出库数量
  4992. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4993. if prescribingNumber < dialysisInfo.Count {
  4994. //改变数量
  4995. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4996. }
  4997. if prescribingNumber >= dialysisInfo.Count {
  4998. //删除出库表
  4999. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5000. }
  5001. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5002. var flush_count_one int64
  5003. for _, it := range goodList {
  5004. flush_count_one += it.StockCount
  5005. }
  5006. //更新库存
  5007. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5008. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5009. //更新基础库库存
  5010. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5011. }
  5012. }
  5013. }
  5014. }
  5015. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5016. fmt.Println(err)
  5017. }
  5018. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5019. fmt.Println(err)
  5020. if len(advices) > 0 {
  5021. for _, item := range advices {
  5022. redis := service.RedisClient()
  5023. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5024. redis.Set(keyFive, "", time.Second)
  5025. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5026. redis.Set(keyOne, "", time.Second)
  5027. redis.Close()
  5028. }
  5029. }
  5030. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5031. if len(advices) > 0 {
  5032. for _, item := range advices {
  5033. creater := c.GetAdminUserInfo().AdminUser.Id
  5034. service.DrugAutoAddCancelInfo(item, creater)
  5035. }
  5036. }
  5037. } else {
  5038. if drugOutConfig.IsOpen == 1 {
  5039. if len(advices) > 0 {
  5040. for _, item := range advices {
  5041. creater := c.GetAdminUserInfo().AdminUser.Id
  5042. service.DrugAutoAddCancelInfo(item, creater)
  5043. }
  5044. }
  5045. } else {
  5046. if len(advices) > 0 {
  5047. for _, item := range advices {
  5048. creater := c.GetAdminUserInfo().AdminUser.Id
  5049. service.DrugAutoAddCancelInfo(item, creater)
  5050. }
  5051. }
  5052. }
  5053. }
  5054. c.ServeSuccessJSON(map[string]interface{}{
  5055. "msg": "删除成功",
  5056. })
  5057. return
  5058. }
  5059. func (c *HisApiController) DeleteDoctorAdvice() {
  5060. id, _ := c.GetInt64("id")
  5061. advice, _ := service.GetHisDoctorAdvicesById(id)
  5062. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5063. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5064. //已收费和已发药的限制逻辑
  5065. isCharge := false
  5066. isMedicine := false
  5067. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5068. //获取今天该患者所有处方,判断是否发药或者收费
  5069. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5070. for _, item := range new_prescriptions {
  5071. if item.IsMedicine == 1 {
  5072. isMedicine = true
  5073. }
  5074. }
  5075. for _, item := range new_prescriptions {
  5076. if item.OrderStatus == 4 {
  5077. isCharge = true
  5078. }
  5079. }
  5080. if isMedicine {
  5081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5082. return
  5083. }
  5084. if isCharge {
  5085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5086. return
  5087. }
  5088. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5089. for _, item := range advices {
  5090. if item.IsMedicine == 1 {
  5091. isMedicine = true
  5092. }
  5093. }
  5094. if isMedicine {
  5095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5096. return
  5097. }
  5098. if new_prescription.ID > 0 {
  5099. if new_prescription.OrderStatus == 2 {
  5100. isCharge = true
  5101. }
  5102. }
  5103. if isCharge {
  5104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5105. return
  5106. }
  5107. //已收费和已发药的限制逻辑
  5108. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5109. redis := service.RedisClient()
  5110. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5111. redis.Set(keyFive, "", time.Second)
  5112. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5113. redis.Set(keyOne, "", time.Second)
  5114. defer redis.Close()
  5115. if err == nil {
  5116. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5117. //查询是否在处方中出库
  5118. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5119. if openConfig.IsOpen != 1 {
  5120. //判断该医嘱是否执行了
  5121. if advice.ExecutionState == 1 {
  5122. creater := c.GetAdminUserInfo().AdminUser.Id
  5123. service.DrugAutoAddCancelInfo(&advice, creater)
  5124. }
  5125. }
  5126. //开启保存处方扣减功能
  5127. if openConfig.IsOpen == 1 {
  5128. creater := c.GetAdminUserInfo().AdminUser.Id
  5129. service.DrugAutoAddCancelInfo(&advice, creater)
  5130. }
  5131. } else {
  5132. if drugOutConfig.IsOpen == 1 {
  5133. //查询是否在处方中出库
  5134. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5135. if openConfig.IsOpen != 1 {
  5136. //判断该医嘱是否执行了
  5137. if advice.ExecutionState == 1 {
  5138. creater := c.GetAdminUserInfo().AdminUser.Id
  5139. service.DrugAutoAddCancelInfo(&advice, creater)
  5140. }
  5141. }
  5142. //开启保存处方扣减功能
  5143. if openConfig.IsOpen == 1 {
  5144. creater := c.GetAdminUserInfo().AdminUser.Id
  5145. service.DrugAutoAddCancelInfo(&advice, creater)
  5146. }
  5147. } else {
  5148. //判断该医嘱是否执行了
  5149. if advice.ExecutionState == 1 {
  5150. creater := c.GetAdminUserInfo().AdminUser.Id
  5151. service.DrugAutoAddCancelInfo(&advice, creater)
  5152. }
  5153. }
  5154. }
  5155. c.ServeSuccessJSON(map[string]interface{}{
  5156. "msg": "删除成功",
  5157. })
  5158. return
  5159. } else {
  5160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5161. return
  5162. }
  5163. }
  5164. func (c *HisApiController) DeleteProject() {
  5165. id, _ := c.GetInt64("id")
  5166. adminInfo := c.GetAdminUserInfo()
  5167. project, _ := service.GetHisProjectByID(id)
  5168. // var consumable models.DialysisBeforePrepare
  5169. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5170. //耗材保存处方出库
  5171. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5172. isCharge := false
  5173. isMedicine := false
  5174. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5175. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5176. for _, item := range new_prescriptions {
  5177. if item.IsMedicine == 1 {
  5178. isMedicine = true
  5179. }
  5180. }
  5181. for _, item := range new_prescriptions {
  5182. if item.OrderStatus == 4 {
  5183. isCharge = true
  5184. }
  5185. }
  5186. if isMedicine {
  5187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5188. return
  5189. }
  5190. if isCharge {
  5191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5192. return
  5193. }
  5194. if new_prescription.ID > 0 {
  5195. if new_prescription.OrderStatus == 2 {
  5196. isCharge = true
  5197. }
  5198. }
  5199. if isCharge {
  5200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5201. return
  5202. }
  5203. service.DeletePrintInfo(id)
  5204. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5205. label.Status = 0
  5206. service.CreateHisLabelRecordTwo(&label)
  5207. fmt.Println(goodOutConfig.IsOpen)
  5208. if goodOutConfig.IsOpen != 1 {
  5209. if stockConfig.IsOpen == 1 {
  5210. if project.Type == 2 {
  5211. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5212. fmt.Println(err)
  5213. }
  5214. if project.Type == 3 && project.IsOut == 1 {
  5215. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5216. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5217. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5218. operation_time := time.Now().Unix()
  5219. creater := adminInfo.AdminUser.Id
  5220. //创建退库单
  5221. timeStr := time.Now().Format("2006-01-02")
  5222. timeArr := strings.Split(timeStr, "-")
  5223. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5224. total = total + 1
  5225. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5226. cancelStock := models.CancelStock{
  5227. OrderNumber: orderNumber,
  5228. OperaTime: operation_time,
  5229. OrgId: adminInfo.CurrentOrgId,
  5230. Creater: creater,
  5231. Ctime: time.Now().Unix(),
  5232. Status: 1,
  5233. ReturnTime: project.RecordDate,
  5234. Type: 1,
  5235. StorehouseId: houseConfig.StorehouseOutInfo,
  5236. IsCheck: 1,
  5237. }
  5238. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5239. if msgerrkonde == gorm.ErrRecordNotFound {
  5240. service.AddSigleCancelStock(&cancelStock)
  5241. }
  5242. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5243. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5244. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5245. //查询是否有出库
  5246. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5247. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5248. deaerler, _ := service.GetDealerById(info.Dealer)
  5249. if info.ID > 0 {
  5250. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5251. if info.Count >= prescribingNumber {
  5252. cancelStockInfo := models.CancelStockInfo{
  5253. GoodId: project.ProjectId,
  5254. CancelStockId: cancel.ID,
  5255. GoodTypeId: good.GoodTypeId,
  5256. Count: prescribingNumber,
  5257. Price: info.Price,
  5258. Total: 0,
  5259. ProductDate: info.ProductDate,
  5260. ExpiryDate: info.ExpiryDate,
  5261. Ctime: time.Now().Unix(),
  5262. Status: 1,
  5263. OrgId: adminInfo.CurrentOrgId,
  5264. OrderNumber: cancel.OrderNumber,
  5265. Type: 0,
  5266. Dealer: deaerler.DealerName,
  5267. Manufacturer: manufacturer.ManufacturerName,
  5268. Number: info.Number,
  5269. RegisterAccount: "",
  5270. Remark: "",
  5271. WarehouseInfoId: info.WarehouseInfotId,
  5272. PatientId: info.PatientId,
  5273. RecordDate: info.SysRecordTime,
  5274. StorehouseId: houseConfig.StorehouseOutInfo,
  5275. IsCheck: 1,
  5276. }
  5277. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5278. //回退库存
  5279. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5280. //退库数量增加
  5281. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5282. //出库数量减少
  5283. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5284. }
  5285. if info.Count < prescribingNumber {
  5286. cancelStockInfo := models.CancelStockInfo{
  5287. GoodId: project.ProjectId,
  5288. CancelStockId: cancel.ID,
  5289. GoodTypeId: good.GoodTypeId,
  5290. Count: info.Count,
  5291. Price: info.Price,
  5292. Total: 0,
  5293. ProductDate: info.ProductDate,
  5294. ExpiryDate: info.ExpiryDate,
  5295. Ctime: time.Now().Unix(),
  5296. Status: 1,
  5297. OrgId: adminInfo.CurrentOrgId,
  5298. OrderNumber: cancel.OrderNumber,
  5299. Type: 0,
  5300. Dealer: deaerler.DealerName,
  5301. Manufacturer: manufacturer.ManufacturerName,
  5302. Number: info.Number,
  5303. RegisterAccount: "",
  5304. Remark: "",
  5305. WarehouseInfoId: info.WarehouseInfotId,
  5306. PatientId: info.PatientId,
  5307. RecordDate: info.SysRecordTime,
  5308. StorehouseId: houseConfig.StorehouseOutInfo,
  5309. IsCheck: 1,
  5310. }
  5311. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5312. //回退库存
  5313. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5314. //退库数量增加
  5315. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5316. //出库数量减少
  5317. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5318. }
  5319. //查询剩余库存
  5320. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5321. var over_count int64
  5322. for _, it := range goodList {
  5323. over_count += it.StockCount
  5324. }
  5325. //出库数据 大于 退库数量
  5326. if info.Count >= prescribingNumber {
  5327. flow := models.VmStockFlow{
  5328. WarehousingId: info.WarehouseInfotId,
  5329. GoodId: project.ProjectId,
  5330. Number: info.Number,
  5331. LicenseNumber: info.LicenseNumber,
  5332. Count: prescribingNumber,
  5333. UserOrgId: adminInfo.CurrentOrgId,
  5334. PatientId: project.PatientId,
  5335. SystemTime: info.SysRecordTime,
  5336. ConsumableType: 7,
  5337. IsSys: 0,
  5338. WarehousingOrder: "",
  5339. WarehouseOutId: info.WarehouseOutId,
  5340. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5341. IsEdit: 0,
  5342. CancelStockId: cancel.ID,
  5343. CancelOrderNumber: cancel.OrderNumber,
  5344. Manufacturer: manufacturer.ID,
  5345. Dealer: 0,
  5346. Creator: adminInfo.AdminUser.Id,
  5347. UpdateCreator: 0,
  5348. Status: 1,
  5349. Ctime: time.Now().Unix(),
  5350. Mtime: 0,
  5351. Price: info.Price,
  5352. WarehousingDetailId: info.WarehouseInfotId,
  5353. WarehouseOutDetailId: info.ID,
  5354. CancelOutDetailId: cancelInfo.ID,
  5355. ProductDate: info.ProductDate,
  5356. ExpireDate: info.ExpiryDate,
  5357. StorehouseId: houseConfig.StorehouseOutInfo,
  5358. OverCount: over_count,
  5359. OperateTime: time.Now().Unix(),
  5360. }
  5361. service.CreateStockFlowOne(flow)
  5362. }
  5363. //出库数据小于退库数据
  5364. if info.Count < prescribingNumber {
  5365. flow := models.VmStockFlow{
  5366. WarehousingId: info.WarehouseInfotId,
  5367. GoodId: project.ProjectId,
  5368. Number: info.Number,
  5369. LicenseNumber: info.LicenseNumber,
  5370. Count: info.Count,
  5371. UserOrgId: adminInfo.CurrentOrgId,
  5372. PatientId: project.PatientId,
  5373. SystemTime: info.SysRecordTime,
  5374. ConsumableType: 7,
  5375. IsSys: 0,
  5376. WarehousingOrder: "",
  5377. WarehouseOutId: info.WarehouseOutId,
  5378. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5379. IsEdit: 0,
  5380. CancelStockId: cancel.ID,
  5381. CancelOrderNumber: cancel.OrderNumber,
  5382. Manufacturer: manufacturer.ID,
  5383. Dealer: 0,
  5384. Creator: adminInfo.AdminUser.Id,
  5385. UpdateCreator: 0,
  5386. Status: 1,
  5387. Ctime: time.Now().Unix(),
  5388. Mtime: 0,
  5389. Price: info.Price,
  5390. WarehousingDetailId: info.WarehouseInfotId,
  5391. WarehouseOutDetailId: info.ID,
  5392. CancelOutDetailId: cancelInfo.ID,
  5393. ProductDate: info.ProductDate,
  5394. ExpireDate: info.ExpiryDate,
  5395. StorehouseId: houseConfig.StorehouseOutInfo,
  5396. OverCount: over_count,
  5397. OperateTime: time.Now().Unix(),
  5398. }
  5399. service.CreateStockFlowOne(flow)
  5400. }
  5401. //查询已出库数量
  5402. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5403. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5404. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5405. if prescribingNumber < dialysisInfo.Count {
  5406. //改变数量
  5407. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5408. }
  5409. if prescribingNumber >= dialysisInfo.Count {
  5410. //删除出库表
  5411. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5412. }
  5413. //更新剩余库存
  5414. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5415. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5416. var total_count_one int64
  5417. for _, it := range stockList {
  5418. total_count_one += it.StockCount
  5419. }
  5420. //基础库插入数据
  5421. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5422. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5423. var flush_count int64
  5424. for _, it := range goodListOne {
  5425. flush_count += it.StockCount
  5426. }
  5427. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5428. if errs != nil {
  5429. goodErrcode := models.XtGoodErrcode{
  5430. UserOrgId: project.UserOrgId,
  5431. Errcode: "手动出库更新剩余出库失败",
  5432. GoodId: project.ProjectId,
  5433. Status: 1,
  5434. Ctime: time.Now().Unix(),
  5435. Mtime: 0,
  5436. Count: 0,
  5437. StockCount: 0,
  5438. Creater: creater,
  5439. BatchNumberId: 0,
  5440. WarehouseOutId: 0,
  5441. }
  5442. service.CreateGoodErrcode(goodErrcode)
  5443. }
  5444. }
  5445. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5446. fmt.Println(err)
  5447. } else {
  5448. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5449. fmt.Println(err)
  5450. }
  5451. } else {
  5452. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5453. fmt.Println(err)
  5454. }
  5455. }
  5456. //保存处方出库
  5457. if goodOutConfig.IsOpen == 1 {
  5458. if project.Type == 3 {
  5459. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5460. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5461. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5462. operation_time := time.Now().Unix()
  5463. creater := adminInfo.AdminUser.Id
  5464. //创建退库单
  5465. timeStr := time.Now().Format("2006-01-02")
  5466. timeArr := strings.Split(timeStr, "-")
  5467. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5468. total = total + 1
  5469. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5470. cancelStock := models.CancelStock{
  5471. OrderNumber: orderNumber,
  5472. OperaTime: operation_time,
  5473. OrgId: adminInfo.CurrentOrgId,
  5474. Creater: creater,
  5475. Ctime: time.Now().Unix(),
  5476. Status: 1,
  5477. ReturnTime: project.RecordDate,
  5478. Type: 1,
  5479. StorehouseId: houseConfig.StorehouseOutInfo,
  5480. IsCheck: 1,
  5481. }
  5482. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5483. if msgerrkonde == gorm.ErrRecordNotFound {
  5484. service.AddSigleCancelStock(&cancelStock)
  5485. }
  5486. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5487. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5488. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5489. //获取出库数据
  5490. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5491. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5492. deaerler, _ := service.GetDealerById(info.Dealer)
  5493. if info.ID > 0 {
  5494. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5495. if info.Count >= prescribingNumber {
  5496. cancelStockInfo := models.CancelStockInfo{
  5497. GoodId: project.ProjectId,
  5498. CancelStockId: cancel.ID,
  5499. GoodTypeId: good.GoodTypeId,
  5500. Count: prescribingNumber,
  5501. Price: info.Price,
  5502. Total: 0,
  5503. ProductDate: info.ProductDate,
  5504. ExpiryDate: info.ExpiryDate,
  5505. Ctime: time.Now().Unix(),
  5506. Status: 1,
  5507. OrgId: adminInfo.CurrentOrgId,
  5508. OrderNumber: cancel.OrderNumber,
  5509. Type: 0,
  5510. Dealer: deaerler.DealerName,
  5511. Manufacturer: manufacturer.ManufacturerName,
  5512. Number: info.Number,
  5513. RegisterAccount: "",
  5514. Remark: "",
  5515. WarehouseInfoId: info.WarehouseInfotId,
  5516. PatientId: info.PatientId,
  5517. RecordDate: info.SysRecordTime,
  5518. StorehouseId: houseConfig.StorehouseOutInfo,
  5519. IsCheck: 1,
  5520. }
  5521. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5522. //退库数量增加
  5523. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5524. //出库数量减少
  5525. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5526. }
  5527. if info.Count < prescribingNumber {
  5528. cancelStockInfo := models.CancelStockInfo{
  5529. GoodId: project.ProjectId,
  5530. CancelStockId: cancel.ID,
  5531. GoodTypeId: good.GoodTypeId,
  5532. Count: prescribingNumber,
  5533. Price: info.Price,
  5534. Total: 0,
  5535. ProductDate: info.ProductDate,
  5536. ExpiryDate: info.ExpiryDate,
  5537. Ctime: time.Now().Unix(),
  5538. Status: 1,
  5539. OrgId: adminInfo.CurrentOrgId,
  5540. OrderNumber: cancel.OrderNumber,
  5541. Type: 0,
  5542. Dealer: deaerler.DealerName,
  5543. Manufacturer: manufacturer.ManufacturerName,
  5544. Number: info.Number,
  5545. RegisterAccount: "",
  5546. Remark: "",
  5547. WarehouseInfoId: info.WarehouseInfotId,
  5548. PatientId: info.PatientId,
  5549. RecordDate: info.SysRecordTime,
  5550. StorehouseId: houseConfig.StorehouseOutInfo,
  5551. IsCheck: 1,
  5552. }
  5553. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5554. //回退库存
  5555. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5556. }
  5557. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5558. var over_count int64
  5559. for _, it := range goodList {
  5560. over_count += it.StockCount
  5561. }
  5562. //查询出库数量
  5563. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5564. //出库数据 大于 退库数量
  5565. if len(list) > 0 {
  5566. for _, it := range list {
  5567. //回退库存
  5568. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5569. //退库数量增加
  5570. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5571. //出库数量减少
  5572. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5573. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5574. var over_count_one int64
  5575. for _, it := range goodList {
  5576. over_count_one += it.StockCount
  5577. }
  5578. //查询该批次是否有退库数据
  5579. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5580. flow := models.VmStockFlow{
  5581. WarehousingId: it.WarehouseInfotId,
  5582. GoodId: it.GoodId,
  5583. Number: it.Number,
  5584. LicenseNumber: it.LicenseNumber,
  5585. Count: it.Count,
  5586. UserOrgId: adminInfo.CurrentOrgId,
  5587. PatientId: it.PatientId,
  5588. SystemTime: it.SysRecordTime,
  5589. ConsumableType: 7,
  5590. IsSys: 0,
  5591. WarehousingOrder: "",
  5592. WarehouseOutId: it.WarehouseOutId,
  5593. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5594. IsEdit: 0,
  5595. CancelStockId: cancel.ID,
  5596. CancelOrderNumber: cancel.OrderNumber,
  5597. Manufacturer: manufacturer.ID,
  5598. Dealer: 0,
  5599. Creator: adminInfo.AdminUser.Id,
  5600. UpdateCreator: 0,
  5601. Status: 1,
  5602. Ctime: time.Now().Unix(),
  5603. Mtime: 0,
  5604. Price: it.Price,
  5605. WarehousingDetailId: it.WarehouseInfotId,
  5606. WarehouseOutDetailId: it.ID,
  5607. CancelOutDetailId: cancelInfo.ID,
  5608. ProductDate: it.ProductDate,
  5609. ExpireDate: it.ExpiryDate,
  5610. StorehouseId: houseConfig.StorehouseOutInfo,
  5611. OverCount: over_count_one,
  5612. OperateTime: time.Now().Unix(),
  5613. }
  5614. service.CreateStockFlowOne(flow)
  5615. }
  5616. }
  5617. //查询已出库数量
  5618. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5619. if prescribingNumber < dialysisInfo.Count {
  5620. //改变数量
  5621. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5622. }
  5623. if prescribingNumber >= dialysisInfo.Count {
  5624. //删除出库表
  5625. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5626. }
  5627. //更新剩余库存
  5628. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5629. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5630. var total_count_one int64
  5631. for _, it := range stockList {
  5632. total_count_one += it.StockCount
  5633. }
  5634. //基础库插入数据
  5635. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5636. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5637. var flush_count int64
  5638. for _, it := range goodListOne {
  5639. flush_count += it.StockCount
  5640. }
  5641. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5642. if errs != nil {
  5643. goodErrcode := models.XtGoodErrcode{
  5644. UserOrgId: project.UserOrgId,
  5645. Errcode: "手动出库更新剩余出库失败",
  5646. GoodId: project.ProjectId,
  5647. Status: 1,
  5648. Ctime: time.Now().Unix(),
  5649. Mtime: 0,
  5650. Count: 0,
  5651. StockCount: 0,
  5652. Creater: creater,
  5653. BatchNumberId: 0,
  5654. WarehouseOutId: 0,
  5655. }
  5656. service.CreateGoodErrcode(goodErrcode)
  5657. }
  5658. }
  5659. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5660. fmt.Println(err)
  5661. } else {
  5662. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5663. fmt.Println(err)
  5664. }
  5665. }
  5666. c.ServeSuccessJSON(map[string]interface{}{
  5667. "msg": "删除成功",
  5668. })
  5669. return
  5670. }
  5671. func (c *HisApiController) CreateHisAdditionalCharge() {
  5672. his_patient_id, _ := c.GetInt64("his_patient_id")
  5673. patient_id, _ := c.GetInt64("patient_id")
  5674. record_date := c.GetString("record_date")
  5675. timeLayout := "2006-01-02"
  5676. loc, _ := time.LoadLocation("Local")
  5677. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5678. if err != nil {
  5679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5680. return
  5681. }
  5682. adminInfo := c.GetAdminUserInfo()
  5683. recordDateTime := theTime.Unix()
  5684. dataBody := make(map[string]interface{}, 0)
  5685. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5686. if err != nil {
  5687. utils.ErrorLog(err.Error())
  5688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5689. return
  5690. }
  5691. var additions []*models.HisAdditionalCharge
  5692. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5693. additions, _ := dataBody["addition"].([]interface{})
  5694. if len(additions) > 0 {
  5695. for _, item := range additions {
  5696. items := item.(map[string]interface{})
  5697. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5698. utils.ErrorLog("item_id")
  5699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5700. return
  5701. }
  5702. item_id := int64(items["item_id"].(float64))
  5703. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5704. utils.ErrorLog("item_name")
  5705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5706. return
  5707. }
  5708. item_name := items["item_name"].(string)
  5709. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5710. utils.ErrorLog("price")
  5711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5712. return
  5713. }
  5714. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5715. ctime := time.Now().Unix()
  5716. additional := &models.HisAdditionalCharge{
  5717. PatientId: patient_id,
  5718. HisPatientId: his_patient_id,
  5719. UserOrgId: adminInfo.CurrentOrgId,
  5720. RecordDate: recordDateTime,
  5721. CreatedTime: ctime,
  5722. UpdatedTime: ctime,
  5723. Modifier: adminInfo.AdminUser.Id,
  5724. Creator: adminInfo.AdminUser.Id,
  5725. Price: price,
  5726. ItemName: item_name,
  5727. ItemId: item_id,
  5728. Status: 1,
  5729. }
  5730. additions = append(additions, additional)
  5731. }
  5732. }
  5733. }
  5734. for _, item := range additions {
  5735. service.CreateAddtionalCharge(item)
  5736. }
  5737. c.ServeSuccessJSON(map[string]interface{}{
  5738. "msg": "创建成功",
  5739. })
  5740. }
  5741. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5742. blood_fat := c.GetString("blood_fat")
  5743. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5744. blood_sugar := c.GetString("blood_sugar")
  5745. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5746. chief_conplaint := c.GetString("chief_conplaint")
  5747. dbp := c.GetString("dbp")
  5748. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5749. delivery_way, _ := c.GetInt64("delivery_way")
  5750. diagnostic := c.GetString("diagnostic")
  5751. family_history := c.GetString("family_history")
  5752. height := c.GetString("height")
  5753. history_of_present_illness := c.GetString("history_of_present_illness")
  5754. is_infect, _ := c.GetInt64("is_infect")
  5755. past_history := c.GetString("past_history")
  5756. patient_id, _ := c.GetInt64("patient_id")
  5757. his_patient_id, _ := c.GetInt64("his_patient_id")
  5758. personal_history := c.GetString("personal_history")
  5759. pulse := c.GetString("pulse")
  5760. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5761. sbp := c.GetString("sbp")
  5762. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5763. heightfloat, _ := strconv.ParseFloat(height, 64)
  5764. sicktype := c.GetString("sick_type")
  5765. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5766. symptom := c.GetString("symptom")
  5767. sick_date := c.GetString("sick_date")
  5768. temperatures := c.GetString("temperature")
  5769. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5770. record_date := c.GetString("record_date")
  5771. breathing := c.GetString("breathing")
  5772. doctor_advice := c.GetString("doctor_advice")
  5773. remark := c.GetString("remark")
  5774. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5775. sick, _ := c.GetInt64("sick")
  5776. diagnose, _ := c.GetInt64("diagnose")
  5777. //id, _ := c.GetInt64("id")
  5778. timeLayout := "2006-01-02"
  5779. loc, _ := time.LoadLocation("Local")
  5780. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5781. allergic_history := c.GetString("allergic_history")
  5782. if err != nil {
  5783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5784. return
  5785. }
  5786. recordDateTime := theTime.Unix()
  5787. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5788. if err != nil {
  5789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5790. return
  5791. }
  5792. sickTimes := sickTime.Unix()
  5793. ctime := time.Now().Unix()
  5794. primary_disease := c.GetString("primary_disease")
  5795. confirm_failure_date := c.GetString("confirm_failure_date")
  5796. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5797. drug_allergy_history := c.GetString("drug_allergy_history")
  5798. physical_examination := c.GetString("physical_examination")
  5799. special_inspection := c.GetString("special_inspection")
  5800. lab_apparatus := c.GetString("lab_apparatus")
  5801. caseHistory := models.HisPatientCaseHistory{
  5802. HisPatientId: his_patient_id,
  5803. PatientId: patient_id,
  5804. Temperature: temperature,
  5805. BloodSugar: bloodsugarfloat,
  5806. Pulse: pulsefloat,
  5807. Sbp: sbpfloat,
  5808. Dbp: dbpfloat,
  5809. Height: heightfloat,
  5810. BloodFat: bloodfatfloat,
  5811. SickType: sick_type,
  5812. Symptom: symptom,
  5813. SickDate: sickTimes,
  5814. IsInfect: is_infect,
  5815. HistoryOfPresentIllness: history_of_present_illness,
  5816. PastHistory: past_history,
  5817. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5818. ChiefConplaint: chief_conplaint,
  5819. PersonalHistory: personal_history,
  5820. FamilyHistory: family_history,
  5821. Diagnostic: diagnostic,
  5822. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5823. Status: 1,
  5824. Ctime: ctime,
  5825. Mtime: ctime,
  5826. RecordDate: recordDateTime,
  5827. DeliveryWay: delivery_way,
  5828. Breathing: breathingfloat,
  5829. DoctorAdvice: doctor_advice,
  5830. Remark: remark,
  5831. Sick: sick,
  5832. Diagnose: diagnose,
  5833. AllergicHistory: allergic_history,
  5834. PrimaryDisease: primary_disease,
  5835. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5836. DrugAllergyHistory: drug_allergy_history,
  5837. PhysicalExamination: physical_examination,
  5838. SpecialInspection: special_inspection,
  5839. LabApparatus: lab_apparatus,
  5840. }
  5841. //查询该患者是否有病历
  5842. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5843. if errcodes == gorm.ErrRecordNotFound {
  5844. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5845. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5846. if err != nil {
  5847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5848. return
  5849. }
  5850. c.ServeSuccessJSON(map[string]interface{}{
  5851. "caseHistory": caseHistory,
  5852. "historyInfo": historyInfo,
  5853. })
  5854. return
  5855. } else if errcodes == nil {
  5856. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5857. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5858. if err != nil {
  5859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5860. return
  5861. }
  5862. c.ServeSuccessJSON(map[string]interface{}{
  5863. "caseHistory": caseHistory,
  5864. "historyInfo": historyInfo,
  5865. })
  5866. }
  5867. //查询该患者是否有病历
  5868. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5869. //if errcode == gorm.ErrRecordNotFound {
  5870. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5871. // if err != nil {
  5872. // c.ServeSuccessJSON(map[string]interface{}{
  5873. // "msg": "保存成功",
  5874. // })
  5875. // }
  5876. //} else if errcode == nil {
  5877. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5878. // return
  5879. //}
  5880. }
  5881. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5882. patient_id, _ := c.GetInt64("patient_id", 0)
  5883. adminUser := c.GetAdminUserInfo()
  5884. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5885. c.ServeSuccessJSON(map[string]interface{}{
  5886. "list": caseHistorys,
  5887. })
  5888. }
  5889. func (c *HisApiController) GetHisPatientCaseHistory() {
  5890. record_date, _ := c.GetInt64("record_date", 0)
  5891. patient_id, _ := c.GetInt64("patient_id", 0)
  5892. admin := c.GetAdminUserInfo()
  5893. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5894. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5895. c.ServeSuccessJSON(map[string]interface{}{
  5896. "info": info,
  5897. "case_history": case_history,
  5898. })
  5899. }
  5900. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5901. template_name := c.GetString("template_name")
  5902. template_remark := c.GetString("template_remark")
  5903. doctor := c.GetAdminUserInfo().AdminUser.Id
  5904. diagnostic := c.GetString("diagnostic")
  5905. chief_conplaint := c.GetString("chief_conplain")
  5906. history_of_present_illness := c.GetString("history_of_present_illness")
  5907. past_history := c.GetString("past_history")
  5908. personal_history := c.GetString("personal_history")
  5909. family_history := c.GetString("family_history")
  5910. user_name := c.GetString("user_name")
  5911. doctor_advice := c.GetString("doctor_advice")
  5912. remark := c.GetString("remark")
  5913. //record_date := c.GetString("record_date")
  5914. //fmt.Println("record_date--------",record_date)
  5915. //timeLayout := "2006-01-02"
  5916. //loc, _ := time.LoadLocation("Local")
  5917. //
  5918. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5919. //if err != nil {
  5920. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5921. // return
  5922. //}
  5923. //recordDateTime := theTime.Unix()
  5924. ctime := time.Now().Unix()
  5925. template := models.HisCaseHistoryTemplate{
  5926. HistoryOfPresentIllness: history_of_present_illness,
  5927. PastHistory: past_history,
  5928. ChiefConplaint: chief_conplaint,
  5929. PersonalHistory: personal_history,
  5930. FamilyHistory: family_history,
  5931. Diagnostic: diagnostic,
  5932. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5933. Status: 1,
  5934. Ctime: ctime,
  5935. Mtime: ctime,
  5936. RecordDate: time.Now().Unix(),
  5937. TemplateName: template_name,
  5938. TemplateRemark: template_remark,
  5939. Creator: doctor,
  5940. Modifier: doctor,
  5941. UserName: user_name,
  5942. DoctorAdvice: doctor_advice,
  5943. Remark: remark,
  5944. }
  5945. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5946. if err == nil {
  5947. c.ServeSuccessJSON(map[string]interface{}{
  5948. "msg": "保存成功",
  5949. })
  5950. } else {
  5951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5952. return
  5953. }
  5954. }
  5955. func (c *HisApiController) GetCaseHistoryTemplate() {
  5956. timeLayout := "2006-01-02"
  5957. loc, _ := time.LoadLocation("Local")
  5958. keyword := c.GetString("keyword")
  5959. start_time := c.GetString("start_time")
  5960. end_time := c.GetString("end_time")
  5961. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5962. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5963. admin := c.GetAdminUserInfo()
  5964. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5965. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5966. c.ServeSuccessJSON(map[string]interface{}{
  5967. "template": template,
  5968. //"history": history,
  5969. })
  5970. }
  5971. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5972. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5973. utils.ErrorLog("drug_name")
  5974. return enums.ErrorCodeParamWrong
  5975. }
  5976. adviceName, _ := json["drug_name"].(string)
  5977. if len(adviceName) == 0 {
  5978. utils.ErrorLog("len(advice_name) == 0")
  5979. return enums.ErrorCodeParamWrong
  5980. }
  5981. advice.AdviceName = adviceName
  5982. adviceDesc, _ := json["advice_desc"].(string)
  5983. advice.AdviceDesc = adviceDesc
  5984. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5985. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5986. advice.DrugSpec = drugSpec
  5987. }
  5988. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5989. remark, _ := json["remark"].(string)
  5990. advice.Remark = remark
  5991. }
  5992. if json["id"] == nil {
  5993. advice.DrugId = 0
  5994. } else {
  5995. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5996. drug_id := int64(json["id"].(float64))
  5997. advice.DrugId = drug_id
  5998. }
  5999. }
  6000. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6001. advice_id := int64(json["advice_id"].(float64))
  6002. advice.ID = advice_id
  6003. if advice.ID > 0 {
  6004. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6005. if err == nil {
  6006. if hisAdvice.ID > 0 {
  6007. advice.ExecutionTime = hisAdvice.ExecutionTime
  6008. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6009. advice.ExecutionState = hisAdvice.ExecutionState
  6010. advice.CheckTime = hisAdvice.CheckTime
  6011. advice.Checker = hisAdvice.Checker
  6012. advice.CheckState = hisAdvice.CheckState
  6013. advice.StartTime = hisAdvice.StartTime
  6014. advice.FeedetlSn = hisAdvice.FeedetlSn
  6015. }
  6016. }
  6017. }
  6018. }
  6019. //
  6020. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6021. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6022. // advice.ExecutionTime = execution_time
  6023. //}
  6024. //
  6025. //
  6026. //
  6027. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6028. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6029. // advice.ExecutionStaff = execution_staff
  6030. //}
  6031. //
  6032. //
  6033. //
  6034. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6035. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6036. // advice.ExecutionState = execution_state
  6037. //}
  6038. //
  6039. //
  6040. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6041. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6042. // advice.CheckTime = check_time
  6043. //}
  6044. //
  6045. //
  6046. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6047. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6048. // advice.CheckState = check_state
  6049. //}
  6050. //
  6051. //
  6052. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6053. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6054. // advice.Checker = checker
  6055. //}
  6056. //
  6057. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6058. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6059. // advice.StartTime = start_time
  6060. //}
  6061. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6062. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6063. advice.IsSelfDrug = is_self_drug
  6064. }
  6065. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6066. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6067. drug_way_count, _ := json["drug_way_count"].(string)
  6068. advice.DrugWayCount = drug_way_count
  6069. }
  6070. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6071. drugSpecUnit, _ := json["min_unit"].(string)
  6072. advice.DrugSpecUnit = drugSpecUnit
  6073. }
  6074. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6075. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6076. advice.SingleDose = singleDose
  6077. }
  6078. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6079. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6080. advice.SingleDoseUnit = singleDoseUnit
  6081. }
  6082. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6083. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6084. advice.PrescribingNumber = prescribingNumber
  6085. }
  6086. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6087. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6088. advice.PrescribingNumberUnit = prescribingNumberUnit
  6089. }
  6090. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6091. deliveryWay, _ := json["delivery_way"].(string)
  6092. advice.DeliveryWay = deliveryWay
  6093. }
  6094. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6095. executionFrequency, _ := json["execution_frequency"].(string)
  6096. advice.ExecutionFrequency = executionFrequency
  6097. }
  6098. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6099. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6100. advice.Price = price
  6101. }
  6102. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6103. med_list_codg, _ := json["medical_insurance_number"].(string)
  6104. advice.MedListCodg = med_list_codg
  6105. }
  6106. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6107. day := int64(json["day"].(float64))
  6108. advice.Day = day
  6109. }
  6110. return 0
  6111. }
  6112. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6113. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6114. id := int64(json["id"].(float64))
  6115. project.ID = id
  6116. historyProject, _ := service.GetHisProjectByID(id)
  6117. project.FeedetlSn = historyProject.FeedetlSn
  6118. }
  6119. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6120. project_id := int64(json["project_id"].(float64))
  6121. project.ProjectId = project_id
  6122. }
  6123. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6124. // price := int64(json["price"].(float64))
  6125. // formatInt_price := strconv.FormatInt(price, 10)
  6126. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6127. // project.Price = float_price
  6128. // }
  6129. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6130. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6131. project.Price = price
  6132. }
  6133. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6134. total, _ := json["total"].(string)
  6135. project.Count = total
  6136. }
  6137. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6138. medical_code, _ := json["medical_code"].(string)
  6139. project.MedListCodg = medical_code
  6140. }
  6141. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6142. single_dose, _ := json["single_dose"].(string)
  6143. project.SingleDose = single_dose
  6144. }
  6145. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6146. delivery_way, _ := json["delivery_way"].(string)
  6147. project.DeliveryWay = delivery_way
  6148. }
  6149. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6150. execution_frequency, _ := json["execution_frequency"].(string)
  6151. project.ExecutionFrequency = execution_frequency
  6152. }
  6153. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6154. remark, _ := json["remark"].(string)
  6155. project.Remark = remark
  6156. }
  6157. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6158. day, _ := json["number_days"].(string)
  6159. project.Day = day
  6160. }
  6161. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6162. unit, _ := json["unit"].(string)
  6163. project.Unit = unit
  6164. }
  6165. return 0
  6166. }
  6167. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6168. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6169. id := int64(json["id"].(float64))
  6170. historyAddtions, _ := service.GetHisAdditionByID(id)
  6171. additionalCharge.ID = id
  6172. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6173. }
  6174. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6175. item_id := int64(json["item_id"].(float64))
  6176. additionalCharge.ItemId = item_id
  6177. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6178. if config.ID > 0 {
  6179. if len(config.Code) > 0 {
  6180. additionalCharge.MedListCodg = config.Code
  6181. }
  6182. }
  6183. }
  6184. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6185. // price := int64(json["price"].(float64))
  6186. // formatInt_price := strconv.FormatInt(price, 10)
  6187. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6188. // additionalCharge.Price = float_price
  6189. // }
  6190. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6191. // price := int64(json["price"].(float64))
  6192. // formatInt_price := strconv.FormatInt(price, 10)
  6193. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6194. // additionalCharge.Price = float_price
  6195. //}
  6196. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6197. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6198. additionalCharge.Price = price
  6199. }
  6200. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6201. count, _ := json["count"].(string)
  6202. counts, _ := strconv.ParseInt(count, 10, 64)
  6203. additionalCharge.Count = counts
  6204. }
  6205. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6206. item_name, _ := json["item_name"].(string)
  6207. additionalCharge.ItemName = item_name
  6208. }
  6209. return 0
  6210. }
  6211. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6212. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6213. utils.ErrorLog("drug_name")
  6214. return enums.ErrorCodeParamWrong
  6215. }
  6216. adviceName, _ := json["drug_name"].(string)
  6217. if len(adviceName) == 0 {
  6218. utils.ErrorLog("len(advice_name) == 0")
  6219. return enums.ErrorCodeParamWrong
  6220. }
  6221. advice.AdviceName = adviceName
  6222. adviceDesc, _ := json["advice_desc"].(string)
  6223. advice.AdviceDesc = adviceDesc
  6224. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6225. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6226. advice.DrugSpec = drugSpec
  6227. }
  6228. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6229. remark, _ := json["remark"].(string)
  6230. advice.Remark = remark
  6231. }
  6232. if json["id"] == nil {
  6233. advice.DrugId = 0
  6234. } else {
  6235. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6236. drug_id := int64(json["id"].(float64))
  6237. advice.DrugId = drug_id
  6238. }
  6239. }
  6240. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6241. groupno := int64(json["groupno"].(float64))
  6242. advice.Groupno = groupno
  6243. }
  6244. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6245. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6246. advice.IsSelfDrug = is_self_drug
  6247. }
  6248. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6249. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6250. drug_way_count, _ := json["drug_way_count"].(string)
  6251. advice.DrugWayCount = drug_way_count
  6252. }
  6253. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6254. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6255. advice.HospApprFlag = hosp_appr_flag
  6256. }
  6257. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6258. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6259. advice.PrescribingNumber = prescribingNumber
  6260. }
  6261. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6262. // frequency_type := int64(json["frequency_type"].(float64))
  6263. // advice.FrequencyType = frequency_type
  6264. //}
  6265. //
  6266. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6267. // day_count := int64(json["day_count"].(float64))
  6268. // advice.DayCount = day_count
  6269. //}
  6270. //
  6271. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6272. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6273. // week_day, _ := json["week_day"].(string)
  6274. // advice.WeekDay = week_day
  6275. //}
  6276. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6277. drugSpecUnit, _ := json["min_unit"].(string)
  6278. advice.DrugSpecUnit = drugSpecUnit
  6279. }
  6280. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6281. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6282. advice.SingleDose = singleDose
  6283. }
  6284. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6285. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6286. advice.SingleDoseUnit = singleDoseUnit
  6287. }
  6288. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6289. deliveryWay, _ := json["delivery_way"].(string)
  6290. advice.DeliveryWay = deliveryWay
  6291. }
  6292. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6293. executionFrequency, _ := json["execution_frequency"].(string)
  6294. advice.ExecutionFrequency = executionFrequency
  6295. }
  6296. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6297. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6298. advice.Price = price
  6299. }
  6300. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6301. med_list_codg, _ := json["medical_insurance_number"].(string)
  6302. advice.MedListCodg = med_list_codg
  6303. }
  6304. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6305. day := int64(json["day"].(float64))
  6306. advice.Day = day
  6307. }
  6308. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6309. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6310. advice.PrescribingNumberUnit = prescribingNumberUnit
  6311. }
  6312. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6313. advice_id := int64(json["advice_id"].(float64))
  6314. advice.ID = advice_id
  6315. if advice.ID > 0 {
  6316. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6317. if err == nil {
  6318. if hisAdvice.ID > 0 {
  6319. advice.ExecutionTime = hisAdvice.ExecutionTime
  6320. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6321. advice.ExecutionState = hisAdvice.ExecutionState
  6322. advice.CheckTime = hisAdvice.CheckTime
  6323. advice.Checker = hisAdvice.Checker
  6324. advice.CheckState = hisAdvice.CheckState
  6325. advice.StartTime = hisAdvice.StartTime
  6326. advice.HospApprFlag = hisAdvice.HospApprFlag
  6327. advice.IsMedicine = hisAdvice.IsMedicine
  6328. if hisAdvice.UserOrgId == 10028 {
  6329. 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 {
  6330. advice.ExecutionTime = 0
  6331. advice.ExecutionStaff = 0
  6332. advice.ExecutionState = 2
  6333. advice.CheckTime = 0
  6334. advice.Checker = 0
  6335. advice.CheckState = 2
  6336. }
  6337. } else {
  6338. 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 {
  6339. advice.ExecutionTime = 0
  6340. advice.ExecutionStaff = 0
  6341. advice.ExecutionState = 2
  6342. advice.CheckTime = 0
  6343. advice.Checker = 0
  6344. advice.CheckState = 2
  6345. advice.UpdatedTime = time.Now().Unix()
  6346. }
  6347. }
  6348. //advice.Groupno = hisAdvice.Groupno
  6349. }
  6350. }
  6351. }
  6352. }
  6353. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6354. //
  6355. //if drugStockConfig.IsOpen == 1 {
  6356. //
  6357. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6358. // if advice.ID == 0 { //医嘱不存在
  6359. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6360. // drug.Total = drug.Total - advice.PrescribingNumber
  6361. // service.UpdateBaseDrugLib(&drug)
  6362. //
  6363. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6364. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6365. // drug.Total = drug.Total - num
  6366. // service.UpdateBaseDrugLib(&drug)
  6367. // }
  6368. //
  6369. // } else if advice.ID > 0 { //医嘱存在
  6370. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6371. // var num float64
  6372. //
  6373. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6374. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6375. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6376. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6377. // drug.Total = drug.Total + num
  6378. // service.UpdateBaseDrugLib(&drug)
  6379. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6380. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6381. // drug.Total = drug.Total - num
  6382. // service.UpdateBaseDrugLib(&drug)
  6383. // }
  6384. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6385. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6386. // if num2 > advice.PrescribingNumber {
  6387. // num = num2 - advice.PrescribingNumber
  6388. // drug.Total = drug.Total + num
  6389. // service.UpdateBaseDrugLib(&drug)
  6390. // } else if num2 < advice.PrescribingNumber {
  6391. // num = advice.PrescribingNumber - num2
  6392. // drug.Total = drug.Total - num
  6393. // service.UpdateBaseDrugLib(&drug)
  6394. // }
  6395. //
  6396. // }
  6397. //
  6398. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6399. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6400. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6401. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6402. // if num1 > num2 {
  6403. // num = num1 - num2
  6404. // drug.Total = drug.Total + num
  6405. // service.UpdateBaseDrugLib(&drug)
  6406. // } else if num1 < num2 {
  6407. // num = num2 - num1
  6408. // drug.Total = drug.Total - num
  6409. // service.UpdateBaseDrugLib(&drug)
  6410. // }
  6411. //
  6412. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6413. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6414. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6415. // if hisAdvice.PrescribingNumber > num2 {
  6416. // num = hisAdvice.PrescribingNumber - num2
  6417. // drug.Total = drug.Total + num
  6418. // service.UpdateBaseDrugLib(&drug)
  6419. // } else if num2 < advice.PrescribingNumber {
  6420. // num = num2 - hisAdvice.PrescribingNumber
  6421. // drug.Total = drug.Total - num
  6422. // service.UpdateBaseDrugLib(&drug)
  6423. // }
  6424. //
  6425. // }
  6426. // }
  6427. // }
  6428. //}
  6429. //
  6430. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6431. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6432. // advice.ExecutionTime = execution_time
  6433. //}
  6434. //
  6435. //
  6436. //
  6437. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6438. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6439. // advice.ExecutionStaff = execution_staff
  6440. //}
  6441. //
  6442. //
  6443. //
  6444. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6445. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6446. // advice.ExecutionState = execution_state
  6447. //}
  6448. //
  6449. //
  6450. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6451. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6452. // advice.CheckTime = check_time
  6453. //}
  6454. //
  6455. //
  6456. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6457. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6458. // advice.CheckState = check_state
  6459. //}
  6460. //
  6461. //
  6462. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6463. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6464. // advice.Checker = checker
  6465. //}
  6466. //
  6467. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6468. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6469. // advice.StartTime = start_time
  6470. //}
  6471. return 0
  6472. }
  6473. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6474. project.ExecutionStaff = 0
  6475. project.ExecutionState = 2
  6476. project.ExecutionTime = 0
  6477. project.Checker = 0
  6478. project.CheckState = 2
  6479. project.CheckTime = 0
  6480. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6481. id := int64(json["id"].(float64))
  6482. project.ID = id
  6483. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6484. project.ExecutionStaff = temp_project.ExecutionStaff
  6485. project.ExecutionState = temp_project.ExecutionState
  6486. project.ExecutionTime = temp_project.ExecutionTime
  6487. project.Checker = temp_project.Checker
  6488. project.CheckState = temp_project.CheckState
  6489. project.CheckTime = temp_project.CheckTime
  6490. project.TeamId = temp_project.TeamId
  6491. }
  6492. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6493. types := int64(json["type"].(float64))
  6494. project.Type = types
  6495. }
  6496. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6497. project_id := int64(json["project_id"].(float64))
  6498. project.ProjectId = project_id
  6499. }
  6500. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6501. team_id := int64(json["team_id"].(float64))
  6502. project.TeamId = team_id
  6503. }
  6504. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6505. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6506. project.Price = price
  6507. }
  6508. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6509. total, _ := json["total"].(string)
  6510. //totals, _ := strconv.ParseInt(total, 10, 64)
  6511. project.Count = total
  6512. }
  6513. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6514. medical_code, _ := json["medical_code"].(string)
  6515. project.MedListCodg = medical_code
  6516. }
  6517. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6518. single_dose, _ := json["single_dose"].(string)
  6519. project.SingleDose = single_dose
  6520. }
  6521. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6522. delivery_way, _ := json["delivery_way"].(string)
  6523. project.DeliveryWay = delivery_way
  6524. }
  6525. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6526. execution_frequency, _ := json["execution_frequency"].(string)
  6527. project.ExecutionFrequency = execution_frequency
  6528. }
  6529. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6530. remark, _ := json["remark"].(string)
  6531. project.Remark = remark
  6532. }
  6533. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6534. day, _ := json["number_days"].(string)
  6535. project.Day = day
  6536. }
  6537. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6538. unit, _ := json["unit"].(string)
  6539. project.Unit = unit
  6540. }
  6541. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6542. // frequency_type := int64(json["frequency_type"].(float64))
  6543. // project.FrequencyType = frequency_type
  6544. //}
  6545. //
  6546. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6547. // day_count := int64(json["day_count"].(float64))
  6548. // project.DayCount = day_count
  6549. //}
  6550. //
  6551. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6552. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6553. // week_day, _ := json["week_day"].(string)
  6554. // project.WeekDay = week_day
  6555. //}
  6556. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6557. //
  6558. //if project.ID == 0 {
  6559. // if stockConfig.IsOpen == 1 {
  6560. // if project.Type == 3 {
  6561. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6562. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6563. // good.Total = good.Total - f_count
  6564. // service.UpdateGoodInfo(&good)
  6565. // }
  6566. // }
  6567. //
  6568. //} else {
  6569. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6570. //
  6571. // if stockConfig.IsOpen == 1 {
  6572. // if project.Type == 3 {
  6573. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6574. // if project.Count < temp_project.Count {
  6575. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6576. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6577. //
  6578. // other_count := f_count_two - f_count_one
  6579. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6580. // good.Total = good.Total + other_count_two
  6581. // service.UpdateGoodInfo(&good)
  6582. // } else if project.Count > temp_project.Count {
  6583. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6584. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6585. //
  6586. // other_count := f_count_one - f_count_two
  6587. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6588. // good.Total = good.Total - other_count_two
  6589. // service.UpdateGoodInfo(&good)
  6590. // }
  6591. //
  6592. // }
  6593. // }
  6594. //
  6595. //}
  6596. return 0
  6597. }
  6598. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6599. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6600. utils.ErrorLog("drug_name")
  6601. return enums.ErrorCodeParamWrong
  6602. }
  6603. adviceName, _ := json["drug_name"].(string)
  6604. if len(adviceName) == 0 {
  6605. utils.ErrorLog("len(advice_name) == 0")
  6606. return enums.ErrorCodeParamWrong
  6607. }
  6608. advice.AdviceName = adviceName
  6609. adviceDesc, _ := json["advice_desc"].(string)
  6610. advice.AdviceDesc = adviceDesc
  6611. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6612. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6613. advice.DrugSpec = drugSpec
  6614. }
  6615. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6616. remark, _ := json["remark"].(string)
  6617. advice.Remark = remark
  6618. }
  6619. if json["id"] == nil {
  6620. advice.DrugId = 0
  6621. } else {
  6622. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6623. drug_id := int64(json["id"].(float64))
  6624. advice.DrugId = drug_id
  6625. }
  6626. }
  6627. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6628. groupno := int64(json["groupno"].(float64))
  6629. advice.Groupno = groupno
  6630. }
  6631. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6632. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6633. advice.IsSelfDrug = is_self_drug
  6634. }
  6635. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6636. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6637. drug_way_count, _ := json["drug_way_count"].(string)
  6638. advice.DrugWayCount = drug_way_count
  6639. }
  6640. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6641. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6642. advice.HospApprFlag = hosp_appr_flag
  6643. }
  6644. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6645. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6646. advice.PrescribingNumber = prescribingNumber
  6647. }
  6648. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6649. // frequency_type := int64(json["frequency_type"].(float64))
  6650. // advice.FrequencyType = frequency_type
  6651. //}
  6652. //
  6653. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6654. // day_count := int64(json["day_count"].(float64))
  6655. // advice.DayCount = day_count
  6656. //}
  6657. //
  6658. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6659. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6660. // week_day, _ := json["week_day"].(string)
  6661. // advice.WeekDay = week_day
  6662. //}
  6663. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6664. drugSpecUnit, _ := json["min_unit"].(string)
  6665. advice.DrugSpecUnit = drugSpecUnit
  6666. }
  6667. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6668. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6669. advice.SingleDose = singleDose
  6670. }
  6671. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6672. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6673. advice.SingleDoseUnit = singleDoseUnit
  6674. }
  6675. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6676. deliveryWay, _ := json["delivery_way"].(string)
  6677. advice.DeliveryWay = deliveryWay
  6678. }
  6679. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6680. executionFrequency, _ := json["execution_frequency"].(string)
  6681. advice.ExecutionFrequency = executionFrequency
  6682. }
  6683. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6684. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6685. advice.Price = price
  6686. }
  6687. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6688. med_list_codg, _ := json["medical_insurance_number"].(string)
  6689. advice.MedListCodg = med_list_codg
  6690. }
  6691. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6692. day := int64(json["day"].(float64))
  6693. advice.Day = day
  6694. }
  6695. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6696. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6697. advice.PrescribingNumberUnit = prescribingNumberUnit
  6698. }
  6699. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6700. advice_id := int64(json["advice_id"].(float64))
  6701. advice.ID = advice_id
  6702. if advice.ID > 0 {
  6703. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6704. if err == nil {
  6705. if hisAdvice.ID > 0 {
  6706. advice.ExecutionTime = hisAdvice.ExecutionTime
  6707. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6708. advice.ExecutionState = hisAdvice.ExecutionState
  6709. advice.CheckTime = hisAdvice.CheckTime
  6710. advice.Checker = hisAdvice.Checker
  6711. advice.CheckState = hisAdvice.CheckState
  6712. advice.StartTime = hisAdvice.StartTime
  6713. advice.HospApprFlag = hisAdvice.HospApprFlag
  6714. advice.IsMedicine = hisAdvice.IsMedicine
  6715. if hisAdvice.UserOrgId == 10028 {
  6716. 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 {
  6717. advice.ExecutionTime = 0
  6718. advice.ExecutionStaff = 0
  6719. advice.ExecutionState = 2
  6720. advice.CheckTime = 0
  6721. advice.Checker = 0
  6722. advice.CheckState = 2
  6723. }
  6724. } else {
  6725. if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || hisAdvice.SingleDose != advice.SingleDose || hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  6726. advice.ExecutionTime = 0
  6727. advice.ExecutionStaff = 0
  6728. advice.ExecutionState = 2
  6729. advice.CheckTime = 0
  6730. advice.Checker = 0
  6731. advice.CheckState = 2
  6732. //advice.UpdatedTime = time.Now().Unix()
  6733. advice.CreatedTime = hisAdvice.CreatedTime
  6734. advice.UpdatedTime = time.Now().Unix()
  6735. } else {
  6736. advice.CreatedTime = hisAdvice.CreatedTime
  6737. advice.UpdatedTime = hisAdvice.UpdatedTime
  6738. }
  6739. }
  6740. //advice.Groupno = hisAdvice.Groupno
  6741. } else {
  6742. ctime := time.Now().Unix()
  6743. advice.CreatedTime = ctime
  6744. advice.UpdatedTime = ctime
  6745. }
  6746. }
  6747. } else {
  6748. ctime := time.Now().Unix()
  6749. advice.CreatedTime = ctime
  6750. advice.UpdatedTime = ctime
  6751. }
  6752. }
  6753. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6754. //
  6755. //if drugStockConfig.IsOpen == 1 {
  6756. //
  6757. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6758. // if advice.ID == 0 { //医嘱不存在
  6759. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6760. // drug.Total = drug.Total - advice.PrescribingNumber
  6761. // service.UpdateBaseDrugLib(&drug)
  6762. //
  6763. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6764. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6765. // drug.Total = drug.Total - num
  6766. // service.UpdateBaseDrugLib(&drug)
  6767. // }
  6768. //
  6769. // } else if advice.ID > 0 { //医嘱存在
  6770. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6771. // var num float64
  6772. //
  6773. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6774. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6775. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6776. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6777. // drug.Total = drug.Total + num
  6778. // service.UpdateBaseDrugLib(&drug)
  6779. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6780. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6781. // drug.Total = drug.Total - num
  6782. // service.UpdateBaseDrugLib(&drug)
  6783. // }
  6784. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6785. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6786. // if num2 > advice.PrescribingNumber {
  6787. // num = num2 - advice.PrescribingNumber
  6788. // drug.Total = drug.Total + num
  6789. // service.UpdateBaseDrugLib(&drug)
  6790. // } else if num2 < advice.PrescribingNumber {
  6791. // num = advice.PrescribingNumber - num2
  6792. // drug.Total = drug.Total - num
  6793. // service.UpdateBaseDrugLib(&drug)
  6794. // }
  6795. //
  6796. // }
  6797. //
  6798. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6799. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6800. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6801. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6802. // if num1 > num2 {
  6803. // num = num1 - num2
  6804. // drug.Total = drug.Total + num
  6805. // service.UpdateBaseDrugLib(&drug)
  6806. // } else if num1 < num2 {
  6807. // num = num2 - num1
  6808. // drug.Total = drug.Total - num
  6809. // service.UpdateBaseDrugLib(&drug)
  6810. // }
  6811. //
  6812. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6813. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6814. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6815. // if hisAdvice.PrescribingNumber > num2 {
  6816. // num = hisAdvice.PrescribingNumber - num2
  6817. // drug.Total = drug.Total + num
  6818. // service.UpdateBaseDrugLib(&drug)
  6819. // } else if num2 < advice.PrescribingNumber {
  6820. // num = num2 - hisAdvice.PrescribingNumber
  6821. // drug.Total = drug.Total - num
  6822. // service.UpdateBaseDrugLib(&drug)
  6823. // }
  6824. //
  6825. // }
  6826. // }
  6827. // }
  6828. //}
  6829. //
  6830. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6831. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6832. // advice.ExecutionTime = execution_time
  6833. //}
  6834. //
  6835. //
  6836. //
  6837. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6838. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6839. // advice.ExecutionStaff = execution_staff
  6840. //}
  6841. //
  6842. //
  6843. //
  6844. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6845. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6846. // advice.ExecutionState = execution_state
  6847. //}
  6848. //
  6849. //
  6850. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6851. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6852. // advice.CheckTime = check_time
  6853. //}
  6854. //
  6855. //
  6856. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6857. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6858. // advice.CheckState = check_state
  6859. //}
  6860. //
  6861. //
  6862. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6863. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6864. // advice.Checker = checker
  6865. //}
  6866. //
  6867. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6868. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6869. // advice.StartTime = start_time
  6870. //}
  6871. return 0
  6872. }
  6873. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6874. project.ExecutionStaff = 0
  6875. project.ExecutionState = 2
  6876. project.ExecutionTime = 0
  6877. project.Checker = 0
  6878. project.CheckState = 2
  6879. project.CheckTime = 0
  6880. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6881. id := int64(json["id"].(float64))
  6882. project.ID = id
  6883. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6884. project.ExecutionStaff = temp_project.ExecutionStaff
  6885. project.ExecutionState = temp_project.ExecutionState
  6886. project.ExecutionTime = temp_project.ExecutionTime
  6887. project.Checker = temp_project.Checker
  6888. project.CheckState = temp_project.CheckState
  6889. project.CheckTime = temp_project.CheckTime
  6890. project.TeamId = temp_project.TeamId
  6891. }
  6892. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6893. types := int64(json["type"].(float64))
  6894. project.Type = types
  6895. }
  6896. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6897. project_id := int64(json["project_id"].(float64))
  6898. project.ProjectId = project_id
  6899. }
  6900. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6901. team_id := int64(json["team_id"].(float64))
  6902. project.TeamId = team_id
  6903. }
  6904. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6905. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6906. project.Price = price
  6907. }
  6908. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6909. total, _ := json["total"].(string)
  6910. //totals, _ := strconv.ParseInt(total, 10, 64)
  6911. project.Count = total
  6912. }
  6913. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6914. medical_code, _ := json["medical_code"].(string)
  6915. project.MedListCodg = medical_code
  6916. }
  6917. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6918. single_dose, _ := json["single_dose"].(string)
  6919. project.SingleDose = single_dose
  6920. }
  6921. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6922. delivery_way, _ := json["delivery_way"].(string)
  6923. project.DeliveryWay = delivery_way
  6924. }
  6925. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6926. execution_frequency, _ := json["execution_frequency"].(string)
  6927. project.ExecutionFrequency = execution_frequency
  6928. }
  6929. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6930. remark, _ := json["remark"].(string)
  6931. project.Remark = remark
  6932. }
  6933. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6934. day, _ := json["number_days"].(string)
  6935. project.Day = day
  6936. }
  6937. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6938. unit, _ := json["unit"].(string)
  6939. project.Unit = unit
  6940. }
  6941. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6942. // frequency_type := int64(json["frequency_type"].(float64))
  6943. // project.FrequencyType = frequency_type
  6944. //}
  6945. //
  6946. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6947. // day_count := int64(json["day_count"].(float64))
  6948. // project.DayCount = day_count
  6949. //}
  6950. //
  6951. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6952. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6953. // week_day, _ := json["week_day"].(string)
  6954. // project.WeekDay = week_day
  6955. //}
  6956. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6957. //
  6958. //if project.ID == 0 {
  6959. // if stockConfig.IsOpen == 1 {
  6960. // if project.Type == 3 {
  6961. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6962. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6963. // good.Total = good.Total - f_count
  6964. // service.UpdateGoodInfo(&good)
  6965. // }
  6966. // }
  6967. //
  6968. //} else {
  6969. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6970. //
  6971. // if stockConfig.IsOpen == 1 {
  6972. // if project.Type == 3 {
  6973. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6974. // if project.Count < temp_project.Count {
  6975. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6976. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6977. //
  6978. // other_count := f_count_two - f_count_one
  6979. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6980. // good.Total = good.Total + other_count_two
  6981. // service.UpdateGoodInfo(&good)
  6982. // } else if project.Count > temp_project.Count {
  6983. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6984. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6985. //
  6986. // other_count := f_count_one - f_count_two
  6987. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6988. // good.Total = good.Total - other_count_two
  6989. // service.UpdateGoodInfo(&good)
  6990. // }
  6991. //
  6992. // }
  6993. // }
  6994. //
  6995. //}
  6996. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6997. id := int64(json["id"].(float64))
  6998. if id > 0 {
  6999. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7000. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7001. fmt.Println("666666")
  7002. project.Mtime = time.Now().Unix()
  7003. project.Ctime = temp_project.Ctime
  7004. } else {
  7005. project.Mtime = temp_project.Mtime
  7006. project.Ctime = temp_project.Ctime
  7007. }
  7008. } else {
  7009. ctime := time.Now().Unix()
  7010. project.Mtime = ctime
  7011. project.Ctime = ctime
  7012. }
  7013. }
  7014. return 0
  7015. }
  7016. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7017. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7018. id := int64(json["id"].(float64))
  7019. additionalCharge.ID = id
  7020. }
  7021. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7022. item_id := int64(json["item_id"].(float64))
  7023. additionalCharge.ItemId = item_id
  7024. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7025. if config.ID > 0 {
  7026. if len(config.Code) > 0 {
  7027. additionalCharge.MedListCodg = config.Code
  7028. }
  7029. }
  7030. }
  7031. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7032. // price := int64(json["price"].(float64))
  7033. // formatInt_price := strconv.FormatInt(price, 10)
  7034. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7035. // additionalCharge.Price = float_price
  7036. // }
  7037. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7038. // price := int64(json["price"].(float64))
  7039. // formatInt_price := strconv.FormatInt(price, 10)
  7040. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7041. // additionalCharge.Price = float_price
  7042. //}
  7043. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7044. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7045. additionalCharge.Price = price
  7046. }
  7047. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7048. count, _ := json["count"].(string)
  7049. counts, _ := strconv.ParseInt(count, 10, 64)
  7050. additionalCharge.Count = counts
  7051. }
  7052. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7053. item_name, _ := json["item_name"].(string)
  7054. additionalCharge.ItemName = item_name
  7055. }
  7056. return 0
  7057. }
  7058. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7059. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7060. utils.ErrorLog("drug_name")
  7061. return enums.ErrorCodeParamWrong
  7062. }
  7063. adviceName, _ := json["drug_name"].(string)
  7064. if len(adviceName) == 0 {
  7065. utils.ErrorLog("len(advice_name) == 0")
  7066. return enums.ErrorCodeParamWrong
  7067. }
  7068. advice.AdviceName = adviceName
  7069. adviceDesc, _ := json["advice_desc"].(string)
  7070. advice.AdviceDesc = adviceDesc
  7071. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7072. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7073. advice.DrugSpec = drugSpec
  7074. }
  7075. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7076. remark, _ := json["remark"].(string)
  7077. advice.Remark = remark
  7078. }
  7079. if json["id"] == nil {
  7080. advice.DrugId = 0
  7081. } else {
  7082. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7083. drug_id := int64(json["id"].(float64))
  7084. advice.DrugId = drug_id
  7085. }
  7086. }
  7087. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7088. groupno := int64(json["groupno"].(float64))
  7089. advice.Groupno = groupno
  7090. }
  7091. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7092. drugSpecUnit, _ := json["min_unit"].(string)
  7093. advice.DrugSpecUnit = drugSpecUnit
  7094. }
  7095. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7096. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7097. advice.SingleDose = singleDose
  7098. }
  7099. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7100. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7101. advice.SingleDoseUnit = singleDoseUnit
  7102. }
  7103. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7104. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7105. advice.PrescribingNumber = prescribingNumber
  7106. }
  7107. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7108. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7109. advice.PrescribingNumberUnit = prescribingNumberUnit
  7110. }
  7111. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7112. deliveryWay, _ := json["delivery_way"].(string)
  7113. advice.DeliveryWay = deliveryWay
  7114. }
  7115. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7116. executionFrequency, _ := json["execution_frequency"].(string)
  7117. advice.ExecutionFrequency = executionFrequency
  7118. }
  7119. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7120. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7121. advice.Price = price
  7122. }
  7123. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7124. med_list_codg, _ := json["medical_insurance_number"].(string)
  7125. advice.MedListCodg = med_list_codg
  7126. }
  7127. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7128. day := int64(json["day"].(float64))
  7129. advice.Day = day
  7130. }
  7131. advice.FrequencyType = 1
  7132. return 0
  7133. }
  7134. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7135. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7136. types := int64(json["type"].(float64))
  7137. project.Type = types
  7138. }
  7139. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7140. project_id := int64(json["project_id"].(float64))
  7141. project.ProjectId = project_id
  7142. }
  7143. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7144. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7145. project.Price = price
  7146. }
  7147. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7148. total, _ := json["total"].(string)
  7149. //totals, _ := strconv.ParseInt(total, 10, 64)
  7150. project.Count = total
  7151. }
  7152. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7153. medical_code, _ := json["medical_code"].(string)
  7154. project.MedListCodg = medical_code
  7155. }
  7156. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7157. single_dose, _ := json["single_dose"].(string)
  7158. project.SingleDose = single_dose
  7159. }
  7160. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7161. delivery_way, _ := json["delivery_way"].(string)
  7162. project.DeliveryWay = delivery_way
  7163. }
  7164. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7165. execution_frequency, _ := json["execution_frequency"].(string)
  7166. project.ExecutionFrequency = execution_frequency
  7167. }
  7168. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7169. remark, _ := json["remark"].(string)
  7170. project.Remark = remark
  7171. }
  7172. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7173. day, _ := json["number_days"].(string)
  7174. project.Day = day
  7175. }
  7176. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7177. unit, _ := json["unit"].(string)
  7178. project.Unit = unit
  7179. }
  7180. project.FrequencyType = 1
  7181. return 0
  7182. }
  7183. func (c *HisApiController) GetHisOrderListTwo() {
  7184. start_time := c.GetString("start_time")
  7185. end_time := c.GetString("end_time")
  7186. timeLayout := "2006-01-02"
  7187. loc, _ := time.LoadLocation("Local")
  7188. var startTime int64
  7189. if len(start_time) > 0 {
  7190. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7191. if err != nil {
  7192. //fmt.Println(err)
  7193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7194. return
  7195. }
  7196. startTime = theTime.Unix()
  7197. }
  7198. var endTime int64
  7199. if len(end_time) > 0 {
  7200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7201. if err != nil {
  7202. utils.ErrorLog(err.Error())
  7203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7204. return
  7205. }
  7206. endTime = theTime.Unix()
  7207. }
  7208. adminUser := c.GetAdminUserInfo()
  7209. org_id := adminUser.CurrentOrgId
  7210. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7211. if err == nil {
  7212. c.ServeSuccessJSON(map[string]interface{}{
  7213. "order2": order,
  7214. })
  7215. } else {
  7216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7217. return
  7218. }
  7219. }
  7220. func (c *HisApiController) GetHisOrderList() {
  7221. page, _ := c.GetInt64("page", -1)
  7222. limit, _ := c.GetInt64("limit", -1)
  7223. start_time := c.GetString("start_time")
  7224. end_time := c.GetString("end_time")
  7225. types, _ := c.GetInt64("type", 0)
  7226. keywords := c.GetString("keywords")
  7227. p_type, _ := c.GetInt64("p_type", 0)
  7228. sort_type, _ := c.GetInt64("sort_type", 0)
  7229. charge_type, _ := c.GetInt64("charge_type", 0)
  7230. sch_type, _ := c.GetInt64("sch_type", 0)
  7231. zone_type, _ := c.GetInt64("zone_type", 0)
  7232. med_type, _ := c.GetInt64("med_type", 0)
  7233. timeLayout := "2006-01-02"
  7234. loc, _ := time.LoadLocation("Local")
  7235. var startTime int64
  7236. if len(start_time) > 0 {
  7237. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7238. if err != nil {
  7239. //fmt.Println(err)
  7240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7241. return
  7242. }
  7243. startTime = theTime.Unix()
  7244. }
  7245. var endTime int64
  7246. if len(end_time) > 0 {
  7247. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7248. if err != nil {
  7249. utils.ErrorLog(err.Error())
  7250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7251. return
  7252. }
  7253. endTime = theTime.Unix()
  7254. }
  7255. adminUser := c.GetAdminUserInfo()
  7256. org_id := adminUser.CurrentOrgId
  7257. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  7258. for _, item := range order {
  7259. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7260. item.DoctorName = info.Doctor
  7261. item.DepartmentName = info.XtHisDepartment.Name
  7262. }
  7263. if err == nil {
  7264. c.ServeSuccessJSON(map[string]interface{}{
  7265. "order": order,
  7266. "total": total,
  7267. })
  7268. } else {
  7269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7270. return
  7271. }
  7272. }
  7273. func (c *HisApiController) GetHisOrder() {
  7274. patient_id, _ := c.GetInt64("patient_id", 0)
  7275. number := c.GetString("number")
  7276. adminInfo := c.GetAdminUserInfo()
  7277. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7278. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7279. if err == nil {
  7280. c.ServeSuccessJSON(map[string]interface{}{
  7281. "order": order,
  7282. "prescription": prescriptions,
  7283. })
  7284. } else {
  7285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7286. return
  7287. }
  7288. }
  7289. func (c *HisApiController) GetHisPrescriptionList() {
  7290. record_date := c.GetString("record_date")
  7291. keywords := c.GetString("keywords")
  7292. page, _ := c.GetInt64("page")
  7293. limit, _ := c.GetInt64("limit")
  7294. sch_type, _ := c.GetInt64("sch_type")
  7295. timeLayout := "2006-01-02"
  7296. loc, _ := time.LoadLocation("Local")
  7297. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7298. if err != nil {
  7299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7300. return
  7301. }
  7302. recordDateTime := theTime.Unix()
  7303. adminInfo := c.GetAdminUserInfo()
  7304. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7305. //adminInfo := c.GetAdminUserInfo()
  7306. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7307. //fmt.Println(prescriptionOrder)
  7308. if err == nil {
  7309. c.ServeSuccessJSON(map[string]interface{}{
  7310. "order": prescriptionOrder,
  7311. "total": total,
  7312. })
  7313. } else {
  7314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7315. return
  7316. }
  7317. }
  7318. func (c *HisApiController) GetHisPrescriptionInfo() {
  7319. id, _ := c.GetInt64("id")
  7320. adminInfo := c.GetAdminUserInfo()
  7321. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7322. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7323. if err == nil {
  7324. c.ServeSuccessJSON(map[string]interface{}{
  7325. "order": prescriptionOrder,
  7326. "prescription": prescription,
  7327. })
  7328. } else {
  7329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7330. return
  7331. }
  7332. }
  7333. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7334. adminUser := c.GetAdminUserInfo()
  7335. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7336. c.ServeSuccessJSON(map[string]interface{}{
  7337. "config": config,
  7338. })
  7339. }
  7340. type ResultTwo struct {
  7341. ErrMsg interface{} `json:"err_msg"`
  7342. InfRefmsgid string `json:"inf_refmsgid"`
  7343. Infcode int64 `json:"infcode"`
  7344. Output struct {
  7345. Baseinfo struct {
  7346. Age float64 `json:"age"`
  7347. Brdy string `json:"brdy"`
  7348. Certno string `json:"certno"`
  7349. Gend string `json:"gend"`
  7350. Naty string `json:"naty"`
  7351. PsnCertType string `json:"psn_cert_type"`
  7352. PsnName string `json:"psn_name"`
  7353. PsnNo string `json:"psn_no"`
  7354. } `json:"baseinfo"`
  7355. Idetinfo []interface{} `json:"idetinfo"`
  7356. Iinfo []struct {
  7357. Balc float64 `json:"balc"`
  7358. CvlservFlag string `json:"cvlserv_flag"`
  7359. EmpName string `json:"emp_name"`
  7360. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7361. Insutype string `json:"insutype"`
  7362. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7363. PausInsuDate interface{} `json:"paus_insu_date"`
  7364. PsnInsuDate string `json:"psn_insu_date"`
  7365. PsnInsuStas string `json:"psn_insu_stas"`
  7366. PsnType string `json:"psn_type"`
  7367. } `json:"insuinfo"`
  7368. } `json:"output"`
  7369. RefmsgTime string `json:"refmsg_time"`
  7370. RespondTime string `json:"respond_time"`
  7371. Signtype interface{} `json:"signtype"`
  7372. WarnInfo interface{} `json:"warn_info"`
  7373. }
  7374. type ResultThree struct {
  7375. Cainfo interface{} `json:"cainfo"`
  7376. ErrMsg interface{} `json:"err_msg"`
  7377. InfRefmsgid string `json:"inf_refmsgid"`
  7378. Infcode int64 `json:"infcode"`
  7379. Output struct {
  7380. Data struct {
  7381. IptOtpNo string `json:"ipt_otp_no"`
  7382. MdtrtID string `json:"mdtrt_id"`
  7383. PsnNo string `json:"psn_no"`
  7384. } `json:"data"`
  7385. } `json:"output"`
  7386. RefmsgTime string `json:"refmsg_time"`
  7387. RespondTime string `json:"respond_time"`
  7388. Signtype interface{} `json:"signtype"`
  7389. WarnMsg interface{} `json:"warn_msg"`
  7390. }
  7391. type ResultFour struct {
  7392. Cainfo string `json:"cainfo"`
  7393. ErrMsg string `json:"err_msg"`
  7394. InfRefmsgid string `json:"inf_refmsgid"`
  7395. Infcode int64 `json:"infcode"`
  7396. Output struct {
  7397. Result []struct {
  7398. BasMednFlag string `json:"bas_medn_flag"`
  7399. ChldMedcFlag string `json:"chld_medc_flag"`
  7400. ChrgitmLv string `json:"chrgitm_lv"`
  7401. Cnt float64 `json:"cnt"`
  7402. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7403. DrtReimFlag string `json:"drt_reim_flag"`
  7404. FeedetlSn string `json:"feedetl_sn"`
  7405. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7406. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7407. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7408. ListSpItemFlag string `json:"list_sp_item_flag"`
  7409. LmtUsedFlag string `json:"lmt_used_flag"`
  7410. MedChrgitmType string `json:"med_chrgitm_type"`
  7411. Memo string `json:"memo"`
  7412. OverlmtAmt float64 `json:"overlmt_amt"`
  7413. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7414. Pric float64 `json:"pric"`
  7415. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7416. SelfpayProp float64 `json:"selfpay_prop"`
  7417. } `json:"result"`
  7418. } `json:"output"`
  7419. RefmsgTime string `json:"refmsg_time"`
  7420. RespondTime string `json:"respond_time"`
  7421. Signtype string `json:"signtype"`
  7422. WarnMsg string `json:"warn_msg"`
  7423. }
  7424. type ResultFive struct {
  7425. Insutype string `json:"insutype"`
  7426. }
  7427. type ResultSix struct {
  7428. Cainfo interface{} `json:"cainfo"`
  7429. ErrMsg interface{} `json:"err_msg"`
  7430. InfRefmsgid string `json:"inf_refmsgid"`
  7431. Infcode int64 `json:"infcode"`
  7432. Output struct {
  7433. } `json:"output"`
  7434. RefmsgTime string `json:"refmsg_time"`
  7435. RespondTime string `json:"respond_time"`
  7436. Signtype interface{} `json:"signtype"`
  7437. WarnMsg interface{} `json:"warn_msg"`
  7438. }
  7439. type ResultSeven struct {
  7440. Cainfo string `json:"cainfo"`
  7441. ErrMsg string `json:"err_msg"`
  7442. InfRefmsgid string `json:"inf_refmsgid"`
  7443. Infcode int64 `json:"infcode"`
  7444. Output struct {
  7445. Setldetail []interface{} `json:"setldetail"`
  7446. Setlinfo struct {
  7447. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7448. AcctPay float64 `json:"acct_pay"`
  7449. ActPayDedc float64 `json:"act_pay_dedc"`
  7450. Age float64 `json:"age"`
  7451. Balc float64 `json:"balc"`
  7452. Brdy string `json:"brdy"`
  7453. Certno string `json:"certno"`
  7454. ClrOptins string `json:"clr_optins"`
  7455. ClrType string `json:"clr_type"`
  7456. ClrWay string `json:"clr_way"`
  7457. CvlservFlag string `json:"cvlserv_flag"`
  7458. CvlservPay float64 `json:"cvlserv_pay"`
  7459. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7460. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7461. Gend string `json:"gend"`
  7462. HifesPay float64 `json:"hifes_pay"`
  7463. HifmiPay float64 `json:"hifmi_pay"`
  7464. HifobPay float64 `json:"hifob_pay"`
  7465. HifpPay float64 `json:"hifp_pay"`
  7466. HospPartAmt float64 `json:"hosp_part_amt"`
  7467. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7468. Insutype string `json:"insutype"`
  7469. MafPay float64 `json:"maf_pay"`
  7470. MdtrtCertType string `json:"mdtrt_cert_type"`
  7471. MdtrtID string `json:"mdtrt_id"`
  7472. MedType string `json:"med_type"`
  7473. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7474. MedinsSetlID string `json:"medins_setl_id"`
  7475. Naty string `json:"naty"`
  7476. OthPay float64 `json:"oth_pay"`
  7477. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7478. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7479. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7480. PsnCashPay float64 `json:"psn_cash_pay"`
  7481. PsnCertType string `json:"psn_cert_type"`
  7482. PsnName string `json:"psn_name"`
  7483. PsnNo string `json:"psn_no"`
  7484. PsnPartAmt float64 `json:"psn_part_amt"`
  7485. PsnType string `json:"psn_type"`
  7486. SetlID string `json:"setl_id"`
  7487. SetlTime string `json:"setl_time"`
  7488. } `json:"setlinfo"`
  7489. } `json:"output"`
  7490. RefmsgTime string `json:"refmsg_time"`
  7491. RespondTime string `json:"respond_time"`
  7492. Signtype interface{} `json:"signtype"`
  7493. WarnMsg interface{} `json:"warn_msg"`
  7494. }
  7495. type ResultEight struct {
  7496. Cainfo string `json:"cainfo"`
  7497. ErrMsg string `json:"err_msg"`
  7498. InfRefmsgid string `json:"inf_refmsgid"`
  7499. Infcode int64 `json:"infcode"`
  7500. Output struct {
  7501. Stmtinfo struct {
  7502. SetlOptins string `json:"setl_optins"`
  7503. StmtRslt string `json:"stmt_rslt"`
  7504. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7505. } `json:"stmtinfo"`
  7506. } `json:"output"`
  7507. RefmsgTime string `json:"refmsg_time"`
  7508. RespondTime string `json:"respond_time"`
  7509. Signtype interface{} `json:"signtype"`
  7510. WarnMsg interface{} `json:"warn_msg"`
  7511. }
  7512. type ResultNine struct {
  7513. Cainfo string `json:"cainfo"`
  7514. ErrMsg string `json:"err_msg"`
  7515. InfRefmsgid string `json:"inf_refmsgid"`
  7516. Infcode int64 `json:"infcode"`
  7517. Output struct {
  7518. FileQuryNo string `json:"file_qury_no"`
  7519. } `json:"output"`
  7520. RefmsgTime string `json:"refmsg_time"`
  7521. RespondTime string `json:"respond_time"`
  7522. Signtype interface{} `json:"signtype"`
  7523. WarnMsg interface{} `json:"warn_msg"`
  7524. }
  7525. type ResultTen struct {
  7526. Cainfo string `json:"cainfo"`
  7527. ErrMsg string `json:"err_msg"`
  7528. InfRefmsgid string `json:"inf_refmsgid"`
  7529. Infcode int64 `json:"infcode"`
  7530. Output struct {
  7531. DldEndtime string `json:"dld_endtime"`
  7532. FileQuryNo string `json:"file_qury_no"`
  7533. Filename string `json:"filename"`
  7534. } `json:"output"`
  7535. RefmsgTime string `json:"refmsg_time"`
  7536. RespondTime string `json:"respond_time"`
  7537. Signtype interface{} `json:"signtype"`
  7538. WarnMsg interface{} `json:"warn_msg"`
  7539. }
  7540. type ResultEleven struct {
  7541. Cainfo string `json:"cainfo"`
  7542. ErrMsg string `json:"err_msg"`
  7543. InfRefmsgid string `json:"inf_refmsgid"`
  7544. Infcode int64 `json:"infcode"`
  7545. Output struct {
  7546. Setlinfo struct {
  7547. FixmedinsName string `json:"fixmedins_name"`
  7548. FixmedinsCode string `json:"fixmedins_code"`
  7549. PsnNo string `json:"psn_no"`
  7550. PsnName string `json:"psn_name"`
  7551. HifobPay float64 `json:"hifob_pay"`
  7552. Gend string `json:"gend"`
  7553. Brdy string `json:"brdy"`
  7554. PsnCertType string `json:"psn_cert_type"`
  7555. PsnType string `json:"psn_type"`
  7556. EmpName string `json:"emp_name"`
  7557. Certno string `json:"certno"`
  7558. Insutype string `json:"insutype"`
  7559. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7560. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7561. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7562. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7563. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7564. ActPayDedc float64 `json:"act_pay_dedc"`
  7565. HifpPay float64 `json:"hifp_pay"`
  7566. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7567. CvlservPay float64 `json:"cvlserv_pay"`
  7568. HifesPay float64 `json:"hifes_pay"`
  7569. HifmiPay float64 `json:"hifmi_pay"`
  7570. MafPay float64 `json:"maf_pay"`
  7571. OthPay float64 `json:"oth_pay"`
  7572. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7573. PsnPay float64 `json:"psn_pay"`
  7574. AcctPay float64 `json:"acct_pay"`
  7575. CashPayamt float64 `json:"cash_payamt"`
  7576. Balc float64 `json:"balc"`
  7577. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7578. MedinsSetlId string `json:"medins_setl_id"`
  7579. RefdSetlFlag string `json:"refd_setl_flag"`
  7580. SetlTime string `json:"setl_time"`
  7581. MedType string `json:"med_type"`
  7582. } `json:"setlinfo"`
  7583. } `json:"output"`
  7584. RefmsgTime string `json:"refmsg_time"`
  7585. RespondTime string `json:"respond_time"`
  7586. Signtype interface{} `json:"signtype"`
  7587. WarnMsg interface{} `json:"warn_msg"`
  7588. }
  7589. type Custom struct {
  7590. DetItemFeeSumamt string
  7591. Cut string
  7592. FeedetlSn string
  7593. Price string
  7594. MedListCodg string
  7595. Type int64
  7596. AdviceId int64
  7597. ProjectId int64
  7598. ItemId int64
  7599. }
  7600. // 获取个人信息----挂号-----上传就诊信息
  7601. func (c *HisApiController) GetRegisterInfo() {
  7602. id, _ := c.GetInt64("id")
  7603. record_time := c.GetString("record_time")
  7604. settlementValue, _ := c.GetInt64("settlement_value")
  7605. medical_insurance_card := c.GetString("medical_insurance_card")
  7606. name := c.GetString("name")
  7607. id_card_type, _ := c.GetInt64("id_card_type")
  7608. certificates, _ := c.GetInt64("certificates")
  7609. medical_care, _ := c.GetInt64("medical_care")
  7610. birthday := c.GetString("birthday")
  7611. age, _ := c.GetInt64("age")
  7612. id_card := c.GetString("id_card")
  7613. register_type, _ := c.GetInt64("register")
  7614. doctor, _ := c.GetInt64("doctor")
  7615. department, _ := c.GetInt64("department")
  7616. gender, _ := c.GetInt64("sex")
  7617. phone := c.GetString("phone")
  7618. registration_fee, _ := c.GetFloat("registration_fee")
  7619. medical_expenses, _ := c.GetFloat("medical_expenses")
  7620. social_type, _ := c.GetInt64("social_type")
  7621. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7622. diagnosis_ids := c.GetString("diagnosis")
  7623. sick_type, _ := c.GetInt64("sick_type")
  7624. reg_type := c.GetString("p_type")
  7625. timeLayout := "2006-01-02"
  7626. loc, _ := time.LoadLocation("Local")
  7627. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7628. birthUnix := birthdays.Unix()
  7629. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7630. if err != nil {
  7631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7632. return
  7633. }
  7634. recordDateTime := theTime.Unix()
  7635. adminInfo := c.GetAdminUserInfo()
  7636. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7637. if tempPatient.ID == 0 {
  7638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7639. return
  7640. }
  7641. var patient service.Patients
  7642. if id == 0 {
  7643. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7644. } else {
  7645. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7646. }
  7647. if patient.ID == 0 {
  7648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7649. return
  7650. }
  7651. if len(patient.IdCardNo) == 0 {
  7652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7653. return
  7654. }
  7655. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7656. if len(his) >= 1 {
  7657. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7658. if len(his) >= 1 && order.ID == 0 {
  7659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7660. return
  7661. }
  7662. }
  7663. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7664. fmt.Println(timeStr)
  7665. timeArr := strings.Split(timeStr, " ")
  7666. fmt.Println(timeArr)
  7667. timeArrTwo := strings.Split(timeArr[0], "-")
  7668. timeArrThree := strings.Split(timeArr[1], ":")
  7669. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7670. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7671. if len(lists) == 0 {
  7672. var hisPatient models.XtHisPatient
  7673. hisPatient = models.XtHisPatient{
  7674. Name: name,
  7675. Age: age,
  7676. Gender: gender,
  7677. Birthday: birthUnix,
  7678. Phone: phone,
  7679. MedicalTreatmentType: medical_care,
  7680. IdType: certificates,
  7681. IdCardNo: id_card,
  7682. BalanceAccountsType: settlementValue,
  7683. SocialType: social_type,
  7684. MedicalInsuranceNumber: medical_insurance_card,
  7685. RegisterType: register_type,
  7686. RegisterCost: registration_fee,
  7687. TreatmentCost: medical_expenses,
  7688. AdminUserId: adminInfo.AdminUser.Id,
  7689. UserOrgId: adminInfo.CurrentOrgId,
  7690. Status: 1,
  7691. RecordDate: recordDateTime,
  7692. IsReturn: 1,
  7693. PatientId: patient.ID,
  7694. Ctime: time.Now().Unix(),
  7695. Mtime: time.Now().Unix(),
  7696. Number: str,
  7697. IdCardType: id_card_type,
  7698. Departments: department,
  7699. Doctor: doctor,
  7700. PType: reg_type,
  7701. Diagnosis: diagnosis_ids,
  7702. SickType: sick_type,
  7703. }
  7704. service.CreateHisPatient(&hisPatient)
  7705. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7706. c.ServeSuccessJSON(map[string]interface{}{
  7707. "his_info": hisPatient,
  7708. })
  7709. } else {
  7710. //chrgBchno := rand.Intn(1000000) + 10000
  7711. var hisPatient models.XtHisPatient
  7712. hisPatient = models.XtHisPatient{
  7713. Name: name,
  7714. Age: age,
  7715. Gender: gender,
  7716. Birthday: birthUnix,
  7717. Phone: phone,
  7718. MedicalTreatmentType: medical_care,
  7719. IdType: certificates,
  7720. IdCardNo: id_card,
  7721. BalanceAccountsType: settlementValue,
  7722. SocialType: social_type,
  7723. MedicalInsuranceNumber: medical_insurance_card,
  7724. RegisterType: register_type,
  7725. RegisterCost: registration_fee,
  7726. TreatmentCost: medical_expenses,
  7727. AdminUserId: adminInfo.AdminUser.Id,
  7728. UserOrgId: adminInfo.CurrentOrgId,
  7729. Status: 1,
  7730. RecordDate: recordDateTime,
  7731. IsReturn: 1,
  7732. PatientId: patient.ID,
  7733. Ctime: time.Now().Unix(),
  7734. Mtime: time.Now().Unix(),
  7735. Number: str,
  7736. IdCardType: id_card_type,
  7737. Departments: department,
  7738. Doctor: doctor,
  7739. PType: reg_type,
  7740. Diagnosis: diagnosis_ids,
  7741. SickType: sick_type,
  7742. }
  7743. service.CreateHisPatient(&hisPatient)
  7744. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7745. c.ServeSuccessJSON(map[string]interface{}{
  7746. "his_info": hisPatient,
  7747. })
  7748. }
  7749. }
  7750. // 上传明细----结算
  7751. func (c *HisApiController) GetUploadInfo() {
  7752. id, _ := c.GetInt64("id")
  7753. record_time := c.GetString("record_time")
  7754. his_patient_id, _ := c.GetInt64("his_patient_id")
  7755. oth_desc := c.GetString("oth_desc")
  7756. pay_way, _ := c.GetInt64("pay_way")
  7757. pay_ways := c.GetString("pay_ways")
  7758. pay_price, _ := c.GetFloat("pay_price")
  7759. pay_card_no := c.GetString("pay_card_no")
  7760. discount_price, _ := c.GetFloat("discount_price")
  7761. preferential_price, _ := c.GetFloat("preferential_price")
  7762. reality_price, _ := c.GetFloat("reality_price")
  7763. found_price, _ := c.GetFloat("found_price")
  7764. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7765. private_price, _ := c.GetFloat("private_price")
  7766. timeLayout := "2006-01-02"
  7767. loc, _ := time.LoadLocation("Local")
  7768. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7769. fapiao_code := c.GetString("fapiao_code")
  7770. fapiao_number := c.GetString("fapiao_number")
  7771. diagnosis_id := c.GetString("diagnosis")
  7772. sick_type, _ := c.GetInt64("sick_type")
  7773. reg_type, _ := c.GetInt64("p_type")
  7774. order_id, _ := c.GetInt64("order_id")
  7775. cash_pay := c.GetString("cash_pay")
  7776. wechat_pay := c.GetString("wechat_pay")
  7777. ali_pay := c.GetString("ali_pay")
  7778. jifen_pay := c.GetString("jifen_pay")
  7779. band_card_pay := c.GetString("band_card_pay")
  7780. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7781. tmp_decimal := c.GetString("tmp_decimal")
  7782. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7783. var decimal float64 //本次使用的押金
  7784. var errmsg error
  7785. tx := service.XTWriteDB().Begin() //开了事务
  7786. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7787. defer func() {
  7788. if errmsg != nil {
  7789. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7790. tx.Rollback()
  7791. } else {
  7792. tx.Commit()
  7793. }
  7794. }()
  7795. fmt.Println("dec_way", dec_way)
  7796. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7797. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7798. return
  7799. }
  7800. if len(tmp_decimal) > 0 {
  7801. if tmp_decimal[0] == 45 {
  7802. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7803. return
  7804. }
  7805. }
  7806. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7807. fmt.Println(errs)
  7808. decimal = tt
  7809. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7810. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7811. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7812. if err != nil {
  7813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7814. return
  7815. }
  7816. recordDateTime := theTime.Unix()
  7817. adminUser := c.GetAdminUserInfo()
  7818. var prescriptions []*models.HisPrescription
  7819. var prescriptionsOne []*models.HisPrescription
  7820. var start_time int64
  7821. var end_time int64
  7822. ids_str := c.GetString("ids")
  7823. ids_arr := strings.Split(ids_str, ",")
  7824. if tempOrder.ID == 0 {
  7825. if settle_accounts_type == 1 { //日结
  7826. fmt.Println(reg_type)
  7827. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7828. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7829. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7830. } else {
  7831. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7832. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7833. }
  7834. } else { //月结
  7835. start_time_str := c.GetString("start_time")
  7836. end_time_str := c.GetString("end_time")
  7837. timeLayout := "2006-01-02"
  7838. loc, _ := time.LoadLocation("Local")
  7839. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7840. if err != nil {
  7841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7842. return
  7843. }
  7844. recordStartTime := theStartTime.Unix()
  7845. start_time = recordStartTime
  7846. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7847. if err != nil {
  7848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7849. return
  7850. }
  7851. recordEndTime := theEndTime.Unix()
  7852. end_time = recordEndTime
  7853. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7854. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7855. }
  7856. var goods []*models.DialysisBeforePrepareGoods
  7857. var newGoods []*models.NewDialysisBeforePrepareGoods
  7858. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7859. var infos []*models.HisDoctorAdviceInfo
  7860. var infoList []*models.HisDoctorAdviceInfo
  7861. var hisAdvice []*models.HisDoctorAdviceInfo
  7862. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7863. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7864. //判断库存不足
  7865. //结算出库开关
  7866. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7867. if settConfig.IsOpen == 1 {
  7868. //判断库存的地方
  7869. for _, info := range prescriptions {
  7870. if info.Type == 1 {
  7871. infos = append(infos, info.HisDoctorAdviceInfo...)
  7872. }
  7873. if info.Type == 2 {
  7874. for _, sumItem := range info.HisPrescriptionProject {
  7875. if sumItem.Type == 3 {
  7876. var good models.DialysisBeforePrepareGoods
  7877. var newGood models.NewDialysisBeforePrepareGoods
  7878. good.GoodId = sumItem.GoodInfo.ID
  7879. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7880. count, _ := strconv.Atoi(sumItem.Count)
  7881. good.Count = int64(count)
  7882. good.StorehouseId = houseConfig.StorehouseOutInfo
  7883. good.ProjectId = sumItem.ID
  7884. goods = append(goods, &good)
  7885. newGood.GoodId = sumItem.GoodInfo.ID
  7886. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7887. count2, _ := strconv.Atoi(sumItem.Count)
  7888. newGood.Count = int64(count2)
  7889. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7890. newGood.ProjectId = sumItem.ID
  7891. newGoods = append(newGoods, &newGood)
  7892. }
  7893. }
  7894. }
  7895. }
  7896. for _, info := range prescriptionsOne {
  7897. if info.Type == 1 {
  7898. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7899. }
  7900. if info.Type == 2 {
  7901. for _, sumItem := range info.HisPrescriptionProject {
  7902. if sumItem.Type == 3 {
  7903. var newGood models.NewDialysisBeforePrepareGoods
  7904. newGood.GoodId = sumItem.GoodInfo.ID
  7905. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7906. count2, _ := strconv.Atoi(sumItem.Count)
  7907. newGood.Count = int64(count2)
  7908. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7909. newGood.ProjectId = sumItem.ID
  7910. newGoodOne = append(newGoodOne, &newGood)
  7911. }
  7912. }
  7913. }
  7914. }
  7915. //判断
  7916. for _, itemOne := range infos {
  7917. for _, itemTwo := range hisAdvice {
  7918. if itemOne.DrugId == itemTwo.DrugId {
  7919. itemTwo.Child = append(itemTwo.Child, itemOne)
  7920. }
  7921. }
  7922. }
  7923. for _, itemTwo := range hisAdvice {
  7924. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7925. var sum_out_count int64
  7926. for _, itemThree := range itemTwo.Child {
  7927. var prescribing_number int64
  7928. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7929. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7930. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7931. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7932. }
  7933. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7934. prescribing_number = parseIntPrescribingNumber
  7935. }
  7936. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7937. prescribing_number = parseIntPrescribingNumber
  7938. }
  7939. sum_out_count += prescribing_number
  7940. }
  7941. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7942. if sum_out_count > drugStockOut.FlushCount {
  7943. c.ServeSuccessJSON(map[string]interface{}{
  7944. "msg": "2",
  7945. "drug": medical,
  7946. })
  7947. return
  7948. }
  7949. }
  7950. for _, itemOne := range newGoods {
  7951. for _, item := range newGoodOne {
  7952. if itemOne.GoodId == item.GoodId {
  7953. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7954. }
  7955. }
  7956. }
  7957. for _, item := range newGoodOne {
  7958. var sum_out_count_one int64
  7959. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7960. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7961. sum_out_count_one += itemOne.Count
  7962. }
  7963. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7964. fmt.Println("sum_out_count_one", sum_out_count_one)
  7965. fmt.Println("list.FlushCount", list.FlushCount)
  7966. if sum_out_count_one > list.FlushCount {
  7967. c.ServeSuccessJSON(map[string]interface{}{
  7968. "msg": "3",
  7969. "good": good,
  7970. })
  7971. return
  7972. }
  7973. }
  7974. }
  7975. timestamp := time.Now().Unix()
  7976. tempTime := time.Unix(timestamp, 0)
  7977. timeFormat := tempTime.Format("20060102150405")
  7978. chrgBchno := rand.Intn(100000) + 10000
  7979. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7980. strconv.FormatInt(his.PatientId, 10)
  7981. var ids []int64
  7982. for _, item := range prescriptions {
  7983. ids = append(ids, item.ID)
  7984. }
  7985. var total float64
  7986. for _, item := range prescriptions {
  7987. fmt.Println(item)
  7988. if item.Type == 1 { //药品
  7989. for _, subItem := range item.HisDoctorAdviceInfo {
  7990. total = total + (subItem.Price * subItem.PrescribingNumber)
  7991. }
  7992. }
  7993. if item.Type == 2 { //项目
  7994. for _, subItem := range item.HisPrescriptionProject {
  7995. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7996. total = total + (subItem.Price * cnt)
  7997. }
  7998. }
  7999. for _, subItem := range item.HisAdditionalCharge {
  8000. total = total + (subItem.Price * float64(subItem.Count))
  8001. }
  8002. }
  8003. if reg_type == 1111 || reg_type == 1112 {
  8004. reg_type = 11
  8005. }
  8006. tm := time.Unix(time.Now().Unix(), 0)
  8007. allTotal := fmt.Sprintf("%.4f", total)
  8008. totals, _ := strconv.ParseFloat(allTotal, 64)
  8009. order := &models.HisOrder{
  8010. UserOrgId: adminUser.CurrentOrgId,
  8011. HisPatientId: his.ID,
  8012. PatientId: id,
  8013. SettleAccountsDate: recordDateTime,
  8014. Ctime: time.Now().Unix(),
  8015. Mtime: time.Now().Unix(),
  8016. Status: 1,
  8017. OrderStatus: 2,
  8018. MdtrtId: his.Number,
  8019. Number: chrg_bchno,
  8020. MedfeeSumamt: totals,
  8021. PayWay: pay_way,
  8022. PayWays: pay_ways,
  8023. PayPrice: pay_price,
  8024. MedType: strconv.Itoa(int(reg_type)),
  8025. PayCardNo: pay_card_no,
  8026. DiscountPrice: discount_price,
  8027. PreferentialPrice: preferential_price,
  8028. RealityPrice: reality_price,
  8029. FoundPrice: found_price,
  8030. MedicalInsurancePrice: medical_insurance_price,
  8031. PrivatePrice: private_price,
  8032. SettleEndTime: end_time,
  8033. SettleStartTime: start_time,
  8034. PsnPartAmt: totals,
  8035. PsnCashPay: totals,
  8036. SettleType: settle_accounts_type,
  8037. FaPiaoCode: fapiao_code,
  8038. FaPiaoNumber: fapiao_number,
  8039. Diagnosis: diagnosis_id,
  8040. PType: 2,
  8041. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8042. Decimal: decimal,
  8043. OthDesc: oth_desc,
  8044. CashPay: cash_pay,
  8045. WechatPay: wechat_pay,
  8046. AliPay: ali_pay,
  8047. JifenPay: jifen_pay,
  8048. BandCardPay: band_card_pay,
  8049. Creator: adminUser.AdminUser.Id,
  8050. }
  8051. err = service.CreateOrderTX(order, tx)
  8052. if err != nil {
  8053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8054. return
  8055. }
  8056. var customs []*Custom
  8057. for _, item := range prescriptions {
  8058. if item.Type == 1 { //药品a
  8059. for _, subItem := range item.HisDoctorAdviceInfo {
  8060. cus := &Custom{
  8061. AdviceId: subItem.ID,
  8062. ProjectId: 0,
  8063. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8064. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8065. FeedetlSn: subItem.FeedetlSn,
  8066. Price: fmt.Sprintf("%.4f", subItem.Price),
  8067. MedListCodg: subItem.MedListCodg,
  8068. Type: 1,
  8069. }
  8070. customs = append(customs, cus)
  8071. }
  8072. }
  8073. if item.Type == 2 { //项目
  8074. for _, subItem := range item.HisPrescriptionProject {
  8075. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8076. cus := &Custom{
  8077. AdviceId: 0,
  8078. ProjectId: subItem.ID,
  8079. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8080. Cut: fmt.Sprintf("%.4f", cnt),
  8081. FeedetlSn: subItem.FeedetlSn,
  8082. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8083. MedListCodg: subItem.MedListCodg,
  8084. Type: 2,
  8085. }
  8086. customs = append(customs, cus)
  8087. }
  8088. }
  8089. for _, item := range item.HisAdditionalCharge {
  8090. cus := &Custom{
  8091. ItemId: item.ID,
  8092. AdviceId: 0,
  8093. ProjectId: 0,
  8094. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8095. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8096. FeedetlSn: item.FeedetlSn,
  8097. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8098. MedListCodg: item.XtHisAddtionConfig.Code,
  8099. Type: 3,
  8100. }
  8101. customs = append(customs, cus)
  8102. }
  8103. }
  8104. for _, item := range customs {
  8105. var advice_id int64 = 0
  8106. var project_id int64 = 0
  8107. var item_id int64 = 0
  8108. var types int64 = 0
  8109. if item.Type == 1 {
  8110. advice_id = item.AdviceId
  8111. project_id = 0
  8112. item_id = 0
  8113. } else if item.Type == 2 {
  8114. advice_id = 0
  8115. item_id = 0
  8116. project_id = item.ProjectId
  8117. } else if item.Type == 3 {
  8118. advice_id = 0
  8119. item_id = item.ItemId
  8120. project_id = 0
  8121. }
  8122. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8123. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8124. pric, _ := strconv.ParseFloat(item.Price, 32)
  8125. info := &models.HisOrderInfo{
  8126. OrderNumber: order.Number,
  8127. UploadDate: time.Now().Unix(),
  8128. AdviceId: advice_id,
  8129. DetItemFeeSumamt: detItemFeeSumamt,
  8130. Cnt: cut,
  8131. Pric: pric,
  8132. PatientId: id,
  8133. Status: 1,
  8134. Mtime: time.Now().Unix(),
  8135. Ctime: time.Now().Unix(),
  8136. UserOrgId: adminUser.CurrentOrgId,
  8137. HisPatientId: his.ID,
  8138. OrderId: order.ID,
  8139. ProjectId: project_id,
  8140. Type: types,
  8141. ItemId: item_id,
  8142. }
  8143. service.CreateOrderInfoTX(info, tx)
  8144. }
  8145. his.Diagnosis = diagnosis_id
  8146. his.SickType = sick_type
  8147. his.RegisterType = reg_type
  8148. his.MedicalTreatmentType = reg_type
  8149. service.UpdataHisPateintTX(&his, tx)
  8150. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8151. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8152. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8153. //判断是否使用了押金
  8154. if dec_way == "true" {
  8155. tmpstring := strconv.FormatInt(order.ID, 10)
  8156. //扣押金
  8157. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8158. order.Decimal = decimal
  8159. service.UpDateOrderTwo(order, tx)
  8160. if errmsg != nil {
  8161. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8162. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8163. return
  8164. }
  8165. }
  8166. if err == nil {
  8167. for _, info := range prescriptions {
  8168. if info.Type == 1 {
  8169. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8170. }
  8171. if info.Type == 2 {
  8172. for _, sumItem := range info.HisPrescriptionProject {
  8173. if sumItem.Type == 3 {
  8174. var good models.DialysisBeforePrepareGoods
  8175. var newGood models.NewDialysisBeforePrepareGoods
  8176. var oldGood models.OldDialysisBeforePrepareGoods
  8177. good.GoodId = sumItem.GoodInfo.ID
  8178. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8179. count, _ := strconv.Atoi(sumItem.Count)
  8180. good.Count = int64(count)
  8181. good.StorehouseId = houseConfig.StorehouseOutInfo
  8182. good.ProjectId = sumItem.ID
  8183. good.PatientId = sumItem.PatientId
  8184. goods = append(goods, &good)
  8185. newGood.GoodId = sumItem.GoodInfo.ID
  8186. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8187. count2, _ := strconv.Atoi(sumItem.Count)
  8188. newGood.Count = int64(count2)
  8189. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8190. newGood.ProjectId = sumItem.ID
  8191. newGood.PatientId = sumItem.HisPatientId
  8192. newGoods = append(newGoods, &newGood)
  8193. oldGood.GoodId = sumItem.GoodInfo.ID
  8194. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8195. count3, _ := strconv.Atoi(sumItem.Count)
  8196. oldGood.Count = int64(count3)
  8197. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8198. oldGood.ProjectId = sumItem.ID
  8199. oldGood.RecordDate = sumItem.RecordDate
  8200. oldGood.PatientId = sumItem.HisPatientId
  8201. oldGoods = append(oldGoods, &oldGood)
  8202. }
  8203. }
  8204. }
  8205. }
  8206. if settConfig.IsOpen == 1 {
  8207. for _, item := range infoList {
  8208. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8209. if medical.IsUse == 2 {
  8210. //药品出库
  8211. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8212. //查询默认仓库
  8213. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8214. //查询默认仓库剩余多少库存
  8215. var sum_count int64
  8216. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8217. for _, its := range stockInfo {
  8218. if its.MaxUnit == medical.MaxUnit {
  8219. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8220. }
  8221. sum_count += its.StockMaxNumber + its.StockMinNumber
  8222. }
  8223. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8224. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8225. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8226. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8227. }
  8228. }
  8229. orgId := c.GetAdminUserInfo().CurrentOrgId
  8230. if len(oldGoods) > 0 {
  8231. timeStr := time.Now().Format("2006-01-02")
  8232. timeArr := strings.Split(timeStr, "-")
  8233. total, _ := service.FindAllWarehouseOut(orgId)
  8234. total = total + 1
  8235. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8236. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8237. number = number + total
  8238. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8239. operation_time := time.Now().Unix()
  8240. creater := c.GetAdminUserInfo().AdminUser.Id
  8241. //查询默认出库仓库库存
  8242. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8243. recordDateStr := time.Now().Format("2006-01-02")
  8244. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8245. nowtime := recordDate.Unix()
  8246. warehouseOut := models.WarehouseOut{
  8247. WarehouseOutOrderNumber: warehousing_out_order,
  8248. OperationTime: operation_time,
  8249. OrgId: orgId,
  8250. Creater: creater,
  8251. Ctime: time.Now().Unix(),
  8252. Status: 1,
  8253. WarehouseOutTime: nowtime,
  8254. Type: 1,
  8255. StorehouseId: storeConfig.StorehouseOutInfo,
  8256. IsCheck: 1,
  8257. OrderId: order.ID,
  8258. IsSys: 5,
  8259. }
  8260. //查询是否生成出库单
  8261. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8262. if out.ID == 0 {
  8263. service.AddSigleWarehouseOut(&warehouseOut)
  8264. }
  8265. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8266. for _, item := range oldGoods {
  8267. dialyPrepareOne := models.DialysisBeforePrepare{
  8268. GoodTypeId: item.GoodTypeId,
  8269. GoodId: item.GoodId,
  8270. PatientId: his.PatientId,
  8271. RecordDate: item.RecordDate,
  8272. UserOrgId: adminUser.CurrentOrgId,
  8273. Count: item.Count,
  8274. Ctime: time.Now().Unix(),
  8275. Creater: adminUser.AdminUser.Id,
  8276. CommdityCode: item.CommdityCode,
  8277. Status: 1,
  8278. StorehouseId: houseConfig.StorehouseOutInfo,
  8279. }
  8280. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8281. //非零用
  8282. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8283. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8284. //查询剩余库存
  8285. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8286. var sum_count int64
  8287. for _, item := range goodList {
  8288. sum_count += item.StockCount
  8289. }
  8290. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8291. //耗材
  8292. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8293. }
  8294. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8295. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8296. //查询剩余库存
  8297. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8298. var sum_count int64
  8299. for _, item := range goodList {
  8300. sum_count += item.StockCount
  8301. }
  8302. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8303. //耗材
  8304. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8305. }
  8306. }
  8307. }
  8308. }
  8309. c.ServeSuccessJSON(map[string]interface{}{
  8310. "msg": "结算成功",
  8311. })
  8312. }
  8313. }
  8314. }
  8315. // 退款
  8316. func (c *HisApiController) Refund() {
  8317. order_id, _ := c.GetInt64("order_id")
  8318. order, _ := service.GetHisOrderByID(order_id)
  8319. adminUser := c.GetAdminUserInfo()
  8320. orgid := c.GetAdminUserInfo().CurrentOrgId
  8321. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8322. if err != nil {
  8323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8324. return
  8325. }
  8326. tmp := strconv.FormatInt(order.ID, 10)
  8327. //当押金不为零时产生退费记录
  8328. if order.Decimal != 0 {
  8329. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8330. if err != nil {
  8331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8332. return
  8333. }
  8334. }
  8335. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8336. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8337. var goods []*models.DialysisBeforePrepareGoods
  8338. var newGoods []*models.NewDialysisBeforePrepareGoods
  8339. var infos []*models.HisDoctorAdviceInfo
  8340. for _, info := range orders {
  8341. if info.AdviceId > 0 && info.ProjectId == 0 {
  8342. infos = append(infos, &info.HisDoctorAdviceInfo)
  8343. }
  8344. if info.ProjectId > 0 && info.AdviceId == 0 {
  8345. if info.HisPrescriptionProject.Type == 3 {
  8346. var good models.DialysisBeforePrepareGoods
  8347. var newGood models.NewDialysisBeforePrepareGoods
  8348. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8349. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8350. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8351. good.Count = int64(count)
  8352. good.StorehouseId = houseConfig.StorehouseOutInfo
  8353. good.ProjectId = info.HisPrescriptionProject.ID
  8354. good.PatientId = info.PatientId
  8355. good.OrderId = order_id
  8356. goods = append(goods, &good)
  8357. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8358. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8359. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8360. newGood.Count = int64(count2)
  8361. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8362. newGood.ProjectId = info.HisPrescriptionProject.ID
  8363. newGood.RecordDate = order.SettleAccountsDate
  8364. newGood.UserOrgId = order.UserOrgId
  8365. newGood.PatientId = info.PatientId
  8366. newGood.OrderId = order_id
  8367. newGoods = append(newGoods, &newGood)
  8368. }
  8369. }
  8370. }
  8371. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8372. if settConfig.IsOpen == 1 {
  8373. for _, item := range infos {
  8374. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8375. }
  8376. for _, item := range newGoods {
  8377. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8378. }
  8379. }
  8380. c.ServeSuccessJSON(map[string]interface{}{
  8381. "msg": "退费成功",
  8382. })
  8383. }
  8384. func (c *HisApiController) RefundNumber() {
  8385. his_patient_id, _ := c.GetInt64("id")
  8386. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8387. info.Status = 0
  8388. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8389. if count > 0 {
  8390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8391. return
  8392. }
  8393. err := service.SaveHisPatient(info)
  8394. if err == nil {
  8395. c.ServeSuccessJSON(map[string]interface{}{
  8396. "msg": "退号成功",
  8397. })
  8398. } else {
  8399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8400. return
  8401. }
  8402. }
  8403. func (this *HisApiController) AdditionalCharge() {
  8404. dataBody := make(map[string]interface{}, 0)
  8405. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8406. fmt.Println(err)
  8407. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8408. patient_id := int64(dataBody["patient_id"].(float64))
  8409. medicineData, _ := dataBody["medicineData"].([]interface{})
  8410. adminUserInfo := this.GetAdminUserInfo()
  8411. orgId := adminUserInfo.CurrentOrgId
  8412. admin_user_id := adminUserInfo.AdminUser.Id
  8413. timeStr := time.Now().Format("2006-01-02")
  8414. timeLayout := "2006-01-02 15:04:05"
  8415. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8416. timenow := timeStringToTime.Unix()
  8417. var additionalCharges []*models.HisAdditionalCharge
  8418. for _, item := range medicineData {
  8419. var randNum int
  8420. randNum = rand.Intn(10000) + 1000
  8421. timestamp := time.Now().Unix()
  8422. tempTime := time.Unix(timestamp, 0)
  8423. timeFormat := tempTime.Format("20060102150405")
  8424. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8425. items := item.(map[string]interface{})
  8426. money := items["price"].(string)
  8427. item_id_str := items["item_id"].(string)
  8428. name := items["name"].(string)
  8429. id_str := items["id"].(string)
  8430. moneys, _ := strconv.ParseInt(money, 10, 64)
  8431. monStr := strconv.FormatInt(moneys, 10)
  8432. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8433. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8434. id, _ := strconv.ParseInt(id_str, 10, 64)
  8435. additionalCharge := &models.HisAdditionalCharge{
  8436. ID: id,
  8437. HisPatientId: his_patient_id,
  8438. UserOrgId: orgId,
  8439. PatientId: patient_id,
  8440. RecordDate: timenow,
  8441. Price: monneyStr,
  8442. Status: 1,
  8443. ItemName: name,
  8444. ItemId: item_id,
  8445. AdminUserId: admin_user_id,
  8446. CreatedTime: time.Now().Unix(),
  8447. OrderStatus: 0,
  8448. PrescriptionNumber: "",
  8449. BatchNumber: "",
  8450. FeedetlSn: p_number,
  8451. }
  8452. service.CreateAdditionalCharge(additionalCharge)
  8453. additionalCharges = append(additionalCharges, additionalCharge)
  8454. }
  8455. this.ServeSuccessJSON(map[string]interface{}{
  8456. "msg": "添加成功",
  8457. "additional_charges": additionalCharges,
  8458. })
  8459. }
  8460. func (this *HisApiController) DeleteAddition() {
  8461. id, _ := this.GetInt64("id")
  8462. //TODO 需要判断是否已经结算
  8463. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8464. if err == nil {
  8465. this.ServeSuccessJSON(map[string]interface{}{
  8466. "msg": "删除成功",
  8467. })
  8468. return
  8469. } else {
  8470. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8471. return
  8472. }
  8473. }
  8474. func (this *HisApiController) GetAdminUsers() {
  8475. adminUser := this.GetAdminUserInfo()
  8476. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8477. this.ServeSuccessJSON(map[string]interface{}{
  8478. "doctors": doctors,
  8479. })
  8480. }
  8481. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8482. change_type, _ := this.GetInt64("type", 0)
  8483. record_date := this.GetString("record_time")
  8484. patient_id, _ := this.GetInt64("patient_id", 0)
  8485. p_type, _ := this.GetInt64("p_type", 0)
  8486. timeLayout := "2006-01-02"
  8487. loc, _ := time.LoadLocation("Local")
  8488. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8489. record_time := theAdviceRecordTime.Unix()
  8490. adminUserInfo := this.GetAdminUserInfo()
  8491. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8492. if err == nil {
  8493. if len(prescriptions) == 0 {
  8494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8495. return
  8496. } else {
  8497. this.ServeSuccessJSON(map[string]interface{}{
  8498. "prescriptions": prescriptions,
  8499. })
  8500. return
  8501. }
  8502. } else {
  8503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8504. return
  8505. }
  8506. }
  8507. func (this *HisApiController) GetCallHisPrescription() {
  8508. patient_id, _ := this.GetInt64("patient_id", 0)
  8509. timeLayout := "2006-01-02"
  8510. loc, _ := time.LoadLocation("Local")
  8511. start_time := this.GetString("start_time")
  8512. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8513. end_time := this.GetString("end_time")
  8514. p_type, _ := this.GetInt64("p_type")
  8515. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8516. adminUserInfo := this.GetAdminUserInfo()
  8517. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8518. if err == nil {
  8519. this.ServeSuccessJSON(map[string]interface{}{
  8520. "prescriptions": prescriptions,
  8521. })
  8522. return
  8523. } else {
  8524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8525. return
  8526. }
  8527. }
  8528. func (this *HisApiController) GetHisDayPrescription() {
  8529. timeLayout := "2006-01-02"
  8530. loc, _ := time.LoadLocation("Local")
  8531. start_time := this.GetString("start_time")
  8532. patient_id, _ := this.GetInt64("patient_id", 0)
  8533. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8534. end_time := this.GetString("end_time")
  8535. p_type, _ := this.GetInt64("p_type")
  8536. order_status, _ := this.GetInt64("type")
  8537. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8538. adminUserInfo := this.GetAdminUserInfo()
  8539. var dayHisPrescription []*models.HisPrescription
  8540. var err error
  8541. if order_status == 1 || order_status == 0 {
  8542. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8543. } else if order_status == 2 {
  8544. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8545. }
  8546. var settle_total float64
  8547. for _, item := range dayHisPrescription {
  8548. if len(item.HisPrescriptionProject) > 0 {
  8549. for _, subItem := range item.HisPrescriptionProject {
  8550. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8551. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8552. settle_total = settle_total + total
  8553. }
  8554. }
  8555. if len(item.HisDoctorAdviceInfo) > 0 {
  8556. for _, subItem := range item.HisDoctorAdviceInfo {
  8557. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8558. settle_total = settle_total + total
  8559. }
  8560. }
  8561. }
  8562. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8563. if err == nil {
  8564. this.ServeSuccessJSON(map[string]interface{}{
  8565. "day_prescription": dayHisPrescription,
  8566. "settle_total": settle_total,
  8567. })
  8568. return
  8569. } else {
  8570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8571. return
  8572. }
  8573. }
  8574. func (c *HisApiController) GetHisChargePatientList() {
  8575. record_date := c.GetString("record_date")
  8576. order_status, _ := c.GetInt64("type")
  8577. sch_type, _ := c.GetInt64("sch_type")
  8578. timeLayout := "2006-01-02"
  8579. loc, _ := time.LoadLocation("Local")
  8580. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8581. if err != nil {
  8582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8583. return
  8584. }
  8585. recordDateTime := theTime.Unix()
  8586. adminInfo := c.GetAdminUserInfo()
  8587. var tempPatients []*service.NewTempPatients
  8588. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8589. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8590. if order_status != 2 {
  8591. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8592. } else {
  8593. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8594. }
  8595. } else {
  8596. if order_status != 2 {
  8597. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8598. } else {
  8599. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8600. }
  8601. }
  8602. var patients []*service.NewTempPatients
  8603. var patients_two []*service.NewTempPatients
  8604. for _, item := range tempPatients {
  8605. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8606. //过滤掉没挂号的和没开处方的
  8607. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8608. patients = append(patients, item)
  8609. }
  8610. //过滤掉没挂号的
  8611. if len(item.HisPatient) > 0 {
  8612. patients_two = append(patients_two, item)
  8613. }
  8614. } else {
  8615. if len(item.HisPrescription) > 0 {
  8616. patients = append(patients, item)
  8617. }
  8618. }
  8619. }
  8620. c.ServeSuccessJSON(map[string]interface{}{
  8621. "list": patients,
  8622. "list_two": patients_two,
  8623. })
  8624. }
  8625. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8626. record_date := c.GetString("record_date")
  8627. timeLayout := "2006-01-02"
  8628. loc, _ := time.LoadLocation("Local")
  8629. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8630. if err != nil {
  8631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8632. return
  8633. }
  8634. recordDateTime := theTime.Unix()
  8635. adminUser := c.GetAdminUserInfo()
  8636. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8637. var patients []*service.Patients
  8638. for _, item := range tempPatients {
  8639. if item.HisPatient.ID == 0 {
  8640. patients = append(patients, item)
  8641. }
  8642. }
  8643. c.ServeSuccessJSON(map[string]interface{}{
  8644. "list": patients,
  8645. //"list_two": patients_two,
  8646. })
  8647. }
  8648. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8649. newArr = make([]*service.Patients, 0)
  8650. for i := 0; i < len(patient); i++ {
  8651. repeat := false
  8652. for j := i + 1; j < len(patient); j++ {
  8653. if patient[i].ID == patient[j].ID {
  8654. repeat = true
  8655. break
  8656. }
  8657. }
  8658. if !repeat {
  8659. newArr = append(newArr, patient[i])
  8660. }
  8661. }
  8662. return
  8663. }
  8664. func (c *HisApiController) GetHisChargePatientInfo() {
  8665. patient_id, _ := c.GetInt64("patient_id")
  8666. his_patient_id, _ := c.GetInt64("his_patient_id")
  8667. record_date := c.GetString("record_date")
  8668. //start_time := c.GetString("start_time")
  8669. //end_time := c.GetString("end_time")
  8670. order_status, _ := c.GetInt64("type", 0)
  8671. p_type, _ := c.GetInt64("p_type", 0)
  8672. order_id, _ := c.GetInt64("order_id", 0)
  8673. timeLayout := "2006-01-02"
  8674. loc, _ := time.LoadLocation("Local")
  8675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8676. if err != nil {
  8677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8678. return
  8679. }
  8680. recordDateTime := theTime.Unix()
  8681. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8682. //if err != nil {
  8683. //
  8684. //}
  8685. //startRecordDateTime := startTime.Unix()
  8686. //
  8687. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8688. //if err != nil {
  8689. //
  8690. //}
  8691. //endRecordDateTime := endTime.Unix()
  8692. admin := c.GetAdminUserInfo()
  8693. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8694. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8695. var prescriptions []*models.HisPrescription
  8696. //var unChargeMonthPrescriptions []*models.HisPrescription
  8697. order, _ := service.GetHisOrderByID(order_id)
  8698. if order_status == 1 || order_status == 0 {
  8699. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8700. } else if order_status == 2 {
  8701. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8702. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8703. }
  8704. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8705. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8706. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8707. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8708. //获取所有科室信息
  8709. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8710. c.ServeSuccessJSON(map[string]interface{}{
  8711. "his_info": his_patient_info,
  8712. "xt_info": xt_patient_info,
  8713. "prescription": prescriptions,
  8714. "case_history": case_history,
  8715. "info": patientPrescriptionInfo,
  8716. "last_info": lastPatientPrescriptionInfo,
  8717. "order": order,
  8718. "doctors": doctors,
  8719. "department": department,
  8720. })
  8721. return
  8722. }
  8723. func (c *HisApiController) GetAllOrderDetail() {
  8724. order_id, _ := c.GetInt64("id", 0)
  8725. order, _ := service.GetHisOrderByID(order_id)
  8726. if order.ID == 0 {
  8727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8728. return
  8729. }
  8730. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8731. org_id := c.GetAdminUserInfo().CurrentOrgId
  8732. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8733. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8734. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8735. c.ServeSuccessJSON(map[string]interface{}{
  8736. "order": order,
  8737. "order_info": order_info,
  8738. "patient": patient,
  8739. "admin_info": adminInfo,
  8740. "hospital_record": record,
  8741. })
  8742. return
  8743. }
  8744. func (c *HisApiController) GetAllOrderDetailCollect() {
  8745. order_id, _ := c.GetInt64("id", 0)
  8746. order, _ := service.GetHisOrderByID(order_id)
  8747. if order.ID == 0 {
  8748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8749. return
  8750. }
  8751. org_id := c.GetAdminUserInfo().CurrentOrgId
  8752. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8753. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8754. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8755. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8756. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8757. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8758. var bedCostTotal float64 = 0 //床位总费
  8759. //var bedCostSelfTotal float64 = 0 //床位自费
  8760. var operationCostTotal float64 = 0 //手术费
  8761. //var operationCostSelfTotal float64 = 0 //手术费
  8762. var otherCostTotal float64 = 0 //其他费用
  8763. //var otherCostSelfTotal float64 = 0 //其他费用
  8764. var materialCostTotal float64 = 0 //材料费
  8765. //var materialCostSelfTotal float64 = 0 //材料费
  8766. var westernMedicineCostTotal float64 = 0 //西药费
  8767. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8768. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8769. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8770. var checkCostTotal float64 = 0 //检查费
  8771. //var checkCostSelfTotal float64 = 0 //检查费
  8772. var laboratoryCostTotal float64 = 0 //化验费
  8773. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8774. var treatCostTotal float64 = 0 //治疗费用
  8775. //var treatCostSelfTotal float64 = 0 //治疗费用
  8776. var zhenChaCostTotal float64 = 0 //其他费用
  8777. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8778. decimal.DivisionPrecision = 2
  8779. var BalanceAccountsType int64
  8780. if his.ID > 0 {
  8781. BalanceAccountsType = his.BalanceAccountsType
  8782. } else {
  8783. BalanceAccountsType = record.BalanceAccountsType
  8784. }
  8785. if BalanceAccountsType != 2 {
  8786. for _, item := range order_info {
  8787. if org_id == 10215 {
  8788. if item.MedChrgitmType == "01" { //床位费
  8789. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8790. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8791. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8792. }
  8793. if item.MedChrgitmType == "02" { //诊察费
  8794. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8795. //zhenChaCostSelfTotal = zhenChaCostTotal
  8796. }
  8797. if item.MedChrgitmType == "03" { //检查费
  8798. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8799. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8800. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8801. }
  8802. //if item.MedChrgitmType == "02" { //检查费
  8803. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8804. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8805. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8806. //}
  8807. if item.MedChrgitmType == "04" { //化验费
  8808. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8809. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8810. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8811. }
  8812. if item.MedChrgitmType == "05" { //治疗费
  8813. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8814. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8815. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8816. }
  8817. if item.MedChrgitmType == "06" { //手术费
  8818. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8819. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8820. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8821. }
  8822. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8823. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8824. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8825. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8826. }
  8827. if item.MedChrgitmType == "09" { //西药费
  8828. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8829. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8830. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8831. }
  8832. if item.MedChrgitmType == "11" { //中成费
  8833. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8834. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8835. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8836. }
  8837. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8838. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8839. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8840. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8841. }
  8842. } else if org_id == 10188 || org_id == 10217 {
  8843. if item.MedChrgitmType == "01" { //床位费
  8844. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8845. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8846. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8847. }
  8848. if item.MedChrgitmType == "02" { //诊察费
  8849. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8850. //zhenChaCostSelfTotal = zhenChaCostTotal
  8851. }
  8852. if item.MedChrgitmType == "03" { //检查费
  8853. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8854. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8855. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8856. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8857. }
  8858. //if item.MedChrgitmType == "02" { //检查费
  8859. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8860. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8861. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8862. //}
  8863. if item.MedChrgitmType == "04" { //化验费
  8864. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8865. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8866. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8867. }
  8868. if item.MedChrgitmType == "05" { //治疗费
  8869. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8870. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8871. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8872. }
  8873. if item.MedChrgitmType == "06" { //手术费
  8874. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8875. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8876. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8877. }
  8878. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8879. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8880. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8881. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8882. }
  8883. if item.MedChrgitmType == "09" { //西药费
  8884. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8885. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8886. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8887. }
  8888. if item.MedChrgitmType == "11" { //中成费
  8889. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8890. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8891. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8892. }
  8893. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8894. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8895. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8896. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8897. }
  8898. } else {
  8899. if item.MedChrgitmType == "01" { //床位费
  8900. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8901. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8902. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8903. }
  8904. //if item.MedChrgitmType == "02" { //诊察费
  8905. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8906. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8907. //}
  8908. if item.MedChrgitmType == "03" { //检查费
  8909. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8910. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8911. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8912. }
  8913. //if item.MedChrgitmType == "02" { //检查费
  8914. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8915. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8916. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8917. //}
  8918. if item.MedChrgitmType == "04" { //化验费
  8919. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8920. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8921. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8922. }
  8923. if item.MedChrgitmType == "05" { //治疗费
  8924. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8925. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8926. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8927. }
  8928. if item.MedChrgitmType == "06" { //手术费
  8929. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8930. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8931. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8932. }
  8933. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8934. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8935. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8936. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8937. }
  8938. if item.MedChrgitmType == "09" { //西药费
  8939. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8940. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8941. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8942. }
  8943. if item.MedChrgitmType == "11" { //中成费
  8944. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8945. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8946. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8947. }
  8948. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8949. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8950. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8951. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8952. }
  8953. }
  8954. }
  8955. c.ServeSuccessJSON(map[string]interface{}{
  8956. "order": order,
  8957. "order_info": order_info,
  8958. "patient": patient,
  8959. "admin_info": adminInfo,
  8960. "his_hospital": record,
  8961. "bedCostTotal": bedCostTotal,
  8962. "operationCostTotal": operationCostTotal,
  8963. "otherCostTotal": otherCostTotal,
  8964. "materialCostTotal": materialCostTotal,
  8965. "westernMedicineCostTotal": westernMedicineCostTotal,
  8966. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8967. "checkCostTotal": checkCostTotal,
  8968. "zhenChaCostTotal": zhenChaCostTotal,
  8969. "laboratoryCostTotal": laboratoryCostTotal,
  8970. "treatCostTotal": treatCostTotal,
  8971. })
  8972. } else {
  8973. for _, item := range order_info {
  8974. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8975. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8976. item.MedChrgitmType = "09"
  8977. }
  8978. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8979. if item.HisPrescriptionProject.Type == 2 {
  8980. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8981. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8982. case 0:
  8983. item.MedChrgitmType = "0"
  8984. break
  8985. case 1:
  8986. item.MedChrgitmType = "14"
  8987. break
  8988. case 2:
  8989. item.MedChrgitmType = "05"
  8990. break
  8991. case 3:
  8992. item.MedChrgitmType = "03"
  8993. break
  8994. case 4:
  8995. item.MedChrgitmType = "03"
  8996. break
  8997. case 5:
  8998. item.MedChrgitmType = "08"
  8999. break
  9000. case 6:
  9001. item.MedChrgitmType = "14"
  9002. break
  9003. case 7:
  9004. item.MedChrgitmType = "14"
  9005. break
  9006. case 8:
  9007. item.MedChrgitmType = "03"
  9008. break
  9009. case 9:
  9010. item.MedChrgitmType = "14"
  9011. break
  9012. case 10:
  9013. item.MedChrgitmType = "14"
  9014. break
  9015. case 11:
  9016. item.MedChrgitmType = "06"
  9017. break
  9018. case 12:
  9019. item.MedChrgitmType = "12"
  9020. break
  9021. case 13:
  9022. item.MedChrgitmType = "01"
  9023. break
  9024. case 14:
  9025. item.MedChrgitmType = "04"
  9026. break
  9027. case 15:
  9028. item.MedChrgitmType = "14"
  9029. break
  9030. }
  9031. } else {
  9032. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9033. case 1:
  9034. item.MedChrgitmType = "14"
  9035. break
  9036. case 2:
  9037. item.MedChrgitmType = "05"
  9038. break
  9039. case 3:
  9040. item.MedChrgitmType = "04"
  9041. break
  9042. case 4:
  9043. item.MedChrgitmType = "14"
  9044. break
  9045. case 5:
  9046. item.MedChrgitmType = "08"
  9047. break
  9048. case 6:
  9049. item.MedChrgitmType = "14"
  9050. break
  9051. case 7:
  9052. item.MedChrgitmType = "14"
  9053. break
  9054. case 8:
  9055. item.MedChrgitmType = "03"
  9056. break
  9057. case 9:
  9058. item.MedChrgitmType = "14"
  9059. break
  9060. }
  9061. }
  9062. } else if item.HisPrescriptionProject.Type == 3 {
  9063. item.MedChrgitmType = "08"
  9064. }
  9065. }
  9066. }
  9067. for _, item := range order_info {
  9068. if org_id == 10215 {
  9069. if item.MedChrgitmType == "01" { //床位费
  9070. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9071. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9072. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9073. }
  9074. if item.MedChrgitmType == "02" { //诊察费
  9075. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9076. //zhenChaCostSelfTotal = zhenChaCostTotal
  9077. }
  9078. if item.MedChrgitmType == "03" { //检查费
  9079. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9080. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9081. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9082. }
  9083. //if item.MedChrgitmType == "02" { //检查费
  9084. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9085. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9086. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9087. //}
  9088. if item.MedChrgitmType == "04" { //化验费
  9089. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9090. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9091. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9092. }
  9093. if item.MedChrgitmType == "05" { //治疗费
  9094. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9095. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9096. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9097. }
  9098. if item.MedChrgitmType == "06" { //手术费
  9099. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9100. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9101. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9102. }
  9103. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9104. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9105. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9106. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9107. }
  9108. if item.MedChrgitmType == "09" { //西药费
  9109. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9110. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9111. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9112. }
  9113. if item.MedChrgitmType == "11" { //中成费
  9114. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9115. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9116. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9117. }
  9118. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9119. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9120. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9121. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9122. }
  9123. } else {
  9124. if item.MedChrgitmType == "01" { //床位费
  9125. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9126. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9127. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9128. }
  9129. //if item.MedChrgitmType == "02" { //诊察费
  9130. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9131. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9132. //}
  9133. if item.MedChrgitmType == "03" { //检查费
  9134. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9135. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9136. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9137. }
  9138. //if item.MedChrgitmType == "02" { //检查费
  9139. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9140. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9141. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9142. //}
  9143. if item.MedChrgitmType == "04" { //化验费
  9144. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9145. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9146. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9147. }
  9148. if item.MedChrgitmType == "05" { //治疗费
  9149. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9150. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9151. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9152. }
  9153. if item.MedChrgitmType == "06" { //手术费
  9154. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9155. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9156. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9157. }
  9158. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9159. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9160. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9161. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9162. }
  9163. if item.MedChrgitmType == "09" { //西药费
  9164. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9165. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9166. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9167. }
  9168. if item.MedChrgitmType == "11" { //中成费
  9169. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9170. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9171. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9172. }
  9173. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9174. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9175. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9176. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9177. }
  9178. }
  9179. }
  9180. c.ServeSuccessJSON(map[string]interface{}{
  9181. "order": order,
  9182. "order_info": order_info,
  9183. "patient": patient,
  9184. "admin_info": adminInfo,
  9185. "his_hospital": record,
  9186. "bedCostTotal": bedCostTotal,
  9187. "operationCostTotal": operationCostTotal,
  9188. "otherCostTotal": otherCostTotal,
  9189. "materialCostTotal": materialCostTotal,
  9190. "westernMedicineCostTotal": westernMedicineCostTotal,
  9191. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9192. "checkCostTotal": checkCostTotal,
  9193. "zhenChaCostTotal": zhenChaCostTotal,
  9194. "laboratoryCostTotal": laboratoryCostTotal,
  9195. "treatCostTotal": treatCostTotal,
  9196. })
  9197. }
  9198. }
  9199. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9200. page, _ := c.GetInt64("page")
  9201. limit, _ := c.GetInt64("limit")
  9202. keywords := c.GetString("keywords")
  9203. start_time := c.GetString("start_time")
  9204. end_time := c.GetString("end_time")
  9205. //clr_type := c.GetString("clr_type")
  9206. insutype := c.GetString("insutype")
  9207. timeLayout := "2006-01-02"
  9208. loc, _ := time.LoadLocation("Local")
  9209. var theStartTIme int64
  9210. if len(start_time) > 0 {
  9211. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9212. theStartTIme = theTime.Unix()
  9213. }
  9214. var theEndtTIme int64
  9215. if len(end_time) > 0 {
  9216. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9217. theEndtTIme = theTime.Unix()
  9218. }
  9219. if page <= 0 {
  9220. page = 1
  9221. }
  9222. if limit <= 0 {
  9223. limit = 10
  9224. }
  9225. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9226. c.ServeSuccessJSON(map[string]interface{}{
  9227. "total": total,
  9228. "list": list,
  9229. })
  9230. return
  9231. }
  9232. func (c *HisApiController) GetPutOnRecordList() {
  9233. page, _ := c.GetInt64("page")
  9234. limit, _ := c.GetInt64("limit")
  9235. keywords := c.GetString("keywords")
  9236. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9237. if page <= 0 {
  9238. page = 1
  9239. }
  9240. if limit <= 0 {
  9241. limit = 10
  9242. }
  9243. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9244. c.ServeSuccessJSON(map[string]interface{}{
  9245. "total": total,
  9246. "list": list,
  9247. })
  9248. return
  9249. }
  9250. func (c *HisApiController) GetCompareData() {
  9251. start_time := c.GetString("start_time")
  9252. end_time := c.GetString("end_time")
  9253. insutype := c.GetString("insutype")
  9254. clr_type := c.GetString("clr_type")
  9255. timeLayout := "2006-01-02"
  9256. loc, _ := time.LoadLocation("Local")
  9257. var theStartTIme int64
  9258. if len(start_time) > 0 {
  9259. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9260. if err != nil {
  9261. theStartTIme = 0
  9262. }
  9263. theStartTIme = theTime.Unix()
  9264. }
  9265. var theEndtTIme int64
  9266. if len(end_time) > 0 {
  9267. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9268. if err != nil {
  9269. theEndtTIme = 0
  9270. }
  9271. theEndtTIme = theTime.Unix()
  9272. }
  9273. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9274. fmt.Println(err)
  9275. if err == nil {
  9276. c.ServeSuccessJSON(map[string]interface{}{
  9277. "list": formData,
  9278. })
  9279. } else {
  9280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9281. return
  9282. }
  9283. }
  9284. func (c *HisApiController) GetFaPiaoData() {
  9285. order_id, _ := c.GetInt64("order_id")
  9286. patient_id, _ := c.GetInt64("patient_id")
  9287. //number := c.GetString("number")
  9288. adminUser := c.GetAdminUserInfo()
  9289. order, _ := service.GetHisOrderByID(order_id)
  9290. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9291. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9292. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9293. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9294. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9295. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9296. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9297. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9298. var bedCostTotal float64 = 0 //床位总费
  9299. var bedCostSelfTotal float64 = 0 //床位自费
  9300. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9301. var operationCostTotal float64 = 0 //手术费
  9302. var operationCostSelfTotal float64 = 0 //手术费
  9303. var operationCostPartSelfTotal float64 = 0 //手术费
  9304. var otherCostTotal float64 = 0 //其他费用
  9305. var otherCostSelfTotal float64 = 0 //其他费用
  9306. var otherCostPartSelfTotal float64 = 0 //其他费用
  9307. var materialCostTotal float64 = 0 //材料费
  9308. var materialCostSelfTotal float64 = 0 //材料费
  9309. var materialCostPartSelfTotal float64 = 0 //材料费
  9310. var westernMedicineCostTotal float64 = 0 //西药费
  9311. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9312. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9313. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9314. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9315. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9316. var checkCostTotal float64 = 0 //检查费
  9317. var checkCostSelfTotal float64 = 0 //检查费
  9318. var checkCostPartSelfTotal float64 = 0 //检查费
  9319. var hiliCostTotal float64 = 0 //护理费
  9320. var hiliCostSelfTotal float64 = 0 //护理费
  9321. var hiliCostPartSelfTotal float64 = 0 //护理费
  9322. var laboratoryCostTotal float64 = 0 //化验费
  9323. var laboratoryCostSelfTotal float64 = 0 //化验费
  9324. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9325. var treatCostTotal float64 = 0 //治疗费用
  9326. var treatCostSelfTotal float64 = 0 //治疗费用
  9327. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9328. var zhenChaCostTotal float64 = 0 //其他费用
  9329. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9330. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9331. decimal.DivisionPrecision = 2
  9332. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9333. var balanceAccountsType int64
  9334. if his.ID > 0 {
  9335. balanceAccountsType = his.BalanceAccountsType
  9336. } else {
  9337. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9338. }
  9339. if balanceAccountsType == 2 {
  9340. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9341. for _, item := range orderInfos_two {
  9342. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9343. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9344. item.MedChrgitmType = "09"
  9345. }
  9346. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9347. if item.HisPrescriptionProject.Type == 2 {
  9348. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9349. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9350. case 0:
  9351. item.MedChrgitmType = "0"
  9352. break
  9353. case 1:
  9354. item.MedChrgitmType = "14"
  9355. break
  9356. case 2:
  9357. item.MedChrgitmType = "05"
  9358. break
  9359. case 3:
  9360. item.MedChrgitmType = "03"
  9361. break
  9362. case 4:
  9363. item.MedChrgitmType = "03"
  9364. break
  9365. case 5:
  9366. item.MedChrgitmType = "08"
  9367. break
  9368. case 6:
  9369. item.MedChrgitmType = "14"
  9370. break
  9371. case 7:
  9372. item.MedChrgitmType = "14"
  9373. break
  9374. case 8:
  9375. item.MedChrgitmType = "03"
  9376. break
  9377. case 9:
  9378. item.MedChrgitmType = "14"
  9379. break
  9380. case 10:
  9381. item.MedChrgitmType = "14"
  9382. break
  9383. case 11:
  9384. item.MedChrgitmType = "06"
  9385. break
  9386. case 12:
  9387. item.MedChrgitmType = "12"
  9388. break
  9389. case 13:
  9390. item.MedChrgitmType = "01"
  9391. break
  9392. case 14:
  9393. item.MedChrgitmType = "04"
  9394. break
  9395. case 15:
  9396. item.MedChrgitmType = "02"
  9397. break
  9398. }
  9399. } else {
  9400. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9401. case 1:
  9402. item.MedChrgitmType = "14"
  9403. break
  9404. case 2:
  9405. item.MedChrgitmType = "05"
  9406. break
  9407. case 3:
  9408. item.MedChrgitmType = "04"
  9409. break
  9410. case 4:
  9411. item.MedChrgitmType = "03"
  9412. break
  9413. case 5:
  9414. item.MedChrgitmType = "08"
  9415. break
  9416. case 6:
  9417. item.MedChrgitmType = "14"
  9418. break
  9419. case 7:
  9420. item.MedChrgitmType = "14"
  9421. break
  9422. case 8:
  9423. item.MedChrgitmType = "03"
  9424. break
  9425. case 9:
  9426. item.MedChrgitmType = "14"
  9427. break
  9428. }
  9429. }
  9430. } else if item.HisPrescriptionProject.Type == 3 {
  9431. item.MedChrgitmType = "08"
  9432. }
  9433. }
  9434. }
  9435. for _, item := range orderInfos_two {
  9436. fmt.Println(item.MedChrgitmType)
  9437. if item.MedChrgitmType == "07" { //床位费
  9438. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9439. hiliCostSelfTotal = hiliCostTotal
  9440. }
  9441. if item.MedChrgitmType == "01" { //床位费
  9442. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9443. bedCostSelfTotal = bedCostTotal
  9444. }
  9445. if item.MedChrgitmType == "02" { //诊察费
  9446. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9447. zhenChaCostSelfTotal = zhenChaCostTotal
  9448. }
  9449. if item.MedChrgitmType == "03" { //检查费
  9450. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9451. checkCostSelfTotal = checkCostTotal
  9452. }
  9453. if item.MedChrgitmType == "04" { //化验费
  9454. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9455. laboratoryCostSelfTotal = laboratoryCostTotal
  9456. }
  9457. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9458. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9459. treatCostSelfTotal = treatCostTotal
  9460. }
  9461. if item.MedChrgitmType == "06" { //手术费
  9462. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9463. operationCostSelfTotal = treatCostTotal
  9464. }
  9465. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9466. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9467. materialCostSelfTotal = materialCostTotal
  9468. }
  9469. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9470. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9471. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9472. }
  9473. if item.MedChrgitmType == "11" { //中成费
  9474. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9475. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9476. }
  9477. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9478. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9479. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9480. otherCostSelfTotal = otherCostTotal
  9481. }
  9482. } else {
  9483. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9484. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9485. otherCostSelfTotal = otherCostTotal
  9486. }
  9487. }
  9488. }
  9489. } else {
  9490. for _, item := range orderInfos {
  9491. if item.MedChrgitmType == "01" { //床位费
  9492. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9493. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9494. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9495. }
  9496. if item.MedChrgitmType == "02" { //诊察费
  9497. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9498. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9499. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9500. }
  9501. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9502. if item.MedChrgitmType == "03" { //检查费
  9503. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9504. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9505. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9506. }
  9507. } else {
  9508. if item.MedChrgitmType == "03" { //检查费
  9509. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9510. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9511. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9512. }
  9513. }
  9514. if item.MedChrgitmType == "04" { //化验费
  9515. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9516. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9517. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9518. }
  9519. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9520. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9521. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9522. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9523. }
  9524. if item.MedChrgitmType == "06" { //手术费
  9525. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9526. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9527. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9528. }
  9529. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9530. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9531. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9532. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9533. }
  9534. if item.MedChrgitmType == "07" { //护理
  9535. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9536. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9537. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9538. }
  9539. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9540. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9541. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9542. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9543. }
  9544. if item.MedChrgitmType == "11" { //中成费
  9545. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9546. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9547. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9548. }
  9549. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9550. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9551. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9552. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9553. }
  9554. }
  9555. }
  9556. timeLayout := "2006-01-02"
  9557. loc, _ := time.LoadLocation("Local")
  9558. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9559. if err != nil {
  9560. }
  9561. startRecordDateTime := startTime.Unix()
  9562. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9563. if err != nil {
  9564. }
  9565. endRecordDateTime := endTime.Unix()
  9566. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9567. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9568. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9569. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  9570. c.ServeSuccessJSON(map[string]interface{}{
  9571. "charge_admin_name": charge_admin.UserName,
  9572. "order_number": order.Number, //业务流水号
  9573. "id_card_no": his.IdCardNo, //社会保障号
  9574. "patient": patient,
  9575. "department_name": department.Name, //科室
  9576. "number": his.Number, //门诊号
  9577. "date": order.SettleAccountsDate, //结算日期
  9578. "name": order.PsnName, //姓名
  9579. "gender": patient.Gender, //性别
  9580. "psn_cash_money": order.PsnCashPay, //个人支付
  9581. "pay_way": "门诊", //结算方式
  9582. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9583. "admin_user_name": admin.UserName, //收款员
  9584. "order": order,
  9585. "order_info": orderInfos_two,
  9586. "his": his,
  9587. "bedCostTotal": bedCostTotal,
  9588. "bedCostSelfTotal": bedCostSelfTotal,
  9589. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9590. "operationCostTotal": operationCostTotal,
  9591. "operationCostSelfTotal": operationCostSelfTotal,
  9592. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9593. "otherCostTotal": otherCostTotal,
  9594. "otherCostSelfTotal": otherCostSelfTotal,
  9595. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9596. "materialCostTotal": materialCostTotal,
  9597. "materialCostSelfTotal": materialCostSelfTotal,
  9598. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9599. "westernMedicineCostTotal": westernMedicineCostTotal,
  9600. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9601. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9602. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9603. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9604. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9605. "checkCostTotal": checkCostTotal,
  9606. "checkCostSelfTotal": checkCostSelfTotal,
  9607. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9608. "laboratoryCostTotal": laboratoryCostTotal,
  9609. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9610. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9611. "treatCostTotal": treatCostTotal,
  9612. "treatCostSelfTotal": treatCostSelfTotal,
  9613. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9614. "zhenChaCostTotal": zhenChaCostTotal,
  9615. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9616. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9617. "his_hospital_record": his_hospital_record,
  9618. "pre_pay_money": pre_pay_money,
  9619. "refund_sum": sum,
  9620. "doctor_info": doctor_info,
  9621. "hiliCostTotal": hiliCostTotal,
  9622. "hiliCostSelfTotal": hiliCostSelfTotal,
  9623. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9624. })
  9625. }
  9626. //func (c *HisApiController) GetFaPiaoDatas() {
  9627. // order_ids := c.GetString("order_ids")
  9628. // patient_id, _ := c.GetInt64("patient_id")
  9629. // adminUser := c.GetAdminUserInfo()
  9630. //
  9631. // orders := strings.Split(order_ids, ",")
  9632. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9633. //
  9634. // for _, item := range orders {
  9635. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9636. // order, _ := service.GetHisOrderByID(order_id)
  9637. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9638. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9639. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9640. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9641. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9642. //
  9643. // }
  9644. //
  9645. // var bedCostTotal float64 = 0 //床位总费
  9646. // var bedCostSelfTotal float64 = 0 //床位自费
  9647. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9648. //
  9649. // var operationCostTotal float64 = 0 //手术费
  9650. // var operationCostSelfTotal float64 = 0 //手术费
  9651. // var operationCostPartSelfTotal float64 = 0 //手术费
  9652. //
  9653. // var otherCostTotal float64 = 0 //其他费用
  9654. // var otherCostSelfTotal float64 = 0 //其他费用
  9655. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9656. //
  9657. // var materialCostTotal float64 = 0 //材料费
  9658. // var materialCostSelfTotal float64 = 0 //材料费
  9659. // var materialCostPartSelfTotal float64 = 0 //材料费
  9660. //
  9661. // var westernMedicineCostTotal float64 = 0 //西药费
  9662. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9663. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9664. //
  9665. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9666. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9667. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9668. //
  9669. // var checkCostTotal float64 = 0 //检查费
  9670. // var checkCostSelfTotal float64 = 0 //检查费
  9671. // var checkCostPartSelfTotal float64 = 0 //检查费
  9672. //
  9673. // var laboratoryCostTotal float64 = 0 //化验费
  9674. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9675. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9676. //
  9677. // var treatCostTotal float64 = 0 //治疗费用
  9678. // var treatCostSelfTotal float64 = 0 //治疗费用
  9679. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9680. //
  9681. // var zhenChaCostTotal float64 = 0 //其他费用
  9682. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9683. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9684. //
  9685. // decimal.DivisionPrecision = 2
  9686. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9687. //
  9688. // var balanceAccountsType int64
  9689. // if his.ID > 0 {
  9690. // balanceAccountsType = his.BalanceAccountsType
  9691. // } else {
  9692. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9693. // }
  9694. // if balanceAccountsType == 2 {
  9695. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9696. // for _, item := range orderInfos_two {
  9697. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9698. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9699. // item.MedChrgitmType = "09"
  9700. // }
  9701. //
  9702. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9703. // if item.HisPrescriptionProject.Type == 2 {
  9704. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9705. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9706. // case 0:
  9707. // item.MedChrgitmType = "0"
  9708. // break
  9709. // case 1:
  9710. // item.MedChrgitmType = "14"
  9711. // break
  9712. // case 2:
  9713. // item.MedChrgitmType = "05"
  9714. //
  9715. // break
  9716. // case 3:
  9717. // item.MedChrgitmType = "03"
  9718. //
  9719. // break
  9720. // case 4:
  9721. // item.MedChrgitmType = "03"
  9722. //
  9723. // break
  9724. // case 5:
  9725. // item.MedChrgitmType = "08"
  9726. //
  9727. // break
  9728. // case 6:
  9729. // item.MedChrgitmType = "14"
  9730. //
  9731. // break
  9732. // case 7:
  9733. // item.MedChrgitmType = "14"
  9734. //
  9735. // break
  9736. // case 8:
  9737. // item.MedChrgitmType = "03"
  9738. // break
  9739. // case 9:
  9740. // item.MedChrgitmType = "14"
  9741. // break
  9742. // case 10:
  9743. // item.MedChrgitmType = "14"
  9744. // break
  9745. // case 11:
  9746. // item.MedChrgitmType = "06"
  9747. // break
  9748. // case 12:
  9749. // item.MedChrgitmType = "12"
  9750. // break
  9751. // case 13:
  9752. // item.MedChrgitmType = "01"
  9753. // break
  9754. // case 14:
  9755. // item.MedChrgitmType = "04"
  9756. // break
  9757. // case 15:
  9758. // item.MedChrgitmType = "02"
  9759. // break
  9760. //
  9761. // }
  9762. //
  9763. // } else {
  9764. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9765. //
  9766. // case 1:
  9767. // item.MedChrgitmType = "14"
  9768. // break
  9769. // case 2:
  9770. // item.MedChrgitmType = "05"
  9771. //
  9772. // break
  9773. // case 3:
  9774. // item.MedChrgitmType = "03"
  9775. //
  9776. // break
  9777. // case 4:
  9778. // item.MedChrgitmType = "03"
  9779. //
  9780. // break
  9781. // case 5:
  9782. // item.MedChrgitmType = "08"
  9783. //
  9784. // break
  9785. // case 6:
  9786. // item.MedChrgitmType = "14"
  9787. //
  9788. // break
  9789. // case 7:
  9790. // item.MedChrgitmType = "14"
  9791. //
  9792. // break
  9793. // case 8:
  9794. // item.MedChrgitmType = "03"
  9795. // break
  9796. // case 9:
  9797. // item.MedChrgitmType = "14"
  9798. // break
  9799. //
  9800. // }
  9801. //
  9802. // }
  9803. //
  9804. // } else if item.HisPrescriptionProject.Type == 3 {
  9805. // item.MedChrgitmType = "08"
  9806. // }
  9807. // }
  9808. // }
  9809. //
  9810. // for _, item := range orderInfos_two {
  9811. // fmt.Println(item.MedChrgitmType)
  9812. // if item.MedChrgitmType == "01" { //床位费
  9813. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9814. // bedCostSelfTotal = bedCostTotal
  9815. // }
  9816. //
  9817. // if item.MedChrgitmType == "02" { //诊察费
  9818. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9819. // zhenChaCostSelfTotal = zhenChaCostTotal
  9820. // }
  9821. //
  9822. // if item.MedChrgitmType == "03" { //检查费
  9823. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9824. // checkCostSelfTotal = checkCostTotal
  9825. // }
  9826. //
  9827. // if item.MedChrgitmType == "04" { //化验费
  9828. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9829. // laboratoryCostSelfTotal = laboratoryCostTotal
  9830. // }
  9831. //
  9832. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9833. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9834. // treatCostSelfTotal = treatCostTotal
  9835. // }
  9836. //
  9837. // if item.MedChrgitmType == "06" { //手术费
  9838. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9839. // operationCostSelfTotal = treatCostTotal
  9840. // }
  9841. //
  9842. // if item.MedChrgitmType == "08" { //材料费
  9843. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9844. // materialCostSelfTotal = materialCostTotal
  9845. // }
  9846. //
  9847. // if item.MedChrgitmType == "09" { //西药费
  9848. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9849. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9850. // }
  9851. //
  9852. // if item.MedChrgitmType == "11" { //中成费
  9853. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9854. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9855. // }
  9856. //
  9857. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9858. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9859. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9860. // otherCostSelfTotal = otherCostTotal
  9861. // }
  9862. // } else {
  9863. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9864. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9865. // otherCostSelfTotal = otherCostTotal
  9866. // }
  9867. //
  9868. // }
  9869. //
  9870. // }
  9871. //
  9872. // } else {
  9873. // for _, item := range orderInfos {
  9874. // if item.MedChrgitmType == "01" { //床位费
  9875. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9876. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9877. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9878. // }
  9879. //
  9880. // if item.MedChrgitmType == "02" { //诊察费
  9881. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9882. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9883. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9884. // }
  9885. //
  9886. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9887. // if item.MedChrgitmType == "03" { //检查费
  9888. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9889. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9890. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9891. //
  9892. // }
  9893. // } else {
  9894. // if item.MedChrgitmType == "03" { //检查费
  9895. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9896. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9897. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9898. // }
  9899. //
  9900. // }
  9901. //
  9902. // if item.MedChrgitmType == "04" { //化验费
  9903. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9904. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9905. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9906. //
  9907. // }
  9908. //
  9909. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9910. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9911. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9912. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9913. //
  9914. // }
  9915. //
  9916. // if item.MedChrgitmType == "06" { //手术费
  9917. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9918. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9919. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9920. // }
  9921. //
  9922. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9923. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9924. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9925. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9926. // }
  9927. //
  9928. // if item.MedChrgitmType == "09" { //西药费
  9929. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9930. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9931. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9932. // }
  9933. //
  9934. // if item.MedChrgitmType == "11" { //中成费
  9935. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9936. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9937. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9938. // }
  9939. //
  9940. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9941. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9942. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9943. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9944. // }
  9945. //
  9946. // }
  9947. // }
  9948. // timeLayout := "2006-01-02"
  9949. // loc, _ := time.LoadLocation("Local")
  9950. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9951. // if err != nil {
  9952. // }
  9953. // startRecordDateTime := startTime.Unix()
  9954. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9955. // if err != nil {
  9956. // }
  9957. // endRecordDateTime := endTime.Unix()
  9958. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9959. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9960. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9961. //
  9962. // c.ServeSuccessJSON(map[string]interface{}{
  9963. // "order_number": order.Number, //业务流水号
  9964. // "id_card_no": his.IdCardNo, //社会保障号
  9965. // "department_name": department.Name, //科室
  9966. // "number": his.Number, //门诊号
  9967. // "date": order.SettleAccountsDate, //结算日期
  9968. // "name": order.PsnName, //姓名
  9969. // "gender": patient.Gender, //性别
  9970. // "psn_cash_money": order.PsnCashPay, //个人支付
  9971. // "pay_way": "门诊", //结算方式
  9972. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9973. // "admin_user_name": admin.UserName, //收款员
  9974. // "order": order,
  9975. // "order_info": orderInfos_two,
  9976. // "his": his,
  9977. // "bedCostTotal": bedCostTotal,
  9978. // "bedCostSelfTotal": bedCostSelfTotal,
  9979. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9980. // "operationCostTotal": operationCostTotal,
  9981. // "operationCostSelfTotal": operationCostSelfTotal,
  9982. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9983. // "otherCostTotal": otherCostTotal,
  9984. // "otherCostSelfTotal": otherCostSelfTotal,
  9985. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9986. // "materialCostTotal": materialCostTotal,
  9987. // "materialCostSelfTotal": materialCostSelfTotal,
  9988. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9989. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9990. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9991. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9992. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9993. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9994. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9995. // "checkCostTotal": checkCostTotal,
  9996. // "checkCostSelfTotal": checkCostSelfTotal,
  9997. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9998. // "laboratoryCostTotal": laboratoryCostTotal,
  9999. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10000. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10001. // "treatCostTotal": treatCostTotal,
  10002. // "treatCostSelfTotal": treatCostSelfTotal,
  10003. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10004. // "zhenChaCostTotal": zhenChaCostTotal,
  10005. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10006. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10007. // "his_hospital_record": his_hospital_record,
  10008. // "pre_pay_money": pre_pay_money,
  10009. // "refund_sum": sum,
  10010. // })
  10011. //
  10012. //}
  10013. func (this *HisApiController) GetIncomeStatisticsData() {
  10014. start_time := this.GetString("start_time")
  10015. end_time := this.GetString("end_time")
  10016. key_words := this.GetString("key_words")
  10017. limit, _ := this.GetInt64("limit")
  10018. page, _ := this.GetInt64("page")
  10019. if page <= 0 {
  10020. page = 1
  10021. }
  10022. if limit <= 0 {
  10023. limit = 10
  10024. }
  10025. statistics_type, _ := this.GetInt64("statistics_type")
  10026. admin := this.GetAdminUserInfo()
  10027. timeLayout := "2006-01-02"
  10028. loc, _ := time.LoadLocation("Local")
  10029. var theStartTIme int64
  10030. if len(start_time) > 0 {
  10031. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10032. if err != nil {
  10033. theStartTIme = 0
  10034. }
  10035. theStartTIme = theTime.Unix()
  10036. }
  10037. var theEndtTIme int64
  10038. if len(end_time) > 0 {
  10039. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10040. if err != nil {
  10041. theEndtTIme = 0
  10042. }
  10043. theEndtTIme = theTime.Unix()
  10044. }
  10045. if statistics_type == 1 {
  10046. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10047. this.ServeSuccessJSON(map[string]interface{}{
  10048. "list": list,
  10049. "total": total,
  10050. })
  10051. } else {
  10052. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10053. this.ServeSuccessJSON(map[string]interface{}{
  10054. "list": list,
  10055. "total": total,
  10056. })
  10057. }
  10058. }
  10059. func (c *HisApiController) PostProjectInformation() {
  10060. adminUser := c.GetAdminUserInfo()
  10061. orgId := adminUser.CurrentOrgId
  10062. dataBody := make(map[string]interface{}, 0)
  10063. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10064. if err != nil {
  10065. utils.ErrorLog(err.Error())
  10066. return
  10067. }
  10068. utils.ErrorLog("%v", dataBody)
  10069. var projectList []*models.HisProject
  10070. var total_goods []interface{}
  10071. tempProjects := dataBody["projects"].([]interface{})
  10072. total_goods = tempProjects
  10073. for index, projectMap := range tempProjects {
  10074. projectM := projectMap.(map[string]interface{})
  10075. var project models.HisProject
  10076. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10077. utils.ErrorLog("project_name")
  10078. return
  10079. }
  10080. project_name, _ := projectM["project_name"].(string)
  10081. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10082. err_log := models.ExportErrLog{
  10083. LogType: 6,
  10084. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10085. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10086. Status: 1,
  10087. CreateTime: time.Now().Unix(),
  10088. UpdateTime: time.Now().Unix(),
  10089. ExportTime: time.Now().Unix(),
  10090. }
  10091. service.CreateExportErrLog(&err_log)
  10092. continue
  10093. }
  10094. project.ProjectName = project_name
  10095. prices := projectM["price"].(string)
  10096. price, _ := strconv.ParseFloat(prices, 64)
  10097. if price <= 0 { //名字为空则生成一条导入错误日志
  10098. err_log := models.ExportErrLog{
  10099. LogType: 6,
  10100. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10101. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10102. Status: 1,
  10103. CreateTime: time.Now().Unix(),
  10104. UpdateTime: time.Now().Unix(),
  10105. ExportTime: time.Now().Unix(),
  10106. }
  10107. service.CreateExportErrLog(&err_log)
  10108. continue
  10109. }
  10110. project.Price = price
  10111. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10112. utils.ErrorLog("unit_id")
  10113. return
  10114. }
  10115. unit := projectM["unit"].(string)
  10116. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10117. err_log := models.ExportErrLog{
  10118. LogType: 6,
  10119. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10120. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10121. Status: 1,
  10122. CreateTime: time.Now().Unix(),
  10123. UpdateTime: time.Now().Unix(),
  10124. ExportTime: time.Now().Unix(),
  10125. }
  10126. service.CreateExportErrLog(&err_log)
  10127. continue
  10128. }
  10129. project.Unit = unit
  10130. cost_classify := projectM["cost_classify"].(string)
  10131. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10132. err_log := models.ExportErrLog{
  10133. LogType: 6,
  10134. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10135. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10136. Status: 1,
  10137. CreateTime: time.Now().Unix(),
  10138. UpdateTime: time.Now().Unix(),
  10139. ExportTime: time.Now().Unix(),
  10140. }
  10141. service.CreateExportErrLog(&err_log)
  10142. continue
  10143. }
  10144. var costClassify = "费用类别"
  10145. var cost_classify_id int64
  10146. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10147. if len(cost_classify) != 0 {
  10148. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10149. if errcode == gorm.ErrRecordNotFound {
  10150. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10151. dataconfig := models.DictDataconfig{
  10152. ParentId: costClassifyConfig.ID,
  10153. Module: "system",
  10154. OrgId: orgId,
  10155. Name: cost_classify,
  10156. FieldName: "",
  10157. Value: costConfig.Value + 1,
  10158. CreatedTime: "",
  10159. UpdatedTime: "",
  10160. CreateUserId: adminUser.AdminUser.Id,
  10161. Status: 1,
  10162. Remark: "",
  10163. DeleteIdSystem: 0,
  10164. Title: "",
  10165. Content: "",
  10166. Order: 0,
  10167. Code: "",
  10168. }
  10169. service.CreatedDicConfig(&dataconfig)
  10170. }
  10171. }
  10172. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10173. for _, it := range costClassList {
  10174. if cost_classify == it.Name {
  10175. cost_classify_id = int64(it.Value)
  10176. }
  10177. }
  10178. project.CostClassify = cost_classify_id
  10179. executive_section := projectM["executive_section"].(string)
  10180. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10181. err_log := models.ExportErrLog{
  10182. LogType: 6,
  10183. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10184. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10185. Status: 1,
  10186. CreateTime: time.Now().Unix(),
  10187. UpdateTime: time.Now().Unix(),
  10188. ExportTime: time.Now().Unix(),
  10189. }
  10190. service.CreateExportErrLog(&err_log)
  10191. continue
  10192. }
  10193. if len(executive_section) != 0 {
  10194. //查找科室是否有内容
  10195. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10196. if errcodedepart == gorm.ErrRecordNotFound {
  10197. department := models.XtHisDepartment{
  10198. Name: executive_section,
  10199. Status: 1,
  10200. UserOrgId: adminUser.CurrentOrgId,
  10201. CreatedTime: time.Now().Unix(),
  10202. }
  10203. service.CreateDePartment(&department)
  10204. }
  10205. }
  10206. var executive_section_id int64
  10207. departMentList, _ := service.GetAllDepartMent(orgId)
  10208. for _, it := range departMentList {
  10209. if executive_section == it.Name {
  10210. executive_section_id = it.ID
  10211. }
  10212. }
  10213. project.ExecutiveSection = executive_section_id
  10214. medical_coverage := projectM["medical_coverage"].(string)
  10215. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10216. err_log := models.ExportErrLog{
  10217. LogType: 6,
  10218. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10219. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10220. Status: 1,
  10221. CreateTime: time.Now().Unix(),
  10222. UpdateTime: time.Now().Unix(),
  10223. ExportTime: time.Now().Unix(),
  10224. }
  10225. service.CreateExportErrLog(&err_log)
  10226. continue
  10227. }
  10228. var medicalCoverage = "医保等级"
  10229. var medical_coverage_id int64
  10230. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10231. if len(medical_coverage) != 0 {
  10232. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10233. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10234. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10235. dataconfig := models.DictDataconfig{
  10236. ParentId: medicalCoverageConfig.ID,
  10237. Module: "system",
  10238. OrgId: orgId,
  10239. Name: medical_coverage,
  10240. FieldName: "",
  10241. Value: medicalCoverageConfig.Value + 1,
  10242. CreatedTime: "",
  10243. UpdatedTime: "",
  10244. CreateUserId: adminUser.AdminUser.Id,
  10245. Status: 1,
  10246. Remark: "",
  10247. DeleteIdSystem: 0,
  10248. Title: "",
  10249. Content: "",
  10250. Order: 0,
  10251. Code: "",
  10252. }
  10253. service.CreatedDicConfig(&dataconfig)
  10254. }
  10255. }
  10256. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10257. for _, it := range medicalCoverageList {
  10258. if medical_coverage == it.Name {
  10259. medical_coverage_id = int64(it.Value)
  10260. }
  10261. }
  10262. project.MedicalCoverage = medical_coverage_id
  10263. pinyin := projectM["pinyin"].(string)
  10264. project.Pinyin = pinyin
  10265. wubi := projectM["wubi"].(string)
  10266. project.Wubi = wubi
  10267. statistical_classification := projectM["statistical_classification"].(string)
  10268. var statisticalClassification = "统计分类"
  10269. var statistical_classification_id int64
  10270. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10271. if len(statistical_classification) != 0 {
  10272. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10273. if classificationerrcodes == gorm.ErrRecordNotFound {
  10274. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10275. dataconfig := models.DictDataconfig{
  10276. ParentId: classiFication.ID,
  10277. Module: "system",
  10278. OrgId: orgId,
  10279. Name: statistical_classification,
  10280. FieldName: "",
  10281. Value: classiFicationConfig.Value + 1,
  10282. CreatedTime: "",
  10283. UpdatedTime: "",
  10284. CreateUserId: adminUser.AdminUser.Id,
  10285. Status: 1,
  10286. Remark: "",
  10287. DeleteIdSystem: 0,
  10288. Title: "",
  10289. Content: "",
  10290. Order: 0,
  10291. Code: "",
  10292. }
  10293. service.CreatedDicConfig(&dataconfig)
  10294. }
  10295. }
  10296. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10297. for _, it := range classiFicationList {
  10298. if statistical_classification == it.Name {
  10299. statistical_classification_id = int64(it.Value)
  10300. }
  10301. }
  10302. project.StatisticalClassification = statistical_classification_id
  10303. disease_directory := int64(projectM["disease_directory"].(float64))
  10304. project.DiseaseDirectory = disease_directory
  10305. is_record := int64(projectM["is_record"].(float64))
  10306. project.IsRecord = is_record
  10307. medical_code := projectM["medical_code"].(string)
  10308. project.MedicalCode = medical_code
  10309. tube_color := projectM["tube_color"].(string)
  10310. var tubeColor = "试管颜色"
  10311. var tube_color_id int64
  10312. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10313. if len(tube_color) != 0 {
  10314. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10315. if errcodetube == gorm.ErrRecordNotFound {
  10316. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10317. dataconfig := models.DictDataconfig{
  10318. ParentId: tubeColorConfig.ID,
  10319. Module: "system",
  10320. OrgId: orgId,
  10321. Name: tube_color,
  10322. FieldName: "",
  10323. Value: tubeConfig.Value + 1,
  10324. CreatedTime: "",
  10325. UpdatedTime: "",
  10326. CreateUserId: adminUser.AdminUser.Id,
  10327. Status: 1,
  10328. Remark: "",
  10329. DeleteIdSystem: 0,
  10330. Title: "",
  10331. Content: "",
  10332. Order: 0,
  10333. Code: "",
  10334. }
  10335. service.CreatedDicConfig(&dataconfig)
  10336. }
  10337. }
  10338. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10339. for _, it := range tubeColorList {
  10340. if tube_color == it.Name {
  10341. tube_color_id = int64(it.Value)
  10342. }
  10343. }
  10344. project.TubeColor = tube_color_id
  10345. single_dose := projectM["single_dose"].(string)
  10346. project.SingleDose = single_dose
  10347. execution_frequency := projectM["execution_frequency"].(string)
  10348. project.ExecutionFrequency = execution_frequency
  10349. delivery_way := projectM["delivery_way"].(string)
  10350. project.DeliveryWay = delivery_way
  10351. number_days := projectM["number_days"].(string)
  10352. project.NumberDays = number_days
  10353. total := projectM["total"].(string)
  10354. project.Total = total
  10355. medical_status := int64(projectM["medical_status"].(float64))
  10356. project.MedicalStatus = medical_status
  10357. category := int64(projectM["category"].(float64))
  10358. project.Category = category
  10359. specail_project := int64(projectM["specail_project"].(float64))
  10360. project.SpecailProject = specail_project
  10361. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10362. project.SocialSecurityDirectoryCode = social_security_directory_code
  10363. remark := projectM["remark"].(string)
  10364. project.Remark = remark
  10365. record_date := projectM["record_date"].(string)
  10366. timeLayout := "2006-01-02"
  10367. loc, _ := time.LoadLocation("Local")
  10368. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10369. project.RecordDate = theTime.Unix()
  10370. projectList = append(projectList, &project)
  10371. }
  10372. export_time := time.Now().Unix()
  10373. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10374. if len(projectList) > 0 {
  10375. for _, item := range projectList {
  10376. hans := item.ProjectName // 要转换的汉字字符串
  10377. // 创建一个拼音转换器
  10378. p := pinyin.NewArgs()
  10379. // 将汉字转为拼音
  10380. pinyinSlice := pinyin.Pinyin(hans, p)
  10381. // 输出拼音
  10382. fmt.Println("Pinyin:", pinyinSlice)
  10383. // 获取首字母
  10384. firstLetter := ""
  10385. for _, py := range pinyinSlice {
  10386. if len(py) > 0 {
  10387. firstLetter += string(py[0][0])
  10388. }
  10389. }
  10390. item.FirstLetter = firstLetter
  10391. project := models.HisProject{
  10392. ProjectName: item.ProjectName,
  10393. Price: item.Price,
  10394. Unit: item.Unit,
  10395. CostClassify: item.CostClassify,
  10396. ExecutiveSection: item.ExecutiveSection,
  10397. MedicalCoverage: item.MedicalCoverage,
  10398. UserOrgId: orgId,
  10399. Status: 1,
  10400. CreatedTime: time.Now().Unix(),
  10401. Pinyin: item.Pinyin,
  10402. Wubi: item.Wubi,
  10403. StatisticalClassification: item.StatisticalClassification,
  10404. DiseaseDirectory: item.DiseaseDirectory,
  10405. IsRecord: item.IsRecord,
  10406. MedicalCode: item.MedicalCode,
  10407. TubeColor: item.TubeColor,
  10408. SingleDose: item.SingleDose,
  10409. DeliveryWay: item.DeliveryWay,
  10410. NumberDays: item.NumberDays,
  10411. Total: item.Total,
  10412. Category: item.Category,
  10413. MedicalStatus: item.MedicalStatus,
  10414. SpecailProject: item.SpecailProject,
  10415. RecordDate: item.RecordDate,
  10416. Remark: item.Remark,
  10417. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10418. ExecutionFrequency: item.ExecutionFrequency,
  10419. FirstLetter: item.FirstLetter,
  10420. }
  10421. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10422. if errcodeproject == gorm.ErrRecordNotFound {
  10423. service.CreateProjectInfomation(&project)
  10424. } else if errcodeproject == nil {
  10425. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10426. }
  10427. log := models.ExportLog{
  10428. LogType: 6,
  10429. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10430. TotalNum: int64(len(total_goods)),
  10431. FailNum: int64(len(errLogs)),
  10432. SuccessNum: int64(len(projectList)),
  10433. CreateTime: time.Now().Unix(),
  10434. UpdateTime: time.Now().Unix(),
  10435. ExportTime: export_time,
  10436. Status: 1,
  10437. }
  10438. service.CreateExportLog(&log)
  10439. c.ServeSuccessJSON(map[string]interface{}{
  10440. "msg": "导入成功",
  10441. "total_num": len(total_goods),
  10442. "success_num": len(projectList),
  10443. "fail_num": int64(len(errLogs)),
  10444. })
  10445. }
  10446. } else {
  10447. log := models.ExportLog{
  10448. LogType: 6,
  10449. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10450. TotalNum: int64(len(total_goods)),
  10451. FailNum: int64(len(errLogs)),
  10452. SuccessNum: int64(len(projectList)),
  10453. CreateTime: time.Now().Unix(),
  10454. UpdateTime: time.Now().Unix(),
  10455. ExportTime: export_time,
  10456. Status: 1,
  10457. }
  10458. service.CreateExportLog(&log)
  10459. c.ServeSuccessJSON(map[string]interface{}{
  10460. "msg": "导入成功",
  10461. "total_num": len(total_goods),
  10462. "success_num": len(projectList),
  10463. "fail_num": int64(len(errLogs)),
  10464. })
  10465. }
  10466. }
  10467. //func (this *HisApiController) EditProjectInformation(){
  10468. //
  10469. // id, _ := this.GetInt64("id")
  10470. // project_team := this.GetString("project_team")
  10471. // price := this.GetString("price")
  10472. // price_float, _ := strconv.ParseFloat(price, 64)
  10473. // pinyin := this.GetString("pinyin")
  10474. // wubi := this.GetString("wubi")
  10475. // tube_color, _ := this.GetInt64("tube_color")
  10476. // team_type, _ := this.GetInt64("team_type")
  10477. // remark := this.GetString("remark")
  10478. // ids := this.GetString("ids")
  10479. // item_id := this.GetString("item_id")
  10480. // projectTeam := models.XtHisProjectTeam{
  10481. // ProjectTeam: project_team,
  10482. // Price: price_float,
  10483. // Pinyin: pinyin,
  10484. // Wubi: wubi,
  10485. // TubeColor: tube_color,
  10486. // TeamType: team_type,
  10487. // Remark: remark,
  10488. // ProjectId: ids,
  10489. // ItemId: item_id,
  10490. // }
  10491. //
  10492. //
  10493. // dataBody := make(map[string]interface{}, 0)
  10494. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10495. // if err != nil {
  10496. // utils.ErrorLog(err.Error())
  10497. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10498. // return
  10499. // }
  10500. //
  10501. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10502. //
  10503. //
  10504. // if err != nil {
  10505. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10506. // return
  10507. // }
  10508. //
  10509. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10510. // infos, _ := dataBody["info"].([]interface{})
  10511. // if len(infos) > 0 {
  10512. // var ids []string
  10513. //
  10514. // for _, item := range infos {
  10515. // items := item.(map[string]interface{})
  10516. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10517. // utils.ErrorLog("id")
  10518. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10519. // return
  10520. // }
  10521. // id := int64(items["id"].(float64))
  10522. //
  10523. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10524. // utils.ErrorLog("type")
  10525. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10526. // return
  10527. // }
  10528. // types := int64(items["type"].(float64))
  10529. //
  10530. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10531. // utils.ErrorLog("number")
  10532. // }
  10533. //
  10534. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10535. //
  10536. // projectList := models.XtHisProjectList{
  10537. // Number: number,
  10538. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10539. // ProjectId: id,
  10540. // Status: 1,
  10541. // CreatedTime: time.Now().Unix(),
  10542. // UpdatedTime: time.Now().Unix(),
  10543. // TeamId: projectTeam.ID,
  10544. // Type: types,
  10545. // }
  10546. // list := projectList
  10547. //
  10548. // service.CreateProjectList(&list)
  10549. //
  10550. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10551. //
  10552. // }
  10553. // ids_str := strings.Join(ids, ",")
  10554. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10555. // service.SaveProjectTeam(&projectTeam)
  10556. // this.ServeSuccessJSON(map[string]interface{}{
  10557. // "projectTeam": projectTeam,
  10558. // })
  10559. // }
  10560. // }
  10561. //}
  10562. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10563. name := c.GetString("name")
  10564. mode_id, _ := c.GetInt64("mode", 0)
  10565. types, _ := c.GetInt64("type", 0)
  10566. patient_id, _ := c.GetInt64("patient_id", 0)
  10567. types = 1
  10568. adminInfo := c.GetAdminUserInfo()
  10569. template := &models.HisPrescriptionTemplate{
  10570. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10571. PatientId: patient_id,
  10572. Type: types,
  10573. Status: 1,
  10574. Ctime: time.Now().Unix(),
  10575. Mtime: time.Now().Unix(),
  10576. Name: name,
  10577. Mode: mode_id,
  10578. }
  10579. dataBody := make(map[string]interface{}, 0)
  10580. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10581. if err != nil {
  10582. utils.ErrorLog(err.Error())
  10583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10584. return
  10585. }
  10586. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10587. //如果已经存在记录则删除处方
  10588. if template_one.ID > 0 {
  10589. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10590. var ids []int64
  10591. var org_id int64
  10592. for _, item := range ps {
  10593. org_id = c.GetAdminUserInfo().CurrentOrgId
  10594. ids = append(ids, item.ID)
  10595. }
  10596. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10597. if err2 == nil {
  10598. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10599. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10600. if len(prescriptions) > 0 {
  10601. for _, item := range prescriptions {
  10602. items := item.(map[string]interface{})
  10603. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10604. utils.ErrorLog("type")
  10605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10606. return
  10607. }
  10608. types := int64(items["type"].(float64))
  10609. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10610. utils.ErrorLog("med_type")
  10611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10612. return
  10613. }
  10614. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10615. ctime := time.Now().Unix()
  10616. prescription := &models.HisPrescriptionInfoTemplate{
  10617. PatientId: patient_id,
  10618. UserOrgId: adminInfo.CurrentOrgId,
  10619. Ctime: ctime,
  10620. Mtime: ctime,
  10621. Type: types,
  10622. Modifier: adminInfo.AdminUser.Id,
  10623. Creator: adminInfo.AdminUser.Id,
  10624. Status: 1,
  10625. PTemplateId: template_one.ID,
  10626. MedType: med_type,
  10627. }
  10628. service.CreateHisPrescriptionInfoTemplate(prescription)
  10629. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10630. advices := items["advices"].([]interface{})
  10631. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10632. ctime := time.Now().Unix()
  10633. mtime := ctime
  10634. if len(advices) > 0 {
  10635. for _, advice := range advices {
  10636. var s models.HisPrescriptionAdviceTemplate
  10637. s.PrescriptionId = prescription.ID
  10638. s.AdviceType = 2
  10639. s.StopState = 2
  10640. s.ExecutionState = 2
  10641. s.Status = 1
  10642. s.UserOrgId = adminInfo.CurrentOrgId
  10643. s.CreatedTime = ctime
  10644. s.UpdatedTime = mtime
  10645. s.PatientId = patient_id
  10646. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10647. if errcode > 0 {
  10648. c.ServeFailJSONWithSGJErrorCode(errcode)
  10649. return
  10650. }
  10651. service.CreateHisPrescriptionAdviceTemplate(&s)
  10652. }
  10653. }
  10654. }
  10655. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10656. projects := items["project"].([]interface{})
  10657. if len(projects) > 0 {
  10658. for _, project := range projects {
  10659. var p models.HisPrescriptionProjectTemplate
  10660. p.PrescriptionId = prescription.ID
  10661. p.Ctime = time.Now().Unix()
  10662. p.Mtime = time.Now().Unix()
  10663. p.PatientId = patient_id
  10664. p.UserOrgId = adminInfo.CurrentOrgId
  10665. p.Status = 1
  10666. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10667. if errcode > 0 {
  10668. c.ServeFailJSONWithSGJErrorCode(errcode)
  10669. return
  10670. }
  10671. service.CreateHisPrescriptionProjectTemplate(&p)
  10672. }
  10673. }
  10674. }
  10675. }
  10676. c.ServeSuccessJSON(map[string]interface{}{
  10677. "msg": "创建成功",
  10678. })
  10679. }
  10680. }
  10681. } else {
  10682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10683. return
  10684. }
  10685. } else {
  10686. err3 := service.CreateHisPrescriptionTemplate(template)
  10687. if err3 == nil {
  10688. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10689. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10690. if len(prescriptions) > 0 {
  10691. for _, item := range prescriptions {
  10692. items := item.(map[string]interface{})
  10693. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10694. utils.ErrorLog("type")
  10695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10696. return
  10697. }
  10698. types := int64(items["type"].(float64))
  10699. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10700. utils.ErrorLog("med_type")
  10701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10702. return
  10703. }
  10704. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10705. ctime := time.Now().Unix()
  10706. prescription := &models.HisPrescriptionInfoTemplate{
  10707. PatientId: patient_id,
  10708. UserOrgId: adminInfo.CurrentOrgId,
  10709. Ctime: ctime,
  10710. Mtime: ctime,
  10711. Type: types,
  10712. Modifier: adminInfo.AdminUser.Id,
  10713. Creator: adminInfo.AdminUser.Id,
  10714. Status: 1,
  10715. PTemplateId: template.ID,
  10716. MedType: med_type,
  10717. }
  10718. service.CreateHisPrescriptionInfoTemplate(prescription)
  10719. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10720. advices := items["advices"].([]interface{})
  10721. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10722. ctime := time.Now().Unix()
  10723. mtime := ctime
  10724. if len(advices) > 0 {
  10725. for _, advice := range advices {
  10726. var s models.HisPrescriptionAdviceTemplate
  10727. s.PrescriptionId = prescription.ID
  10728. s.AdviceType = 2
  10729. s.StopState = 2
  10730. s.ExecutionState = 2
  10731. s.Status = 1
  10732. s.UserOrgId = adminInfo.CurrentOrgId
  10733. s.CreatedTime = ctime
  10734. s.UpdatedTime = mtime
  10735. s.PatientId = patient_id
  10736. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10737. if errcode > 0 {
  10738. c.ServeFailJSONWithSGJErrorCode(errcode)
  10739. return
  10740. }
  10741. service.CreateHisPrescriptionAdviceTemplate(&s)
  10742. }
  10743. }
  10744. }
  10745. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10746. projects := items["project"].([]interface{})
  10747. if len(projects) > 0 {
  10748. for _, project := range projects {
  10749. var p models.HisPrescriptionProjectTemplate
  10750. p.PrescriptionId = prescription.ID
  10751. p.Ctime = time.Now().Unix()
  10752. p.Mtime = time.Now().Unix()
  10753. p.PatientId = patient_id
  10754. p.UserOrgId = adminInfo.CurrentOrgId
  10755. p.Status = 1
  10756. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10757. if errcode > 0 {
  10758. c.ServeFailJSONWithSGJErrorCode(errcode)
  10759. return
  10760. }
  10761. service.CreateHisPrescriptionProjectTemplate(&p)
  10762. }
  10763. }
  10764. }
  10765. }
  10766. c.ServeSuccessJSON(map[string]interface{}{
  10767. "msg": "创建成功",
  10768. })
  10769. }
  10770. }
  10771. } else {
  10772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10773. return
  10774. }
  10775. }
  10776. }
  10777. func (c *HisApiController) PreSettle() {
  10778. id, _ := c.GetInt64("id")
  10779. record_time := c.GetString("record_time")
  10780. his_patient_id, _ := c.GetInt64("his_patient_id")
  10781. timeLayout := "2006-01-02"
  10782. loc, _ := time.LoadLocation("Local")
  10783. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10784. diagnosis_id := c.GetString("diagnosis")
  10785. sick_type, _ := c.GetInt64("sick_type")
  10786. reg_type, _ := c.GetInt64("p_type")
  10787. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10788. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10789. if err != nil {
  10790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10791. return
  10792. }
  10793. recordDateTime := theTime.Unix()
  10794. adminUser := c.GetAdminUserInfo()
  10795. var prescriptions []*models.HisPrescription
  10796. var start_time int64
  10797. var end_time int64
  10798. ids_str := c.GetString("ids")
  10799. ids_arr := strings.Split(ids_str, ",")
  10800. fmt.Println(reg_type)
  10801. if settle_accounts_type == 1 { //日结
  10802. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10803. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10804. } else {
  10805. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10806. }
  10807. fmt.Println(prescriptions)
  10808. } else { //月结
  10809. start_time_str := c.GetString("start_time")
  10810. end_time_str := c.GetString("end_time")
  10811. timeLayout := "2006-01-02"
  10812. loc, _ := time.LoadLocation("Local")
  10813. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10814. if err != nil {
  10815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10816. return
  10817. }
  10818. recordStartTime := theStartTime.Unix()
  10819. start_time = recordStartTime
  10820. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10821. if err != nil {
  10822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10823. return
  10824. }
  10825. recordEndTime := theEndTime.Unix()
  10826. end_time = recordEndTime
  10827. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10828. }
  10829. if reg_type == 1111 || reg_type == 1112 {
  10830. reg_type = 11
  10831. }
  10832. timestamp := time.Now().Unix()
  10833. tempTime := time.Unix(timestamp, 0)
  10834. timeFormat := tempTime.Format("20060102150405")
  10835. chrgBchno := rand.Intn(100000) + 10000
  10836. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10837. strconv.FormatInt(his.PatientId, 10)
  10838. var ids []int64
  10839. for _, item := range prescriptions {
  10840. ids = append(ids, item.ID)
  10841. }
  10842. fmt.Println(ids)
  10843. var total float64
  10844. for _, item := range prescriptions {
  10845. fmt.Println(item)
  10846. if item.Type == 1 { //药品
  10847. for _, subItem := range item.HisDoctorAdviceInfo {
  10848. total = total + (subItem.Price * subItem.PrescribingNumber)
  10849. }
  10850. }
  10851. if item.Type == 2 { //项目
  10852. for _, subItem := range item.HisPrescriptionProject {
  10853. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10854. total = total + (subItem.Price * cnt)
  10855. }
  10856. }
  10857. for _, subItem := range item.HisAdditionalCharge {
  10858. total = total + (subItem.Price * float64(subItem.Count))
  10859. }
  10860. }
  10861. allTotal := fmt.Sprintf("%.2f", total)
  10862. totals, _ := strconv.ParseFloat(allTotal, 64)
  10863. order := &models.HisOrder{
  10864. UserOrgId: adminUser.CurrentOrgId,
  10865. HisPatientId: his.ID,
  10866. PatientId: id,
  10867. SettleAccountsDate: recordDateTime,
  10868. Ctime: time.Now().Unix(),
  10869. Mtime: time.Now().Unix(),
  10870. Status: 1,
  10871. OrderStatus: 1,
  10872. MdtrtId: his.Number,
  10873. Number: chrg_bchno,
  10874. MedfeeSumamt: totals,
  10875. SettleEndTime: end_time,
  10876. SettleStartTime: start_time,
  10877. SettleType: settle_accounts_type,
  10878. PsnPartAmt: totals,
  10879. PsnCashPay: totals,
  10880. PType: 2,
  10881. IsPre: 1,
  10882. MedType: strconv.Itoa(int(reg_type)),
  10883. Diagnosis: diagnosis_id,
  10884. }
  10885. err = service.CreateOrder(order)
  10886. if err != nil {
  10887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10888. return
  10889. }
  10890. var customs []*Custom
  10891. for _, item := range prescriptions {
  10892. fmt.Println(item.Type)
  10893. if item.Type == 1 { //药品
  10894. for _, subItem := range item.HisDoctorAdviceInfo {
  10895. cus := &Custom{
  10896. AdviceId: subItem.ID,
  10897. ProjectId: 0,
  10898. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10899. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10900. FeedetlSn: subItem.FeedetlSn,
  10901. Price: fmt.Sprintf("%.2f", subItem.Price),
  10902. MedListCodg: subItem.MedListCodg,
  10903. Type: 1,
  10904. }
  10905. customs = append(customs, cus)
  10906. }
  10907. }
  10908. if item.Type == 2 { //项目
  10909. for _, subItem := range item.HisPrescriptionProject {
  10910. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10911. cus := &Custom{
  10912. AdviceId: 0,
  10913. ProjectId: subItem.ID,
  10914. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10915. Cut: fmt.Sprintf("%.2f", cnt),
  10916. FeedetlSn: subItem.FeedetlSn,
  10917. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10918. MedListCodg: subItem.MedListCodg,
  10919. Type: 2,
  10920. }
  10921. customs = append(customs, cus)
  10922. }
  10923. }
  10924. for _, item := range item.HisAdditionalCharge {
  10925. cus := &Custom{
  10926. ItemId: item.ID,
  10927. AdviceId: 0,
  10928. ProjectId: 0,
  10929. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10930. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10931. FeedetlSn: item.FeedetlSn,
  10932. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10933. MedListCodg: item.XtHisAddtionConfig.Code,
  10934. Type: 3,
  10935. }
  10936. customs = append(customs, cus)
  10937. }
  10938. }
  10939. fmt.Println(customs)
  10940. for _, item := range customs {
  10941. var advice_id int64 = 0
  10942. var project_id int64 = 0
  10943. var item_id int64 = 0
  10944. var types int64 = 0
  10945. if item.Type == 1 {
  10946. advice_id = item.AdviceId
  10947. project_id = 0
  10948. item_id = 0
  10949. } else if item.Type == 2 {
  10950. advice_id = 0
  10951. item_id = 0
  10952. project_id = item.ProjectId
  10953. } else if item.Type == 3 {
  10954. advice_id = 0
  10955. item_id = item.ItemId
  10956. project_id = 0
  10957. }
  10958. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10959. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10960. pric, _ := strconv.ParseFloat(item.Price, 32)
  10961. info := &models.HisOrderInfo{
  10962. OrderNumber: order.Number,
  10963. UploadDate: time.Now().Unix(),
  10964. AdviceId: advice_id,
  10965. DetItemFeeSumamt: detItemFeeSumamt,
  10966. Cnt: cut,
  10967. Pric: pric,
  10968. PatientId: id,
  10969. Status: 1,
  10970. Mtime: time.Now().Unix(),
  10971. Ctime: time.Now().Unix(),
  10972. UserOrgId: adminUser.CurrentOrgId,
  10973. HisPatientId: his.ID,
  10974. OrderId: order.ID,
  10975. ProjectId: project_id,
  10976. Type: types,
  10977. ItemId: item_id,
  10978. }
  10979. service.CreateOrderInfo(info)
  10980. }
  10981. his.SickType = sick_type
  10982. service.UpdataHisPateint(&his)
  10983. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10984. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10985. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10986. if err == nil {
  10987. c.ServeSuccessJSON(map[string]interface{}{
  10988. "msg": "结算成功",
  10989. })
  10990. }
  10991. }
  10992. type CustomOrderInfo struct {
  10993. Name string
  10994. Spec string
  10995. Unit string
  10996. Count float64
  10997. Price float64
  10998. Total float64
  10999. }
  11000. func (c *HisApiController) GetPrivateExpensesInfo() {
  11001. order_id, _ := c.GetInt64("id", 0)
  11002. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11003. order, _ := service.GetHisOrderByID(order_id)
  11004. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11005. if order.ID == 0 {
  11006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11007. return
  11008. }
  11009. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11010. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11011. org_id := c.GetAdminUserInfo().CurrentOrgId
  11012. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11013. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11014. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11015. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11016. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11017. //var orderInfos_four []*models.HisOrderInfoTwo
  11018. //for _, item := range orderInfos_three {
  11019. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11020. // item.HisPrescriptionProject.IsCheckTeam = 1
  11021. // orderInfos_four = append(orderInfos_four, item)
  11022. //
  11023. // }
  11024. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11025. // item.HisPrescriptionProject.IsCheckTeam = 2
  11026. // orderInfos_two = append(orderInfos_two, item)
  11027. // }
  11028. //}
  11029. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11030. //var cus_slice []CustomOrderInfo
  11031. //for _, item := range new_order_info {
  11032. // var cus CustomOrderInfo
  11033. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11034. // cus.Unit = ""
  11035. // cus.Spec = ""
  11036. // var total float64
  11037. // for _, subItem := range orderInfos_four {
  11038. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11039. // total = total + subItem.DetItemFeeSumamt
  11040. // fmt.Println(subItem.DetItemFeeSumamt)
  11041. // }
  11042. // }
  11043. // cus.Count = 1
  11044. // cus.Total = total
  11045. // cus_slice = append(cus_slice, cus)
  11046. //}
  11047. orderInfos = append(orderInfos, orderInfos_two...)
  11048. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11049. //orderInfos = append(orderInfos, orderInfos_three...)
  11050. //}/**/
  11051. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11052. c.ServeSuccessJSON(map[string]interface{}{
  11053. "order": order,
  11054. "order_info": orderInfos,
  11055. "patient": patient,
  11056. "admin_info": adminInfo,
  11057. "his": his,
  11058. "current_admin": role,
  11059. "org_config": miConfig,
  11060. //"new_order_info": cus_slice,
  11061. })
  11062. }
  11063. func (this *HisApiController) ChangeMedType() {
  11064. med_type := this.GetString("med_type")
  11065. old_med_type := this.GetString("old_med_type")
  11066. ids := this.GetString("ids")
  11067. settle_type, _ := this.GetInt64("settle_type")
  11068. start_time := this.GetString("start_time")
  11069. end_time := this.GetString("end_time")
  11070. ids_arr := strings.Split(ids, ",")
  11071. if settle_type == 1 { //日结
  11072. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11073. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11074. prescription.MedType = med_type
  11075. err := service.SaveHisPrescriptionTwo(&prescription)
  11076. if err == nil {
  11077. this.ServeSuccessJSON(map[string]interface{}{
  11078. "msg": "修改成功",
  11079. })
  11080. } else {
  11081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11082. return
  11083. }
  11084. } else if settle_type == 2 {
  11085. timeLayout := "2006-01-02"
  11086. loc, _ := time.LoadLocation("Local")
  11087. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11088. if err != nil {
  11089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11090. return
  11091. }
  11092. recordStartTime := theStartTime.Unix()
  11093. start_time_timestamp := recordStartTime
  11094. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11095. if err != nil {
  11096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11097. return
  11098. }
  11099. recordEndTime := theEndTime.Unix()
  11100. end_time_timestamp := recordEndTime
  11101. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11102. if updateErr == nil {
  11103. this.ServeSuccessJSON(map[string]interface{}{
  11104. "msg": "修改成功",
  11105. })
  11106. } else {
  11107. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11108. return
  11109. }
  11110. }
  11111. }
  11112. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11113. patient_id, _ := c.GetInt64("patient_id")
  11114. his_patient_id, _ := c.GetInt64("his_patient_id")
  11115. record_date := c.GetString("record_date")
  11116. start_time := c.GetString("start_time")
  11117. end_time := c.GetString("end_time")
  11118. order_status, _ := c.GetInt64("type", 0)
  11119. p_type, _ := c.GetInt64("p_type", 0)
  11120. order_id, _ := c.GetInt64("order_id", 0)
  11121. timeLayout := "2006-01-02"
  11122. loc, _ := time.LoadLocation("Local")
  11123. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11124. if err != nil {
  11125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11126. return
  11127. }
  11128. recordDateTime := theTime.Unix()
  11129. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11130. if err != nil {
  11131. }
  11132. startRecordDateTime := startTime.Unix()
  11133. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11134. if err != nil {
  11135. }
  11136. endRecordDateTime := endTime.Unix()
  11137. admin := c.GetAdminUserInfo()
  11138. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11139. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11140. order, _ := service.GetHisOrderByID(order_id)
  11141. var monthPrescriptions []*models.HisPrescription
  11142. if order_status == 1 || order_status == 0 {
  11143. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11144. } else if order_status == 2 {
  11145. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11146. }
  11147. var settle_total float64
  11148. for _, item := range monthPrescriptions {
  11149. if len(item.HisPrescriptionProject) > 0 {
  11150. for _, subItem := range item.HisPrescriptionProject {
  11151. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11152. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11153. settle_total = settle_total + total
  11154. }
  11155. }
  11156. if len(item.HisDoctorAdviceInfo) > 0 {
  11157. for _, subItem := range item.HisDoctorAdviceInfo {
  11158. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11159. settle_total = settle_total + total
  11160. }
  11161. }
  11162. }
  11163. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11164. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11165. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11166. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11167. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11168. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11169. //获取所有科室信息
  11170. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11171. var dia string
  11172. for _, item := range month_p_info {
  11173. if len(dia) == 0 {
  11174. dia = item.Diagnosis
  11175. } else {
  11176. dia = dia + "," + item.Diagnosis
  11177. }
  11178. }
  11179. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11180. dia_arr = removeEmptyStrings(dia_arr)
  11181. c.ServeSuccessJSON(map[string]interface{}{
  11182. "his_info": his_patient_info,
  11183. "xt_info": xt_patient_info,
  11184. "case_history": case_history,
  11185. "info": patientPrescriptionInfo,
  11186. "last_info": lastPatientPrescriptionInfo,
  11187. "month_prescriptions": monthPrescriptions,
  11188. "order": order,
  11189. "doctors": doctors,
  11190. "department": department,
  11191. "settle_total": settle_total,
  11192. "dia_arr": dia_arr,
  11193. })
  11194. return
  11195. }
  11196. func removeEmptyStrings(input []string) []string {
  11197. var output []string
  11198. for _, s := range input {
  11199. if s != "" {
  11200. output = append(output, s)
  11201. }
  11202. }
  11203. return output
  11204. }
  11205. func removeDuplicates(input []string) []string {
  11206. seen := make(map[string]bool)
  11207. output := []string{}
  11208. for _, s := range input {
  11209. if _, exists := seen[s]; !exists {
  11210. seen[s] = true
  11211. output = append(output, s)
  11212. }
  11213. }
  11214. return output
  11215. }
  11216. func (c *HisApiController) GetHisMonthPatientInfo() {
  11217. patient_id, _ := c.GetInt64("patient_id")
  11218. his_patient_id, _ := c.GetInt64("his_patient_id")
  11219. record_date := c.GetString("record_date")
  11220. number := c.GetString("number")
  11221. start_time := c.GetString("start_time")
  11222. end_time := c.GetString("end_time")
  11223. p_type, _ := c.GetInt64("p_type")
  11224. timeLayout := "2006-01-02"
  11225. loc, _ := time.LoadLocation("Local")
  11226. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11227. if err != nil {
  11228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11229. return
  11230. }
  11231. recordDateTime := theTime.Unix()
  11232. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11233. if err != nil {
  11234. }
  11235. startRecordDateTime := startTime.Unix()
  11236. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11237. if err != nil {
  11238. }
  11239. endRecordDateTime := endTime.Unix()
  11240. admin := c.GetAdminUserInfo()
  11241. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11242. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11243. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11244. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11245. var settle_total float64
  11246. for _, item := range monthPrescriptions {
  11247. if len(item.HisPrescriptionProject) > 0 {
  11248. for _, subItem := range item.HisPrescriptionProject {
  11249. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11250. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11251. settle_total = settle_total + total
  11252. }
  11253. }
  11254. if len(item.HisDoctorAdviceInfo) > 0 {
  11255. for _, subItem := range item.HisDoctorAdviceInfo {
  11256. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11257. settle_total = settle_total + total
  11258. }
  11259. }
  11260. }
  11261. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11262. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11263. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11264. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11265. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11266. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11267. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11268. //获取所有科室信息
  11269. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11270. c.ServeSuccessJSON(map[string]interface{}{
  11271. "his_info": his_patient_info,
  11272. "xt_info": xt_patient_info,
  11273. "case_history": case_history,
  11274. "info": patientPrescriptionInfo,
  11275. "month_prescriptions": monthPrescriptions,
  11276. "order": order,
  11277. "doctors": doctors,
  11278. "department": department,
  11279. "count": count,
  11280. "drugStockConfig": drugStockConfig,
  11281. "last_info": lastPatientPrescriptionInfo,
  11282. "settle_total": settle_total,
  11283. })
  11284. return
  11285. }
  11286. func (c *HisApiController) GetAllOrder() {
  11287. org_id := c.GetAdminUserInfo().CurrentOrgId
  11288. orders, _ := service.GetNewHisOrderList(org_id)
  11289. c.ServeSuccessJSON(map[string]interface{}{
  11290. "order": orders,
  11291. })
  11292. return
  11293. }
  11294. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11295. newArr = make([]*models.HisOrderInfoTwo, 0)
  11296. for i := 0; i < len(arr); i++ {
  11297. repeat := false
  11298. for j := i + 1; j < len(arr); j++ {
  11299. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11300. repeat = true
  11301. break
  11302. }
  11303. }
  11304. if !repeat {
  11305. newArr = append(newArr, arr[i])
  11306. }
  11307. }
  11308. return
  11309. }
  11310. // 修改处方退库操作 参数传修改之前的处方数据
  11311. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11312. if advice.ExecutionState == 1 {
  11313. //查询该病人该药品是否有库存记录
  11314. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11315. if errcode == gorm.ErrRecordNotFound {
  11316. } else {
  11317. //退库
  11318. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11319. if advice.PrescribingNumberUnit == drug.MinUnit {
  11320. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11321. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11322. //退库
  11323. warehouseInfo := models.DrugWarehouseInfo{
  11324. StockMinNumber: prescribingNumber,
  11325. }
  11326. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11327. operation_time := time.Now().Unix()
  11328. creater := advice.AdviceDoctor
  11329. ctime := time.Now().Unix()
  11330. timeStr := time.Now().Format("2006-01-02")
  11331. timeArr := strings.Split(timeStr, "-")
  11332. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11333. total = total + 1
  11334. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11335. cancelStock := models.DrugCancelStock{
  11336. OrderNumber: orderNumber,
  11337. OperaTime: operation_time,
  11338. OrgId: advice.UserOrgId,
  11339. Creater: creater,
  11340. Ctime: ctime,
  11341. Status: 1,
  11342. ReturnTime: advice.AdviceDate,
  11343. Dealer: info.Dealer,
  11344. Manufacturer: info.Manufacturer,
  11345. Type: 1,
  11346. }
  11347. service.AddSigleDrugCancelStock(&cancelStock)
  11348. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11349. dealer, _ := service.GetDealerById(info.Dealer)
  11350. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11351. cancelStockInfo := models.DrugCancelStockInfo{
  11352. OrderNumber: cancelInfo.OrderNumber,
  11353. CancelStockId: cancelInfo.ID,
  11354. DrugId: info.DrugId,
  11355. Count: info.Count,
  11356. Status: 1,
  11357. Ctime: ctime,
  11358. OrgId: advice.UserOrgId,
  11359. Type: 1,
  11360. Manufacturer: manufactureName.ManufacturerName,
  11361. Dealer: dealer.DealerName,
  11362. Total: 0,
  11363. RetailPrice: info.RetailPrice,
  11364. RetailTotalPrice: info.RetailTotalPrice,
  11365. Price: info.Price,
  11366. RegisterAccount: "",
  11367. Remark: info.Remark,
  11368. BatchNumber: info.BatchNumber,
  11369. MaxUnit: info.CountUnit,
  11370. ProductDate: info.ProductDate,
  11371. ExpiryDate: info.ExpiryDate,
  11372. BatchNumberId: info.WarehouseInfoId,
  11373. }
  11374. flow := models.DrugFlow{
  11375. WarehousingId: 0,
  11376. DrugId: info.DrugId,
  11377. Number: "",
  11378. BatchNumber: info.BatchNumber,
  11379. Count: info.Count,
  11380. UserOrgId: advice.UserOrgId,
  11381. PatientId: 0,
  11382. SystemTime: ctime,
  11383. ConsumableType: 4,
  11384. IsSys: 0,
  11385. WarehousingOrder: "",
  11386. WarehouseOutId: 0,
  11387. WarehouseOutOrderNumber: "",
  11388. IsEdit: 0,
  11389. CancelStockId: cancelStock.ID,
  11390. CancelOrderNumber: cancelStock.OrderNumber,
  11391. Manufacturer: info.Manufacturer,
  11392. Dealer: info.Dealer,
  11393. Creator: advice.UserOrgId,
  11394. UpdateCreator: 0,
  11395. Status: 1,
  11396. Ctime: time.Now().Unix(),
  11397. Mtime: 0,
  11398. Price: info.Price,
  11399. WarehousingDetailId: 0,
  11400. WarehouseOutDetailId: 0,
  11401. CancelOutDetailId: 0,
  11402. ExpireDate: info.ExpiryDate,
  11403. ProductDate: info.ProductDate,
  11404. MaxUnit: info.CountUnit,
  11405. MinUnit: "",
  11406. }
  11407. service.CreatedCancelStock(cancelStockInfo)
  11408. service.CreateDrugFlowOne(flow)
  11409. } else {
  11410. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11411. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11412. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11413. warehouseInfo := models.DrugWarehouseInfo{
  11414. StockMinNumber: prescribingNumber,
  11415. }
  11416. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11417. }
  11418. operation_time := time.Now().Unix()
  11419. creater := advice.AdviceDoctor
  11420. ctime := time.Now().Unix()
  11421. timeStr := time.Now().Format("2006-01-02")
  11422. timeArr := strings.Split(timeStr, "-")
  11423. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11424. total = total + 1
  11425. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11426. cancelStock := models.DrugCancelStock{
  11427. OrderNumber: orderNumber,
  11428. OperaTime: operation_time,
  11429. OrgId: advice.UserOrgId,
  11430. Creater: creater,
  11431. Ctime: ctime,
  11432. Status: 1,
  11433. ReturnTime: advice.AdviceDate,
  11434. Dealer: info.Dealer,
  11435. Manufacturer: info.Manufacturer,
  11436. Type: 1,
  11437. }
  11438. service.AddSigleDrugCancelStock(&cancelStock)
  11439. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11440. dealer, _ := service.GetDealerById(info.Dealer)
  11441. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11442. cancelStockInfo := models.DrugCancelStockInfo{
  11443. OrderNumber: cancelInfo.OrderNumber,
  11444. CancelStockId: cancelInfo.ID,
  11445. DrugId: info.DrugId,
  11446. Count: info.Count,
  11447. Status: 1,
  11448. Ctime: ctime,
  11449. OrgId: advice.UserOrgId,
  11450. Type: 1,
  11451. Manufacturer: manufactureName.ManufacturerName,
  11452. Dealer: dealer.DealerName,
  11453. Total: 0,
  11454. RetailPrice: info.RetailPrice,
  11455. RetailTotalPrice: info.RetailTotalPrice,
  11456. Price: info.Price,
  11457. RegisterAccount: "",
  11458. Remark: info.Remark,
  11459. BatchNumber: info.BatchNumber,
  11460. MaxUnit: info.CountUnit,
  11461. ProductDate: info.ProductDate,
  11462. ExpiryDate: info.ExpiryDate,
  11463. BatchNumberId: info.WarehouseInfoId,
  11464. }
  11465. flow := models.DrugFlow{
  11466. WarehousingId: 0,
  11467. DrugId: info.DrugId,
  11468. Number: "",
  11469. BatchNumber: info.BatchNumber,
  11470. Count: info.Count,
  11471. UserOrgId: advice.UserOrgId,
  11472. PatientId: 0,
  11473. SystemTime: ctime,
  11474. ConsumableType: 4,
  11475. IsSys: 0,
  11476. WarehousingOrder: "",
  11477. WarehouseOutId: 0,
  11478. WarehouseOutOrderNumber: "",
  11479. IsEdit: 0,
  11480. CancelStockId: cancelStock.ID,
  11481. CancelOrderNumber: cancelStock.OrderNumber,
  11482. Manufacturer: info.Manufacturer,
  11483. Dealer: info.Dealer,
  11484. Creator: advice.AdviceDoctor,
  11485. UpdateCreator: 0,
  11486. Status: 1,
  11487. Ctime: time.Now().Unix(),
  11488. Mtime: 0,
  11489. Price: info.Price,
  11490. WarehousingDetailId: 0,
  11491. WarehouseOutDetailId: 0,
  11492. CancelOutDetailId: 0,
  11493. ExpireDate: info.ExpiryDate,
  11494. ProductDate: info.ProductDate,
  11495. MaxUnit: info.CountUnit,
  11496. MinUnit: "",
  11497. }
  11498. service.CreatedCancelStock(cancelStockInfo)
  11499. service.CreateDrugFlowOne(flow)
  11500. }
  11501. }
  11502. }
  11503. return err
  11504. }
  11505. func (this *HisApiController) DeleteNCDS() {
  11506. id, _ := this.GetInt64("id", 0)
  11507. if id > 0 {
  11508. service.DeletePsnNCDSRecordById(id)
  11509. this.ServeSuccessJSON(map[string]interface{}{
  11510. "msg": "删除成功",
  11511. })
  11512. } else {
  11513. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11514. return
  11515. }
  11516. }
  11517. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11518. id, _ := c.GetInt64("id")
  11519. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11520. c.ServeSuccessJSON(map[string]interface{}{
  11521. "advice": advice,
  11522. })
  11523. return
  11524. }
  11525. func (c *HisApiController) GetHisMonthChargePatientList() {
  11526. record_date := c.GetString("record_date")
  11527. start_time := c.GetString("start_time")
  11528. end_time := c.GetString("end_time")
  11529. timeLayout := "2006-01-02"
  11530. loc, _ := time.LoadLocation("Local")
  11531. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11532. if err != nil {
  11533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11534. return
  11535. }
  11536. if err != nil {
  11537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11538. return
  11539. }
  11540. recordDateTime := theTime.Unix()
  11541. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11542. if err != nil {
  11543. }
  11544. startRecordDateTime := startTime.Unix()
  11545. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11546. if err != nil {
  11547. }
  11548. endRecordDateTime := endTime.Unix()
  11549. adminInfo := c.GetAdminUserInfo()
  11550. var tempMonthChargePatients []*service.MonthChargePatients
  11551. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11552. for _, item := range tempPatients {
  11553. //过滤没有处方的
  11554. if len(item.HisPrescription) == 0 {
  11555. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11556. }
  11557. }
  11558. c.ServeSuccessJSON(map[string]interface{}{
  11559. "list": tempMonthChargePatients,
  11560. })
  11561. }
  11562. // PrescriptionDifference 医嘱数量差值结构体
  11563. type PrescriptionDrugDifference struct {
  11564. DrugID int64 //基础库药品id
  11565. ID int64 //医嘱id
  11566. Difference float64 //差值
  11567. Unit string //单位
  11568. }
  11569. type PrescriptionGoodDifference struct {
  11570. GoodID int64 //基础库项目耗材id
  11571. ID int64 //医嘱id
  11572. Difference int64 //差值
  11573. Unit string //单位
  11574. Type int64 //类型
  11575. }
  11576. type EditCustomData struct {
  11577. adviceList []*models.HisDoctorAdviceInfo
  11578. projectList []*models.HisPrescriptionProject
  11579. }
  11580. type SrcCustomData struct {
  11581. adviceList []*models.HisDoctorAdviceInfo
  11582. projectList []*models.HisPrescriptionProject
  11583. }
  11584. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11585. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11586. differences := make([]*PrescriptionDrugDifference, 0)
  11587. // 创建一个 map 来存储第一个切片中的药品信息
  11588. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11589. for _, advice := range firstPrescription {
  11590. firstMap[advice.DrugId] = advice
  11591. }
  11592. // 遍历第二个切片中的药品信息,并比较数量差值
  11593. for _, advice := range secondPrescription {
  11594. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11595. diff := &PrescriptionDrugDifference{
  11596. DrugID: advice.DrugId,
  11597. ID: firstAdvice.ID,
  11598. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11599. Unit: firstAdvice.PrescribingNumberUnit,
  11600. }
  11601. differences = append(differences, diff)
  11602. }
  11603. }
  11604. return differences
  11605. }
  11606. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11607. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11608. differences := make([]*PrescriptionGoodDifference, 0)
  11609. // 创建一个 map 来存储第一个切片中的耗材信息
  11610. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11611. for _, good := range firstPrescription {
  11612. firstMap[good.ProjectId] = good
  11613. }
  11614. // 遍历第二个切片中的耗材信息,并比较数量差值
  11615. for _, good := range secondPrescription {
  11616. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11617. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11618. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11619. diff := &PrescriptionGoodDifference{
  11620. GoodID: good.ProjectId,
  11621. ID: firstGood.ID,
  11622. Difference: count - firstCount,
  11623. Unit: firstGood.Unit,
  11624. Type: firstGood.Type,
  11625. }
  11626. differences = append(differences, diff)
  11627. }
  11628. }
  11629. return differences
  11630. }
  11631. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11632. var adviceList []*models.HisDoctorAdviceInfo
  11633. var projectList []*models.HisPrescriptionProject
  11634. var advice_ids []int64
  11635. var project_ids []int64
  11636. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11637. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11638. //var tempPrescription *models.HisPrescriptionProjectscription
  11639. if len(prescriptions) > 0 {
  11640. for _, item := range prescriptions {
  11641. items := item.(map[string]interface{})
  11642. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11643. advices := items["advices"].([]interface{})
  11644. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11645. groupNo := int64(0)
  11646. ctime := time.Now().Unix()
  11647. mtime := ctime
  11648. if len(advices) > 0 {
  11649. for _, advice := range advices {
  11650. var s models.HisDoctorAdviceInfo
  11651. s.AdviceType = 2
  11652. s.StopState = 2
  11653. s.ExecutionState = 2
  11654. s.Status = 1
  11655. s.Groupno = groupNo
  11656. s.CreatedTime = ctime
  11657. s.UpdatedTime = mtime
  11658. s.IsSettle = 2
  11659. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11660. //存储切片中
  11661. if s.ID > 0 {
  11662. advice_ids = append(advice_ids, s.ID)
  11663. adviceList = append(adviceList, &s)
  11664. }
  11665. }
  11666. }
  11667. }
  11668. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11669. projects := items["project"].([]interface{})
  11670. if len(projects) > 0 {
  11671. for _, project := range projects {
  11672. var p models.HisPrescriptionProject
  11673. p.Ctime = time.Now().Unix()
  11674. p.Mtime = time.Now().Unix()
  11675. p.Status = 1
  11676. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11677. if p.ID > 0 {
  11678. project_ids = append(project_ids, p.ID)
  11679. projectList = append(projectList, &p)
  11680. }
  11681. }
  11682. }
  11683. }
  11684. }
  11685. }
  11686. }
  11687. editCustomData.projectList = projectList
  11688. editCustomData.adviceList = adviceList
  11689. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11690. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11691. srcCustomData.adviceList = list
  11692. srcCustomData.projectList = list2
  11693. return
  11694. }