his_api_controller.go 308KB

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