his_api_controller.go 213KB

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