his_api_controller.go 247KB

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