his_api_controller.go 178KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183
  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. "math/rand"
  11. "reflect"
  12. "strconv"
  13. "strings"
  14. "syscall"
  15. "time"
  16. "unsafe"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. "github.com/shopspring/decimal"
  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. }