his_api_controller.go 314KB

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