his_api_controller.go 178KB

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