his_api_controller.go 244KB

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