his_api_controller.go 173KB

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