his_api_controller.go 299KB

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