his_api_controller.go 185KB

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