his_service.go 203KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608
  1. package service
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. "XT_New/models"
  7. "github.com/jinzhu/gorm"
  8. )
  9. type VMSchedule struct {
  10. ID int64 `gorm:"column:id" json:"id" form:"id"`
  11. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  12. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  13. Status int64 `gorm:"column:status" json:"status" form:"status"`
  14. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  15. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  16. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  17. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  18. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  19. }
  20. func (VMSchedule) TableName() string {
  21. return "xt_schedule"
  22. }
  23. type HisPatient struct {
  24. ID int64 `gorm:"column:id" json:"id" form:"id"`
  25. Name string `gorm:"column:name" json:"name" form:"name"`
  26. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  27. Total float64 `gorm:"column:total" json:"total" form:"total"`
  28. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  29. Status int64 `gorm:"column:status" json:"status" form:"status"`
  30. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  31. HisPrescription []*HisPrescription `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  32. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  33. Number string `gorm:"column:number" json:"number" form:"number"`
  34. VMHisOrders []*VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"orders"`
  35. VMHisOrder VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"order"`
  36. }
  37. func (HisPatient) TableName() string {
  38. return "his_patient"
  39. }
  40. type VMHisPrescriptionInfo struct {
  41. ID int64 `gorm:"column:id" json:"id" form:"id"`
  42. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  43. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  44. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  45. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  46. Status int64 `gorm:"column:status" json:"status" form:"status"`
  47. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  48. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  49. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  50. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  51. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  52. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  53. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  54. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  55. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  56. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  57. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  58. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  59. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  60. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  61. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  62. }
  63. func (VMHisPrescriptionInfo) TableName() string {
  64. return "his_prescription_info"
  65. }
  66. type VMHisOrder struct {
  67. ID int64 `gorm:"column:id" json:"id" form:"id"`
  68. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  69. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  70. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  71. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  72. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  73. Status int64 `gorm:"column:status" json:"status" form:"status"`
  74. Number string `gorm:"column:number" json:"number" form:"number"`
  75. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  76. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  77. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  78. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  79. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  80. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  81. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  82. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  83. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  84. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  85. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  86. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  87. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  88. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  89. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  90. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  91. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  92. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  93. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  94. }
  95. func (VMHisOrder) TableName() string {
  96. return "his_order"
  97. }
  98. type Patients struct {
  99. ID int64 `gorm:"column:id" json:"id" form:"id"`
  100. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  101. Name string `gorm:"column:name" json:"name" form:"name"`
  102. Status int64 `gorm:"column:status" json:"status" form:"status"`
  103. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  104. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  105. Phone int64 `gorm:"column:phone" json:"phone" form:"phone"`
  106. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  107. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  108. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  109. HisPatient HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  110. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  111. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  112. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
  113. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  114. }
  115. func (Patients) TableName() string {
  116. return "xt_patients"
  117. }
  118. type HisPrescription struct {
  119. ID int64 `gorm:"column:id" json:"id" form:"id"`
  120. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  121. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  122. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  123. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  124. Status int64 `gorm:"column:status" json:"status" form:"status"`
  125. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  126. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  127. }
  128. func (HisPrescription) TableName() string {
  129. return "his_prescription"
  130. }
  131. func GetScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*Patients, err error) {
  132. db := readDb.Model(&Patients{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,xt_patients.first_letter,xt_patients.patient_type,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  133. if sch_type != 0 {
  134. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
  135. } else {
  136. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? ", record_date, org_id)
  137. }
  138. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  139. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  140. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Group("xt_patients.id").Order("sch_type").Find(&patients).Error
  141. return
  142. }
  143. func GetChargeHisPatientListOne(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  144. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  145. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  146. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  147. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  148. return
  149. }
  150. func GetAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  151. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  152. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  153. db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  154. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  155. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  156. return
  157. }
  158. func GetChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  159. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  160. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  161. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  162. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  163. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  164. return
  165. }
  166. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  167. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  168. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  169. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  170. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  171. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  172. return
  173. }
  174. type PatientTwo struct {
  175. ID int64 `gorm:"column:id" json:"id" form:"id"`
  176. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  177. Name string `gorm:"column:name" json:"name" form:"name"`
  178. Status int64 `gorm:"column:status" json:"status" form:"status"`
  179. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  180. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  181. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  182. HisPatient []*HisPatientTwo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  183. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  184. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  185. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  186. }
  187. func (PatientTwo) TableName() string {
  188. return "xt_patients"
  189. }
  190. type PatientThree struct {
  191. ID int64 `gorm:"column:id" json:"id" form:"id"`
  192. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  193. Name string `gorm:"column:name" json:"name" form:"name"`
  194. Status int64 `gorm:"column:status" json:"status" form:"status"`
  195. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  196. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  197. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  198. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  199. HisPrescription []models.HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  200. }
  201. func (PatientThree) TableName() string {
  202. return "xt_patients"
  203. }
  204. type HisPatientTwo struct {
  205. ID int64 `gorm:"column:id" json:"id" form:"id"`
  206. Name string `gorm:"column:name" json:"name" form:"name"`
  207. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  208. Total float64 `gorm:"column:total" json:"total" form:"total"`
  209. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  210. Status int64 `gorm:"column:status" json:"status" form:"status"`
  211. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  212. HisPrescriptionTwo []*HisPrescriptionTwo `gorm:"ForeignKey:PatientId,HisPatientId;AssociationForeignKey:PatientId,ID" json:"prescription"`
  213. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  214. Number string `gorm:"column:number" json:"number" form:"number"`
  215. }
  216. func (HisPatientTwo) TableName() string {
  217. return "his_patient"
  218. }
  219. type HisPrescriptionTwo struct {
  220. ID int64 `gorm:"column:id" json:"id" form:"id"`
  221. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  222. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  223. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  224. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  225. Status int64 `gorm:"column:status" json:"status" form:"status"`
  226. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  227. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  228. Number string `gorm:"column:number" json:"number" form:"number"`
  229. Type int64 `gorm:"column:type" json:"type" form:"type"`
  230. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  231. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  232. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  233. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  234. PreTime int64 `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
  235. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  236. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  237. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  238. }
  239. func (HisPrescriptionTwo) TableName() string {
  240. return "his_prescription"
  241. }
  242. func GetNewHisPatientList(org_id int64, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  243. db := readDb.Model(&PatientTwo{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  244. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  245. if sch_type > 0 {
  246. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND schedule_type = ?", record_date, org_id, sch_type)
  247. }
  248. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  249. return db.Preload("HisPrescriptionTwo", "status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Where("user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  250. })
  251. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("id").Find(&patients).Error
  252. return
  253. }
  254. func GetNewHisPatientListTwo(org_id int64, record_date int64, sch_type int64) (patients []*PatientThree, err error) {
  255. db := readDb.Model(&PatientThree{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  256. //if sch_type > 0 {
  257. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ?", record_date, org_id)
  258. //}
  259. err = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? and his_patient_id = 0", org_id, record_date).Group("id").Find(&patients).Error
  260. return
  261. }
  262. func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  263. db := readDb.Model(&PatientTwo{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  264. if sch_type != 0 {
  265. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
  266. } else {
  267. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? ", record_date, org_id)
  268. }
  269. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  270. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("xt_patients.id").Order("sch_type").Find(&patients).Error
  271. return
  272. }
  273. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  274. err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&drugs).Error
  275. return
  276. }
  277. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  278. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  279. return
  280. }
  281. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  282. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  283. return
  284. }
  285. func GetHisPatientInfoThree(org_id int64, number string) (info models.HisPatient, err error) {
  286. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND number = ?", org_id, number).First(&info).Error
  287. return
  288. }
  289. func GetHisPatientInfoTen(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  290. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Last(&info).Error
  291. return
  292. }
  293. func GetHisPatientInfoFour(org_id int64, patient_id int64, record_date int64, his_patient_id int64) (info models.HisPatient, err error) {
  294. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND id = ?", org_id, record_date, patient_id, his_patient_id).First(&info).Error
  295. return
  296. }
  297. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  298. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  299. return
  300. }
  301. func GetNewHisPatientInfoTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  302. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  303. return
  304. }
  305. func GetNewHisHosptialRecordTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  306. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  307. return
  308. }
  309. func GetHisPatientCount(org_id int64, patient_id int64, record_date int64) (total int64, err error) {
  310. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Count(&total).Error
  311. return
  312. }
  313. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  314. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  315. return
  316. }
  317. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  318. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Last(&info).Error
  319. return
  320. }
  321. func GetLastHisPatientCaseHistory(org_id int64, patient_id int64) (models.HisPatientCaseHistory, error) {
  322. patientCaseHistory := models.HisPatientCaseHistory{}
  323. err := readDb.Where("user_org_id =? and status= 1 and patient_id = ?", org_id, patient_id).Last(&patientCaseHistory).Error
  324. return patientCaseHistory, err
  325. }
  326. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  327. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  328. err = db.Find(&caseHistorys).Error
  329. return
  330. }
  331. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  332. likekey := "%" + keyword + "%"
  333. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  334. if startime > 0 {
  335. db = db.Where("record_date>=?", startime)
  336. }
  337. if endtime > 0 {
  338. db = db.Where("record_date<=?", endtime)
  339. }
  340. if len(keyword) > 0 {
  341. db = db.Where("template_name like ? ", likekey)
  342. }
  343. err = db.Find(&caseHistorys).Error
  344. return
  345. }
  346. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  347. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  348. return caseHistory, err
  349. }
  350. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  351. err = writeDb.Create(&template).Error
  352. return
  353. }
  354. func GetHisPatientCaseHistoryById(patient_id int64, record_date int64, user_org_id int64) (*models.HisPatientCaseHistory, error) {
  355. history := models.HisPatientCaseHistory{}
  356. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1 and user_org_id = ? and record_date = ?", patient_id, user_org_id, record_date).Find(&history).Error
  357. if err != nil {
  358. if err == gorm.ErrRecordNotFound {
  359. return nil, err
  360. } else {
  361. return nil, err
  362. }
  363. }
  364. return &history, nil
  365. }
  366. func GetLastHisPatientCaseHistoryById(patient_id int64) (models.HisPatientCaseHistory, error) {
  367. history := models.HisPatientCaseHistory{}
  368. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1", patient_id).Last(&history).Error
  369. return history, err
  370. }
  371. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  372. err := writeDb.Create(&caseHistory).Error
  373. return err
  374. }
  375. func UpdatePatientCaseHistory(patient_id int64, record_date int64, user_org_id int64, his *models.HisPatientCaseHistory) error {
  376. err := XTWriteDB().Model(&his).Where("patient_id = ? and record_date = ? and user_org_id = ? and status =1", patient_id, record_date, user_org_id).Updates(map[string]interface{}{"temperature": his.Temperature, "blood_sugar": his.BloodSugar, "pulse": his.Pulse, "allergic_history": his.AllergicHistory, "diagnose": his.AllergicHistory, "sick": his.Sick, "remark": his.Remark, "doctor_advice": his.DoctorAdvice, "breathing": his.Breathing, "delivery_way": his.DeliveryWay, "diagnostic": his.Diagnostic, "family_history": his.FamilyHistory, "personal_history": his.PersonalHistory, "chief_conplaint": his.ChiefConplaint, "doctor": his.Doctor, "past_history": his.PastHistory, "history_of_present_illness": his.HistoryOfPresentIllness, "is_infect": his.IsInfect, "sick_date": his.SickDate, "symptom": his.Symptom, "sick_type": his.SickType, "blood_fat": his.BloodFat, "sbp": his.Sbp, "dbp": his.Dbp, "primary_disease": his.PrimaryDisease, "confirm_failure_date": his.ConfirmFailureDate, "drug_allergy_history": his.DrugAllergyHistory, "physical_examination": his.PhysicalExamination, "special_inspection": his.SpecialInspection, "lab_apparatus": his.LabApparatus}).Error
  377. return err
  378. }
  379. func SaveHisPrescriptionOne(tx *gorm.DB, prescription *models.HisPrescription) (err error) {
  380. err = tx.Model(&models.HisPrescription{}).Save(prescription).Error
  381. if err != nil {
  382. tx.Rollback()
  383. return
  384. }
  385. tx.Commit()
  386. return
  387. }
  388. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  389. err = writeDb.Model(&models.HisPrescription{}).Save(prescription).Error
  390. return err
  391. }
  392. func SaveHisPrescriptionTwo(prescription *models.HisPrescription) (err error) {
  393. err = writeDb.Model(&models.HisPrescription{}).Save(prescription).Error
  394. return
  395. }
  396. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  397. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  398. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  399. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  400. return
  401. }
  402. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  403. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  404. return
  405. }
  406. func DelelteProject(id int64, user_org_id int64) (err error) {
  407. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  408. return
  409. }
  410. func GetHisPrescription(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  411. err = readDb.Model(&models.HisPrescription{}).
  412. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  413. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  414. }).
  415. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  416. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  417. }).
  418. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  419. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  420. }).
  421. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ?", org_id, record_date, patient_id, p_type).
  422. Find(&prescription).Error
  423. return
  424. }
  425. func GetNewHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  426. err = readDb.Model(&models.HisPrescription{}).
  427. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  428. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  429. }).
  430. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  431. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  432. }).
  433. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  434. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  435. }).
  436. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND his_patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, his_patient_id, p_type).
  437. Find(&prescription).Error
  438. return
  439. }
  440. func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  441. err = readDb.Model(&models.HisPrescription{}).
  442. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  443. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  444. }).
  445. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  446. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  447. }).
  448. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  449. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  450. }).
  451. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2 AND his_patient_id = ? AND p_type = ?", org_id, record_date, patient_id, his_patient_id, p_type).
  452. Find(&prescription).Error
  453. return
  454. }
  455. func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  456. err = readDb.Model(&models.HisPrescription{}).
  457. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  458. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  459. }).
  460. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  461. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  462. }).
  463. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  464. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  465. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  466. return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3 AND order_status <> 2 ", org_id)
  467. }).
  468. Where("(user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?) AND (his_patient_id = ? OR his_patient_id = 0)", org_id, record_date, patient_id, p_type, his_patient_id).
  469. Find(&prescription).Error
  470. return
  471. }
  472. func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  473. err = readDb.Model(&models.HisPrescription{}).
  474. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  475. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  476. }).
  477. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  478. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  479. }).
  480. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  481. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  482. }).
  483. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  484. Find(&prescription).Error
  485. return
  486. }
  487. func GetSettleHisPrescriptionTX(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  488. err = tx.Model(&models.HisPrescription{}).
  489. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  490. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  491. }).
  492. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  493. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  494. }).
  495. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  496. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  497. }).
  498. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  499. Find(&prescription).Error
  500. return
  501. }
  502. func GetSettleHisPrescriptionTXOne(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  503. err = tx.Model(&models.HisPrescription{}).
  504. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  505. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  506. }).
  507. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  508. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  509. }).
  510. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  511. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  512. }).
  513. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  514. Find(&prescription).Error
  515. return
  516. }
  517. func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  518. err = readDb.Model(&models.HisPrescription{}).
  519. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  520. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  521. }).
  522. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  523. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  524. }).
  525. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  526. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  527. }).
  528. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
  529. Find(&prescription).Error
  530. return
  531. }
  532. func GetMonthHisPrescriptionTX(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  533. err = tx.Model(&models.HisPrescription{}).
  534. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  535. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  536. }).
  537. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  538. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  539. }).
  540. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  541. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  542. }).
  543. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
  544. Find(&prescription).Error
  545. return
  546. }
  547. func GetMonthHisPrescriptionTXOne(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  548. err = tx.Model(&models.HisPrescription{}).
  549. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  550. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  551. }).
  552. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  553. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  554. }).
  555. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  556. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  557. }).
  558. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
  559. Find(&prescription).Error
  560. return
  561. }
  562. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  563. err = readDb.Model(&models.HisPrescription{}).
  564. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  565. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  566. }).
  567. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  568. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  569. }).
  570. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  571. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  572. }).
  573. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  574. Find(&prescription).Error
  575. return
  576. }
  577. func GetMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  578. err = readDb.Model(&models.HisPrescription{}).
  579. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  580. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  581. }).
  582. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  583. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  584. }).
  585. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  586. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  587. }).
  588. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? ", org_id, start_date, end_date, patient_id, p_type).
  589. Find(&prescription).Error
  590. return
  591. }
  592. // 未收费
  593. func GetUnChargeMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  594. err = readDb.Model(&models.HisPrescription{}).
  595. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  596. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  597. }).
  598. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  599. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  600. }).
  601. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  602. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  603. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  604. return db.Where("status = 1 AND user_org_id = ?", org_id)
  605. }).
  606. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND order_status <> 4 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  607. Find(&prescription).Error
  608. return
  609. }
  610. // 已收费
  611. func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  612. err = readDb.Model(&models.HisPrescription{}).
  613. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  614. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  615. }).
  616. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  617. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  618. }).
  619. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  620. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  621. }).
  622. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  623. Find(&prescription).Error
  624. return
  625. }
  626. func GetUnChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
  627. err = readDb.Model(&models.HisPrescription{}).
  628. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  629. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  630. }).
  631. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  632. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  633. }).
  634. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  635. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  636. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  637. return db.Where("status = 1 AND user_org_id = ?", org_id)
  638. }).
  639. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND order_status <> 4", org_id, start_date, end_date, patient_id).
  640. Find(&prescription).Error
  641. return
  642. }
  643. type OtherDrugWarehouseInfo struct {
  644. ID int64 `gorm:"column:id" json:"id" form:"id"`
  645. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  646. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  647. Status int64 `gorm:"column:status" json:"status" form:"status"`
  648. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  649. StockMaxNumber int64 `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
  650. StockMinNumber int64 `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
  651. Price float64 `gorm:"column:price" json:"price" form:"price"`
  652. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  653. }
  654. func (OtherDrugWarehouseInfo) TableName() string {
  655. return "xt_drug_warehouse_info"
  656. }
  657. type VMDrugSalesReturnInfo struct {
  658. ID int64 `gorm:"column:id" json:"id" form:"id"`
  659. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  660. Count int64 `gorm:"column:count" json:"count" form:"count"`
  661. Status int64 `gorm:"column:status" json:"status" form:"status"`
  662. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  663. }
  664. func (VMDrugSalesReturnInfo) TableName() string {
  665. return "xt_drug_sales_return_info"
  666. }
  667. type VMDrugWarehouseOutInfo struct {
  668. ID int64 `gorm:"column:id" json:"id" form:"id"`
  669. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  670. Count int64 `gorm:"column:count" json:"count" form:"count"`
  671. Status int64 `gorm:"column:status" json:"status" form:"status"`
  672. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  673. }
  674. func (VMDrugWarehouseOutInfo) TableName() string {
  675. return "xt_drug_warehouse_out_info"
  676. }
  677. type VMDrugCancelStockInfo struct {
  678. ID int64 `gorm:"column:id" json:"id" form:"id"`
  679. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  680. Count int64 `gorm:"column:count" json:"count" form:"count"`
  681. Status int64 `gorm:"column:status" json:"status" form:"status"`
  682. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  683. }
  684. func (VMDrugCancelStockInfo) TableName() string {
  685. return "xt_drug_cancel_stock_info"
  686. }
  687. type BaseDrugLib struct {
  688. ID int64 `gorm:"column:id" json:"id" form:"id"`
  689. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  690. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  691. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  692. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  693. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  694. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  695. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  696. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  697. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  698. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  699. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  700. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  701. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  702. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  703. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  704. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  705. Dose string `gorm:"column:dose" json:"dose" form:"dose"`
  706. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  707. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  708. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  709. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  710. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  711. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  712. Number string `gorm:"column:number" json:"number" form:"number"`
  713. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  714. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  715. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  716. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  717. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  718. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  719. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  720. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  721. Code string `gorm:"column:code" json:"code" form:"code"`
  722. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  723. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  724. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  725. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  726. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  727. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  728. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  729. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  730. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  731. Label int64 `gorm:"column:label" json:"label" form:"label"`
  732. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  733. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  734. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  735. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  736. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  737. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  738. Status int64 `gorm:"column:status" json:"status" form:"status"`
  739. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  740. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  741. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  742. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  743. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  744. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  745. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  746. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  747. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  748. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  749. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  750. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  751. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  752. //Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  753. //Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  754. //PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  755. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  756. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  757. Total float64 `gorm:"column:total" json:"total" form:"total"`
  758. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  759. BatchRetaiPrice float64 `gorm:"column:batch_retai_price" json:"batch_retai_price" form:"batch_retai_price"`
  760. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  761. SumCount int64 `gorm:"column:sum_count" json:"sum_count" form:"sum_count"`
  762. SumInCount int64 `gorm:"column:sum_in_count" json:"sum_in_count" form:"sum_in_count"`
  763. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  764. Bby01 string `gorm:"column:bby01" json:"bby01" form:"bby01"`
  765. IsProject int64 `gorm:"column:is_project" json:"is_project" form:"is_project"`
  766. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  767. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  768. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  769. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  770. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  771. }
  772. func (BaseDrugLib) TableName() string {
  773. return "xt_base_drug"
  774. }
  775. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  776. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  777. return db.Where("(status = 1 and stock_max_number > 0) or (status = 1 AND stock_min_number >0)")
  778. }).Find(&list).Error
  779. //err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Find(&list).Error
  780. return
  781. }
  782. func GetAllDrugLibListSix(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  783. if org_id == 10598 {
  784. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  785. return db.Where("(status = 1 and stock_max_number > 0 and storehouse_id = ? ) or (status = 1 AND stock_min_number >0 and storehouse_id = ?)", storehouse_id, storehouse_id)
  786. }).Order("sort asc").Find(&list).Error
  787. return
  788. } else {
  789. if org_id == 10489 {
  790. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0 AND sum_count >0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  791. return db.Where("(status = 1 and stock_max_number > 0 and storehouse_id = ? ) or (status = 1 AND stock_min_number >0 and storehouse_id = ?)", storehouse_id, storehouse_id)
  792. }).Order("sort asc").Find(&list).Error
  793. return
  794. } else {
  795. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  796. return db.Where("(status = 1 and stock_max_number > 0 and storehouse_id = ? ) or (status = 1 AND stock_min_number >0 and storehouse_id = ?)", storehouse_id, storehouse_id)
  797. }).Order("sort asc").Find(&list).Error
  798. return
  799. }
  800. }
  801. }
  802. func GetAllDrugLibListSeven(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  803. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  804. return db.Where("(status = 1 and storehouse_id = ? ) or (status = 1 and storehouse_id = ?)", storehouse_id, storehouse_id)
  805. }).Find(&list).Error
  806. return
  807. }
  808. func GetAllDrugLibs(org_id int64) (drugs []*Drugs, err error) {
  809. db := readDb.Model(&models.BaseDrugLib{}).Preload("Drugs", "status = 1 AND org_id = ? AND find_in_set('停用',drug_status) = 0", org_id).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Group("drug_name")
  810. err = db.Find(&drugs).Error
  811. return
  812. }
  813. func GetAllProjectList(org_id int64, keyword string) (list []*models.HisProject, err error) {
  814. if len(keyword) != 0 {
  815. key := "%" + keyword + "%"
  816. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 AND project_name Like ? ", org_id, key).Find(&list).Error
  817. } else {
  818. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 ", org_id).Find(&list).Error
  819. }
  820. return
  821. }
  822. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  823. err = writeDb.Create(&charge).Error
  824. return
  825. }
  826. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  827. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  828. return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,way,drug_id,drug_name_id, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
  829. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  830. return
  831. }
  832. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  833. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  834. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  835. }).Where("org_id = ? AND status = 1 AND user_type = 2", org_id).Find(&doctors).Error
  836. return
  837. }
  838. func CreateHisDoctorAdviceOne(s *models.HisDoctorAdviceInfo, tx *gorm.DB) (err error) {
  839. err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error
  840. if err != nil {
  841. tx.Rollback()
  842. return
  843. }
  844. return
  845. }
  846. func GetHisToday(patient_id int64, advice_date int64, user_org_id int64, drug_id int64, tx *gorm.DB) (list []*models.HisDoctorAdviceInfo, err error) {
  847. err = tx.Where("patient_id = ? and advice_date = ? and user_org_id = ? and status =1 and drug_id = ?", patient_id, advice_date, user_org_id, drug_id).Find(&list).Error
  848. if err != gorm.ErrRecordNotFound {
  849. if err != nil {
  850. tx.Rollback()
  851. return list, err
  852. }
  853. }
  854. return list, err
  855. }
  856. func GetLastDrugAuto(advice_id int64, drug_id int64, advice_date int64, patient_id int64, user_org_id int64, tx *gorm.DB) (models.DrugAutomaticReduceDetail, error) {
  857. automaticReduceDetail := models.DrugAutomaticReduceDetail{}
  858. err := XTReadDB().Where("advice_id = ? and drug_id = ? and record_time= ? and patient_id =? and status=1 and org_id = ?", advice_id, drug_id, advice_date, patient_id, user_org_id).Find(&automaticReduceDetail).Error
  859. if err != gorm.ErrRecordNotFound {
  860. if err != nil {
  861. tx.Rollback()
  862. return automaticReduceDetail, err
  863. }
  864. }
  865. return automaticReduceDetail, err
  866. }
  867. func UpdateTodayHis(drug_id int64, advice_date int64, patient_id int64, user_org_id int64, min_unit string, count_total int64, id int64, tx *gorm.DB) (models.XtDrugAutomaticReduceDetail, error) {
  868. drugAutomaticReduceDetail := models.XtDrugAutomaticReduceDetail{}
  869. err = tx.Model(&drugAutomaticReduceDetail).Where("drug_id = ? and record_time = ? and patient_id =? and org_id = ? and status=1 and advice_id = ?", drug_id, advice_date, patient_id, user_org_id, id).Updates(map[string]interface{}{"count": count_total, "count_unit": min_unit}).Error
  870. if err != nil {
  871. tx.Rollback()
  872. return drugAutomaticReduceDetail, err
  873. }
  874. return drugAutomaticReduceDetail, err
  875. }
  876. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  877. tx := writeDb.Begin()
  878. if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
  879. tx.Rollback()
  880. return
  881. }
  882. tx.Commit()
  883. return
  884. }
  885. func CreateHisDoctorAdviceTwo(s *models.HisDoctorAdviceInfo) (err error) {
  886. tx := writeDb.Begin()
  887. if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
  888. tx.Rollback()
  889. return
  890. }
  891. tx.Commit()
  892. return
  893. }
  894. func CreateNewHisProjectTwo(project *models.HisPrescriptionProject, tx *gorm.DB) (err error) {
  895. err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error
  896. if err != nil {
  897. tx.Rollback()
  898. return
  899. }
  900. return
  901. }
  902. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  903. err = writeDb.Model(&models.HisPrescriptionProject{}).Save(project).Error
  904. return
  905. }
  906. func GetLastHisProject(patient_id int64, user_org_id int64, record_date int64, tx *gorm.DB, good_id int64) (models.HisPrescriptionProject, error) {
  907. prescriptionProject := models.HisPrescriptionProject{}
  908. err := tx.Where("patient_id = ? and user_org_id = ? and record_date = ? and status=1 and project_id = ? and type =3", patient_id, user_org_id, record_date, good_id).Find(&prescriptionProject).Error
  909. if err != gorm.ErrRecordNotFound {
  910. if err != nil {
  911. tx.Rollback()
  912. return prescriptionProject, err
  913. }
  914. }
  915. return prescriptionProject, err
  916. }
  917. func CreateHisProjectThree(project *models.HisPrescriptionProject) (err error) {
  918. tx := writeDb.Begin()
  919. if err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error; err != nil {
  920. tx.Rollback()
  921. return
  922. }
  923. return
  924. }
  925. func SaveNewHisProjectTwo(project *models.HisPrescriptionProject, tx *gorm.DB) (err error) {
  926. //err = tx.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn, "mtime": time.Now().Unix()}).Error
  927. if err = tx.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn}).Error; err != nil {
  928. tx.Rollback()
  929. return
  930. }
  931. return
  932. }
  933. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  934. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn}).Error
  935. return
  936. }
  937. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  938. err := writeDb.Create(&patient).Error
  939. return err
  940. }
  941. func GetVMHisPatientInfo(org_id int64, id int64, record_date int64) (info models.VMHisPatient, err error) {
  942. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  943. return
  944. }
  945. func CreateOrder(order *models.HisOrder) (err error) {
  946. err = writeDb.Create(&order).Error
  947. return
  948. }
  949. func CreateOrderTX(order *models.HisOrder, tx *gorm.DB) (err error) {
  950. err = tx.Create(&order).Error
  951. return
  952. }
  953. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  954. err = writeDb.Create(&order).Error
  955. return
  956. }
  957. func CreateOrderInfoTX(order *models.HisOrderInfo, tx *gorm.DB) (err error) {
  958. err = tx.Create(&order).Error
  959. return
  960. }
  961. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  962. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? AND his_patient_id = ? ", org_id, record_date, patient_id, p_type, his_patient_id).First(&info).Error
  963. return
  964. }
  965. func FindPatientPrescriptionInfoTen(org_id int64, patient_id int64, start_time int64, end_time int64, p_type int64) (info []models.HisPrescriptionInfo, err error) {
  966. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date >= ? and record_date <= ? AND patient_id = ? AND p_type = ?", org_id, start_time, end_time, patient_id, p_type).Find(&info).Error
  967. return
  968. }
  969. func FindPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  970. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, p_type).First(&info).Error
  971. return
  972. }
  973. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  974. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date < ? AND patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, p_type).Last(&info).Error
  975. return
  976. }
  977. func FindHisPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  978. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? AND his_patient_id = ? ", org_id, record_date, patient_id, p_type, his_patient_id).First(&info).Error
  979. return
  980. }
  981. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  982. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date < ? AND patient_id = ?", org_id, record_date, patient_id).Order("record_date desc").First(&info).Error
  983. return
  984. }
  985. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  986. err = writeDb.Model(&models.HisPrescription{}).Save(&info).Error
  987. return err
  988. }
  989. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time_timestamp int64, end_time_timestamp int64, doctor_id int64, keywords string, p_type int64, sort_type int64, start_time string, end_time string, charge_type int64, sch_type int64, zone_type int64, med_type int64) (order []*models.HisOrder, err error, total int64) {
  990. offset := (page - 1) * limit
  991. db := readDb.Model(&models.HisOrder{})
  992. if doctor_id > 0 {
  993. db = db.Joins("join his_prescription_info as info on info.patient_id = his_order.patient_id AND info.record_date = his_order.settle_accounts_date AND info.doctor_id = ? AND info.user_org_id = ?", doctor_id, user_org_id)
  994. }
  995. if len(keywords) > 0 {
  996. keywords = "%" + keywords + "%"
  997. db = db.Joins("join xt_patients as patient on patient.id = his_order.patient_id AND patient.name like ? AND patient.user_org_id = ?", keywords, user_org_id)
  998. }
  999. if sch_type > 0 && zone_type > 0 {
  1000. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_type = ? AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.partition_id = ? AND sch.status = 1", sch_type, start_time_timestamp, end_time_timestamp, zone_type)
  1001. }
  1002. if sch_type > 0 && zone_type == 0 {
  1003. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_type = ? AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.status = 1", sch_type, start_time_timestamp, end_time_timestamp)
  1004. }
  1005. if sch_type == 0 && zone_type > 0 {
  1006. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.partition_id = ? AND sch.status = 1", start_time_timestamp, end_time_timestamp, zone_type)
  1007. }
  1008. if med_type > 0 {
  1009. db = db.Where("his_order.med_type = ?", med_type)
  1010. }
  1011. //if zone_type > 0 {
  1012. // db = db.Joins("join xt_schedule sch_two on sch_two.schedule_date = his_order.settle_accounts_date AND sch_two.patient_id = his_order.patient_id AND sch_two.partition_id = ?", zone_type)
  1013. //}
  1014. if sort_type == 1 {
  1015. if start_time_timestamp != 0 {
  1016. db = db.Where("his_order.settle_accounts_date>=?", start_time_timestamp)
  1017. }
  1018. if end_time_timestamp != 0 {
  1019. db = db.Where("his_order.settle_accounts_date<=?", end_time_timestamp)
  1020. }
  1021. } else {
  1022. if len(start_time) != 0 {
  1023. db = db.Where("his_order.setl_time>=?", start_time+" 00:00:00")
  1024. }
  1025. if len(end_time) != 0 {
  1026. db = db.Where("his_order.setl_time<=?", end_time+" 23:59:59")
  1027. }
  1028. }
  1029. if p_type > 0 {
  1030. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.p_type = ? AND his_order.order_status = 2", user_org_id, p_type)
  1031. } else {
  1032. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2", user_org_id)
  1033. }
  1034. if charge_type > 0 {
  1035. if charge_type == 2 {
  1036. db = db.Where("his_order.is_medicine_insurance = 0")
  1037. } else {
  1038. db = db.Where("his_order.is_medicine_insurance = ?", charge_type)
  1039. }
  1040. }
  1041. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1042. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  1043. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  1044. Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ?", user_org_id)
  1045. db = db.Preload("HisFundSettleListResult", "status = 1")
  1046. db = db.Count(&total)
  1047. db = db.Limit(limit).Offset(offset)
  1048. if user_org_id == 10215 {
  1049. if sort_type == 1 {
  1050. err = db.Order("settle_accounts_date asc,ctime asc").Group("his_order.id").Find(&order).Error
  1051. }
  1052. if sort_type == 2 {
  1053. err = db.Order("setl_time asc,ctime asc").Group("his_order.id").Find(&order).Error
  1054. }
  1055. } else {
  1056. if sort_type == 1 {
  1057. err = db.Order("settle_accounts_date desc,ctime desc").Group("his_order.id").Find(&order).Error
  1058. }
  1059. if sort_type == 2 {
  1060. err = db.Order("setl_time desc,ctime desc").Group("his_order.id").Find(&order).Error
  1061. }
  1062. }
  1063. return
  1064. }
  1065. func GetNewHisOrderListTwo(user_org_id int64, start_time_timestamp int64, end_time_timestamp int64) (order []*models.HisOrderELE, err error) {
  1066. db := readDb.Model(&models.HisOrderELE{})
  1067. if start_time_timestamp != 0 {
  1068. db = db.Where("his_order.settle_accounts_date>=?", start_time_timestamp)
  1069. }
  1070. if end_time_timestamp != 0 {
  1071. db = db.Where("his_order.settle_accounts_date<=?", end_time_timestamp)
  1072. }
  1073. db = db.Where("user_org_id = ? and order_status = 2 and status = 1", user_org_id)
  1074. err = db.Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).Find(&order).Error
  1075. return
  1076. }
  1077. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  1078. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1079. return
  1080. }
  1081. func UpDatePrescriptionNumberTX(user_org_id int64, ids []int64, number string, tx *gorm.DB) (err error) {
  1082. err = tx.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1083. return
  1084. }
  1085. func UpDateAddtionNumber(user_org_id int64, ids []int64, number string) (err error) {
  1086. err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1087. return
  1088. }
  1089. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  1090. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date = ?", user_org_id, id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1091. return
  1092. }
  1093. func UpDateHisPrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64) (err error) {
  1094. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ? AND record_date = ?", user_org_id, his_patient_id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1095. return
  1096. }
  1097. func UpDateHisPrescriptionInfoNumberTX(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64, tx *gorm.DB) (err error) {
  1098. err = tx.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ? AND record_date = ?", user_org_id, his_patient_id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1099. return
  1100. }
  1101. func UpDateHospitalHisPrescriptionInfoNumber(user_org_id int64, number string, start_time int64, end_time int64) (err error) {
  1102. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date <= ? AND record_date >= ? ", user_org_id, end_time, start_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1103. return
  1104. }
  1105. type HisOrder struct {
  1106. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1107. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1108. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1109. Number string `gorm:"column:number" json:"number" form:"number"`
  1110. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1111. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1112. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1113. Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"`
  1114. WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
  1115. Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
  1116. ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
  1117. RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
  1118. InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
  1119. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1120. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1121. SetlId string `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
  1122. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1123. PsnType string `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
  1124. CvlservFlag string `gorm:"column:cvlserv_flag" json:"cvlserv_flag" form:"cvlserv_flag"`
  1125. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  1126. MdtrtCertType string `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
  1127. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1128. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1129. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1130. OverlmtSelfPay float64 `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
  1131. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  1132. InscpScpAmt float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
  1133. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1134. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  1135. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1136. PoolPropSelfpay float64 `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
  1137. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1138. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1139. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1140. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1141. OthPay float64 `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
  1142. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1143. PsnPartAmt float64 `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
  1144. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1145. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1146. HospPartAmt float64 `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
  1147. Balc float64 `gorm:"column:balc" json:"balc" form:"balc"`
  1148. AcctMulaidPay float64 `gorm:"column:acct_mulaid_pay" json:"acct_mulaid_pay" form:"acct_mulaid_pay"`
  1149. MedinsSetlId string `gorm:"column:medins_setl_id" json:"medins_setl_id" form:"medins_setl_id"`
  1150. ClrOptins string `gorm:"column:clr_optins" json:"clr_optins" form:"clr_optins"`
  1151. ClrWay string `gorm:"column:clr_way" json:"clr_way" form:"clr_way"`
  1152. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1153. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1154. IsMedicineInsurance int64 `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
  1155. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1156. SettleType int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
  1157. SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
  1158. SettleEndTime int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
  1159. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1160. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1161. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1162. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1163. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1164. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1165. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1166. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1167. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1168. }
  1169. func (HisOrder) TableName() string {
  1170. return "his_order"
  1171. }
  1172. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  1173. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1174. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1175. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  1176. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  1177. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1178. Order("ctime desc").
  1179. Find(&order).Error
  1180. return
  1181. }
  1182. func GetHisPrescriptionThree(org_id int64, patient_id int64, number string) (prescription []*models.HisPrescription, err error) {
  1183. err = readDb.Model(&models.HisPrescription{}).
  1184. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1185. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1186. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1187. }).
  1188. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1189. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND batch_number=?", org_id, patient_id, number).
  1190. Find(&prescription).Error
  1191. return
  1192. }
  1193. type HisPrescriptionInfo struct {
  1194. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1195. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1196. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1197. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1198. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1199. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1200. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1201. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1202. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1203. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1204. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1205. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  1206. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1207. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1208. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  1209. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1210. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  1211. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  1212. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1213. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1214. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  1215. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1216. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1217. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1218. }
  1219. func (HisPrescriptionInfo) TableName() string {
  1220. return "his_prescription_info"
  1221. }
  1222. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  1223. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  1224. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1225. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1226. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  1227. Order("ctime desc").Find(&prescriptionOrder).Error
  1228. return
  1229. }
  1230. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  1231. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, org_id).
  1232. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1233. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1234. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  1235. return
  1236. }
  1237. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  1238. err = readDb.Model(&models.HisPrescription{}).
  1239. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1240. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1241. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  1242. }).
  1243. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  1244. Find(&prescription).Error
  1245. return
  1246. }
  1247. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  1248. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  1249. return
  1250. }
  1251. func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
  1252. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  1253. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  1254. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  1255. return
  1256. }
  1257. func UpdataOrderStatusten(id int64, number string, user_org_id int64) (err error) {
  1258. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  1259. //err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  1260. return
  1261. }
  1262. func UpdataHospitalOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  1263. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix(), "refund_request_log": log, "refund_log": result, "status": 1}).Error
  1264. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
  1265. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 4, "mtime": time.Now().Unix()}).Error
  1266. return
  1267. }
  1268. func UpdataOrderStatusTen(id int64, number string, user_org_id int64) (err error) {
  1269. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  1270. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  1271. return
  1272. }
  1273. func UpdataOrderInfoStatus(id int64, number string, user_org_id int64) {
  1274. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  1275. err = writeDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND user_org_id = ? AND order_number = ?", user_org_id, number).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  1276. return
  1277. }
  1278. func SaveHisPatient(his models.HisPatient) (err error) {
  1279. writeDb.Model(&models.HisPatient{}).Where("status = 1 AND record_date =? AND user_org_id = ? AND id = ?", his.RecordDate, his.UserOrgId, his.ID).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  1280. writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", his.UserOrgId, his.ID).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  1281. writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", his.UserOrgId, his.ID).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  1282. return
  1283. }
  1284. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  1285. writeDb.Model(&models.HisPatient{}).Where("patient_id = ? AND status = 1 AND record_date =? AND user_org_id = ?", patient_id, record_time, org_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  1286. }
  1287. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  1288. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  1289. return
  1290. }
  1291. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  1292. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1293. First(&order).Error
  1294. return
  1295. }
  1296. func UpDateOrder(order models.HisOrder) (err error) {
  1297. err = writeDb.Save(&order).Error
  1298. return
  1299. }
  1300. func UpDateOrderTX(order models.HisOrder, tx *gorm.DB) (err error) {
  1301. err = writeDb.Save(&order).Error
  1302. return
  1303. }
  1304. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  1305. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 2, "mtime": time.Now().Unix()}).Error
  1306. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1307. return
  1308. }
  1309. func UpdataOrderStatusTwoTX(number string, user_org_id int64, tx *gorm.DB) (err error) {
  1310. err = tx.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 2, "mtime": time.Now().Unix()}).Error
  1311. err = tx.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1312. return
  1313. }
  1314. func CreateErrMsgLog(log *models.HisOrderError) {
  1315. writeDb.Model(&models.HisOrderError{}).Create(&log)
  1316. }
  1317. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  1318. err = readDb.Model(&models.VMHisPatient{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Count(&total).Error
  1319. return
  1320. }
  1321. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  1322. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  1323. return
  1324. }
  1325. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  1326. db := readDb.Model(&models.OutpatientServiceSick{})
  1327. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1328. err = db.Order("ctime desc").Find(&list).Error
  1329. return
  1330. }
  1331. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  1332. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  1333. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1334. err = db.Order("ctime desc").Find(&list).Error
  1335. return
  1336. }
  1337. func FindPatientDianose(orgId int64) (list []*models.XtPatientDiagnose, err error) {
  1338. err = readDb.Where("user_org_id =?", orgId).Find(&list).Error
  1339. return list, err
  1340. }
  1341. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  1342. db := readDb.Model(&models.XtHisAddtionConfig{})
  1343. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1344. err = db.Order("ctime desc").Find(&list).Error
  1345. return
  1346. }
  1347. type XtHisOrder struct {
  1348. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1349. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1350. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1351. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1352. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1353. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1354. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1355. Number string `gorm:"column:number" json:"number" form:"number"`
  1356. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1357. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1358. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1359. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1360. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1361. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1362. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1363. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1364. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1365. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1366. }
  1367. func (XtHisOrder) TableName() string {
  1368. return "his_order"
  1369. }
  1370. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  1371. err = readDb.Model(&models.HisPrescription{}).
  1372. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  1373. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1374. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1375. }).
  1376. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1377. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  1378. Find(&prescription).Error
  1379. return
  1380. }
  1381. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  1382. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Find(&addition).Error
  1383. return
  1384. }
  1385. func DelelteAddition(id int64, user_org_id int64) (err error) {
  1386. err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  1387. return
  1388. }
  1389. func GetNewHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64, sch_type int64) (patients []*VMHisHospitalPrescriptionInfo, err error, total int64) {
  1390. offset := (page - 1) * limit
  1391. db := readDb.Model(&VMHisHospitalPrescriptionInfo{}).Where("his_prescription_info.user_org_id = ? AND his_prescription_info.status = 1 AND his_prescription_info.record_date = ? AND his_prescription_info.p_type <> 1 ", org_id, record_date)
  1392. if len(keywords) > 0 {
  1393. keywords = "%" + keywords + "%"
  1394. db = db.Joins("JOIN xt_patients On his_prescription_info.patient_id = xt_patients.id AND xt_patients.name like ?", keywords)
  1395. }
  1396. if sch_type > 0 {
  1397. db = db.Joins("JOIN xt_schedule On xt_schedule.status = 1 AND his_prescription_info.patient_id = xt_schedule.patient_id AND xt_schedule.schedule_date = ? AND xt_schedule.schedule_type = ?", record_date, sch_type)
  1398. }
  1399. db = db.Preload("Patients", "xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1400. db = db.Preload("HisPrescription", "his_prescription.user_org_id = ? AND his_prescription.status = 1 AND his_prescription.p_type <> 1", org_id)
  1401. db = db.Count(&total)
  1402. err = db.Limit(limit).Offset(offset).Group("his_prescription_info.id").Find(&patients).Error
  1403. return
  1404. }
  1405. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
  1406. offset := (page - 1) * limit
  1407. db := readDb.Model(&VMSchedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  1408. if len(keywords) > 0 {
  1409. keywords = "%" + keywords + "%"
  1410. db = db.Joins("JOIN xt_patients as p On xt_schedule.patient_id = p.id AND p.user_org_id = ? AND p.name like ?", org_id, keywords)
  1411. db = db.Joins("JOIN his_prescription_info as info On xt_schedule.patient_id = info.patient_id AND info.user_org_id = ? AND info.record_date = ? AND info.prescription_number like ? AND info.p_type <> 1", org_id, record_date, keywords)
  1412. }
  1413. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  1414. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  1415. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id).
  1416. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id)
  1417. db = db.Count(&total)
  1418. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  1419. return
  1420. }
  1421. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  1422. patient := models.VMHisPatient{}
  1423. err := XTWriteDB().Model(&patient).Where("patient_id = ? and record_date = ? and user_org_id = ? and status = 1", patientid, recorddate, orgid).Updates(map[string]interface{}{"is_return": 3}).Error
  1424. return patient, err
  1425. }
  1426. type VMOtherHisPrescriptionInfo struct {
  1427. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1428. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1429. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1430. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1431. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1432. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  1433. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1434. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1435. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  1436. }
  1437. func (VMOtherHisPrescriptionInfo) TableName() string {
  1438. return "his_prescription_info"
  1439. }
  1440. type VMHisPrescription struct {
  1441. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1442. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1443. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1444. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1445. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1446. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1447. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1448. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1449. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1450. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  1451. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1452. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1453. }
  1454. func (VMHisPrescription) TableName() string {
  1455. return "his_prescription"
  1456. }
  1457. func GetHisPrescriptionByType(change_type int64, record_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1458. if change_type == 1 { //根据日期取出上一方数据
  1459. var Id AdviceDate
  1460. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND p_type = ?", patient_id, org_id, record_time, p_type).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  1461. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND p_type = ?", patient_id, org_id, Id.RecordDate, p_type).
  1462. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1463. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1464. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1465. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1466. }).
  1467. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1468. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1469. })
  1470. }).Find(&advice).Error
  1471. } else if change_type == 2 {
  1472. var Id AdviceDate
  1473. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date > ? AND p_type = ?", patient_id, org_id, record_time, p_type).Select("record_date").Group("record_date").Order("record_date desc").Scan(&Id).Error
  1474. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND p_type = ?", patient_id, org_id, Id.RecordDate, p_type).
  1475. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1476. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1477. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1478. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1479. }).
  1480. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1481. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1482. })
  1483. }).Find(&advice).Error
  1484. }
  1485. return
  1486. }
  1487. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1488. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ? AND p_type = ?", patient_id, org_id, start_time, end_time, p_type).
  1489. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1490. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1491. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1492. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1493. }).
  1494. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1495. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1496. })
  1497. }).Order("record_date desc").Find(&advice).Error
  1498. return
  1499. }
  1500. func GetMobileCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1501. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ?", patient_id, org_id, start_time, end_time).
  1502. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1503. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1504. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1505. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1506. }).
  1507. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1508. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1509. })
  1510. }).Find(&advice).Error
  1511. return
  1512. }
  1513. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1514. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1515. return
  1516. }
  1517. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  1518. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1519. return
  1520. }
  1521. func GetHisOrderByIDTX(order_id int64, tx *gorm.DB) (order models.HisOrder, err error) {
  1522. err = tx.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1523. return
  1524. }
  1525. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1526. err = readDb.Model(&models.HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1527. return
  1528. }
  1529. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  1530. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND settle_accounts_date <= ? AND settle_accounts_date >= ? AND insutype = ? AND clr_type = ? ", org_id, end_time, start_time, insutype, clr_type).Find(&orders).Error
  1531. return
  1532. }
  1533. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  1534. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND settle_accounts_date <= ? AND settle_accounts_date >= ? ", org_id, end_time, start_time).Find(&orders).Error
  1535. return
  1536. }
  1537. func GetHisDoctorAdvicesById(id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1538. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND id = ?", id).First(&advice).Error
  1539. return
  1540. }
  1541. func GetAdditionChargeByID(org_id int64, id int64) (addition models.XtHisAddtionConfig, err error) {
  1542. err = readDb.Model(&models.XtHisAddtionConfig{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&addition).Error
  1543. return
  1544. }
  1545. func GetHisPrescriptionByID(org_id int64, id int64) (pre models.HisPrescription, err error) {
  1546. err = readDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&pre).Error
  1547. return
  1548. }
  1549. func GetHisProjectByID(id int64) (project models.HisPrescriptionProject, err error) {
  1550. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id = ?", id).First(&project).Error
  1551. return
  1552. }
  1553. func GetHisAdditionByID(id int64) (addition models.HisAdditionalCharge, err error) {
  1554. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND id = ?", id).First(&addition).Error
  1555. return
  1556. }
  1557. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1558. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  1559. return
  1560. }
  1561. func GetPatientByIDCardAndName(id_card_no string, user_org_id int64, name string) (patient Patients, err error) {
  1562. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ? AND name = ?", id_card_no, user_org_id, name).First(&patient).Error
  1563. return
  1564. }
  1565. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1566. err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND user_org_id = ? AND settle_accounts_date = ? AND status = 1", patient_id, user_org_id, record_time).First(&order).Error
  1567. return
  1568. }
  1569. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1570. var patient Patients
  1571. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1572. return patient, err
  1573. }
  1574. func GetPatientByIDTenTwo(orgID int64, patientID int64) (models.PatientTwos, error) {
  1575. var patient models.PatientTwos
  1576. err := readDb.Model(&models.PatientTwos{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1577. return patient, err
  1578. }
  1579. func GetHisPrescriptionByPatientID(patientID int64, orgID int64) (info models.HisPrescriptionInfo, err error) {
  1580. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND patient_id = ? AND status = 1", orgID, patientID).Preload("XtHisDepartment", "status = 1").Last(&info).Error
  1581. return
  1582. }
  1583. type VMHisProjectTeam struct {
  1584. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1585. ProjectTeam string `gorm:"column:project_team" json:"project_team" form:"project_team"`
  1586. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1587. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1588. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1589. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  1590. TeamType int64 `gorm:"column:team_type" json:"team_type" form:"team_type"`
  1591. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1592. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1593. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1594. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1595. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1596. ProjectId string `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1597. VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
  1598. ItemId string `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1599. }
  1600. func (VMHisProjectTeam) TableName() string {
  1601. return "xt_his_project_team"
  1602. }
  1603. type VMHisProject struct {
  1604. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1605. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1606. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1607. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1608. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1609. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1610. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1611. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1612. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1613. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1614. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1615. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1616. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1617. }
  1618. func (VMHisProject) TableName() string {
  1619. return "xt_his_project"
  1620. }
  1621. type VMItemProjectList struct {
  1622. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1623. Number int64 `gorm:"column:number" json:"number" form:"number"`
  1624. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1625. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1626. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1627. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1628. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1629. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1630. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1631. VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1632. GoodInfo GoodInfo `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good_info"`
  1633. }
  1634. func (VMItemProjectList) TableName() string {
  1635. return "xt_his_project_list"
  1636. }
  1637. type VMHisPrescriptionTwo struct {
  1638. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1639. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1640. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1641. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1642. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1643. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1644. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1645. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1646. }
  1647. func (VMHisPrescriptionTwo) TableName() string {
  1648. return "his_prescription"
  1649. }
  1650. func GetAllProjectTeamList(orgid int64) (project []*VMHisProjectTeam, err error) {
  1651. err = XTReadDB().Model(&VMHisProjectTeam{}).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1652. for _, item := range project {
  1653. var project_item []*VMItemProjectList
  1654. ids := strings.Split(item.ItemId, ",")
  1655. XTReadDB().Model(&VMItemProjectList{}).Where("status = 1 AND id IN (?)", ids).Preload("VMHisProject", "status = 1 AND user_org_id = ?", orgid).Preload("GoodInfo", "status = 1 AND org_id = ?", orgid).Find(&project_item)
  1656. item.VMItemProjectList = append(item.VMItemProjectList, project_item...)
  1657. }
  1658. return
  1659. }
  1660. type HisDoctorAdviceInfo struct {
  1661. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1662. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1663. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1664. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1665. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1666. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1667. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1668. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1669. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1670. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1671. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1672. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1673. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1674. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1675. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1676. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1677. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1678. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1679. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1680. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1681. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1682. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1683. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1684. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1685. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  1686. }
  1687. func (HisDoctorAdviceInfo) TableName() string {
  1688. return "his_doctor_advice_info"
  1689. }
  1690. type HisPrescriptionProject struct {
  1691. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1692. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1693. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1694. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1695. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1696. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1697. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1698. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1699. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1700. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1701. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1702. Count string `gorm:"column:count" json:"count" form:"count"`
  1703. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1704. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1705. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1706. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1707. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1708. Day string `gorm:"column:day" json:"day" form:"day"`
  1709. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1710. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1711. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1712. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1713. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1714. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1715. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1716. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1717. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1718. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1719. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1720. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1721. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1722. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1723. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1724. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  1725. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  1726. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  1727. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1728. }
  1729. func (HisPrescriptionProject) TableName() string {
  1730. return "his_prescription_project"
  1731. }
  1732. type HisOrderInfo struct {
  1733. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1734. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1735. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1736. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1737. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1738. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1739. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1740. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1741. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1742. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1743. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1744. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1745. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1746. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1747. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1748. SelfpayProp float64 `gorm:"column:selfpay_prop" json:"selfpay_prop" form:"selfpay_prop"`
  1749. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1750. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1751. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1752. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1753. }
  1754. func (HisOrderInfo) TableName() string {
  1755. return "his_order_info"
  1756. }
  1757. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1758. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1759. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  1760. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1761. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  1762. }).Find(&order).Error
  1763. return
  1764. }
  1765. //func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1766. // db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1767. // return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  1768. // })
  1769. // err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1770. // return
  1771. //}
  1772. func GetHisOrderInfoByNumberOne(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1773. db := readDb.Model(&models.HisOrderInfoTwo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1774. return db.Preload("Drug", "status = 1").Where("status = 1")
  1775. })
  1776. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1777. return
  1778. }
  1779. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1780. db := readDb.Model(&models.HisOrderInfoTwo{})
  1781. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  1782. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1783. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1784. })
  1785. err = db.Where("his_order_info.order_number = ? AND his_order_info.status = 1 AND his_order_info.project_id > 0 ", order_number).Find(&order).Error
  1786. return
  1787. }
  1788. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1789. db := readDb.Model(&models.HisOrderInfoTwo{})
  1790. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  1791. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1792. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1793. })
  1794. err = db.Where("his_order_info.order_number = ? AND his_order_info.status = 1 AND his_order_info.project_id > 0", order_number).Find(&order).Error
  1795. return
  1796. }
  1797. type MedicalInsuranceCostCompare struct {
  1798. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1799. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1800. EndTime int64 `gorm:"column:end_time" json:"end_time" form:"end_time"`
  1801. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1802. CheckType int64 `gorm:"column:check_type" json:"check_type" form:"check_type"`
  1803. Num int64 `gorm:"column:num" json:"num" form:"num"`
  1804. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1805. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1806. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1807. CostTotal float64 `gorm:"column:cost_total" json:"cost_total" form:"cost_total"`
  1808. FuncTotal float64 `gorm:"column:func_total" json:"func_total" form:"func_total"`
  1809. PsnPay float64 `gorm:"column:psn_pay" json:"psn_pay" form:"psn_pay"`
  1810. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1811. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1812. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1813. }
  1814. func (MedicalInsuranceCostCompare) TableName() string {
  1815. return "medical_insurance_cost_compare"
  1816. }
  1817. func GetMedicalInsuranceCostCompareList(orgID, page, limit int64, keywords string, insutype string, start_time int64, end_time int64) (list []*MedicalInsuranceCostCompare, total int, err error) {
  1818. offset := (page - 1) * limit
  1819. db := readDb.Model(&MedicalInsuranceCostCompare{}).Where("medical_insurance_cost_compare.user_org_id = ?", orgID)
  1820. if len(keywords) == 0 {
  1821. db = db.Where("status=1")
  1822. if len(insutype) != 0 {
  1823. db = db.Where("insutype = ?", insutype)
  1824. }
  1825. if start_time != 0 {
  1826. db = db.Where("ctime >= ? ", start_time)
  1827. }
  1828. if end_time != 0 {
  1829. db = db.Where("ctime <= ? ", end_time)
  1830. }
  1831. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1832. } else {
  1833. keywords = "%" + keywords + "%"
  1834. db = db.Joins("join sgj_users.sgj_user_admin_role role on role.admin_user_id = medical_insurance_cost_compare.creator and role.user_name Like ?", keywords)
  1835. db = db.Where("medical_insurance_cost_compare.status=1 ")
  1836. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1837. }
  1838. return
  1839. }
  1840. type TempPatients struct {
  1841. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1842. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1843. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1844. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  1845. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1846. Name string `gorm:"column:name" json:"name" form:"name"`
  1847. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1848. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  1849. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  1850. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  1851. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1852. GdybPsnNcdsRecord GdybPsnNcdsRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"record"`
  1853. }
  1854. func (TempPatients) TableName() string {
  1855. return "xt_patients"
  1856. }
  1857. type GdybPsnNcdsRecord struct {
  1858. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1859. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1860. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1861. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1862. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1863. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1864. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1865. IsCancel int64 `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
  1866. TrtDclaDetlSn string `gorm:"column:trt_dcla_detl_sn" json:"trt_dcla_detl_sn" form:"trt_dcla_detl_sn"`
  1867. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1868. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1869. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1870. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1871. OrgName string `gorm:"column:org_name" json:"org_name" form:"org_name"`
  1872. }
  1873. func (GdybPsnNcdsRecord) TableName() string {
  1874. return "gdyb_psn_ncds_record"
  1875. }
  1876. func GetGdybPsnNcdsRecordList(orgID, page, limit int64, keywords string, is_cancel int64) (list []*TempPatients, total int64, err error) {
  1877. offset := (page - 1) * limit
  1878. db := readDb.Model(&TempPatients{})
  1879. db = db.Preload("GdybPsnNcdsRecord", func(db *gorm.DB) *gorm.DB {
  1880. return db.Model(&GdybPsnNcdsRecord{}).Where("user_org_id = ?", orgID).Order("id asc")
  1881. })
  1882. fmt.Println(is_cancel)
  1883. if len(keywords) == 0 {
  1884. if is_cancel == 1 {
  1885. db = db.Joins("JOIN gdyb_psn_ncds_record On gdyb_psn_ncds_record.patient_id = xt_patients.id AND gdyb_psn_ncds_record.is_cancel = ?", is_cancel)
  1886. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1887. } else if is_cancel == 0 {
  1888. db = db.Preload("GdybPsnNcdsRecord", "user_org_id = ?", orgID)
  1889. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1890. } else if is_cancel == 2 {
  1891. db = db.Joins("LEFT JOIN gdyb_psn_ncds_record On gdyb_psn_ncds_record.patient_id = xt_patients.id AND (gdyb_psn_ncds_record.is_cancel <> 1 OR gdyb_psn_ncds_record.is_cancel is null)")
  1892. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1893. }
  1894. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1895. } else {
  1896. keywords = "%" + keywords + "%"
  1897. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1 AND xt_patients.name LIKE ?", orgID, keywords)
  1898. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1899. }
  1900. return
  1901. }
  1902. type CustomAccountFormData struct {
  1903. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1904. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1905. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1906. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1907. MdtrtiId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1908. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1909. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1910. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1911. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1912. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1913. CashPay float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
  1914. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  1915. Sumamt float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
  1916. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1917. DiagnosisId string `gorm:"column:diagnosis_id" json:"diagnosis_id" form:"diagnosis_id"`
  1918. DialysisCount int64 `gorm:"-"`
  1919. PatientId int64 `gorm:"column:patient_id" json:"dialysis_count" form:"dialysis_count"`
  1920. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1921. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1922. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1923. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1924. MayPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1925. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1926. SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
  1927. SettleEndTime int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
  1928. }
  1929. func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (cus []*CustomAccountFormData, err error) {
  1930. if clr_type == "9903" {
  1931. err = readDb.Raw("select o.setl_detail as setl_detail, o.maf_pay as maf_pay, o.hifmi_pay as hifmi_pay, o.hifob_pay as hifob_pay, o.cvlserv_pay as cvlserv_pay, o.hifes_pay as hifes_pay, o.patient_id as patient_id, p.diagnosis as diagnosis_id, p.iinfo as iinfo, o.medfee_sumamt as medfee_sumamt ,o.psn_name as psn_name ,p.id_card_no as id_card_no ,o.psn_no as psn_no, o.mdtrt_id as mdtrt_id, o.settle_accounts_date as settle_accounts_date,o.act_pay_dedc as act_pay_dedc,O.fund_pay_sumamt as fund_pay_sumamt,o.psn_cash_pay as psn_cash_pay ,o.acct_pay as acct_pay,o.psn_cash_pay as cash_pay,o.medfee_sumamt as sumamt,o.hifp_pay as hifp_pay, o.settle_start_time as settle_start_time, o.settle_end_time as settle_end_time from his_order o Join his_patient p On o.patient_id = p.patient_id AND o.settle_accounts_date = p.record_date where o.user_org_id = ? AND o.status = 1 AND o.order_status = 2 AND o.settle_accounts_date >= ? AND o.settle_accounts_date <= ? AND o.insutype = ? AND o.clr_type = ? Group by o.id", org_id, start_time, end_time, insutype, clr_type).Scan(&cus).Error
  1932. } else {
  1933. err = readDb.Raw("select o.setl_detail as setl_detail, o.maf_pay as maf_pay, o.hifmi_pay as hifmi_pay, o.hifob_pay as hifob_pay, o.cvlserv_pay as cvlserv_pay, o.hifes_pay as hifes_pay, o.patient_id as patient_id, p.diagnosis as diagnosis_id, p.iinfo as iinfo, o.medfee_sumamt as medfee_sumamt ,o.psn_name as psn_name ,p.id_card_no as id_card_no ,o.psn_no as psn_no, o.mdtrt_id as mdtrt_id, o.settle_accounts_date as settle_accounts_date,o.act_pay_dedc as act_pay_dedc,O.fund_pay_sumamt as fund_pay_sumamt,o.psn_cash_pay as psn_cash_pay ,o.acct_pay as acct_pay,o.psn_cash_pay as cash_pay,o.medfee_sumamt as sumamt,o.hifp_pay as hifp_pay,o.settle_start_time as settle_start_time, o.settle_end_time as settle_end_time from his_order o Join his_patient p On o.patient_id = p.patient_id AND o.settle_accounts_date = p.record_date where o.user_org_id = ? AND o.status = 1 AND o.order_status = 2 AND o.settle_accounts_date >= ? AND o.settle_accounts_date <= ? AND o.insutype = ? AND o.clr_type <> 9903 Group by o.id", org_id, start_time, end_time, insutype).Scan(&cus).Error
  1934. }
  1935. for _, item := range cus {
  1936. var total int64
  1937. if item.SettleStartTime == 0 && item.SettleEndTime == 0 {
  1938. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND dialysis_date >= ?", item.PatientId, item.SettleAccountsDate, item.SettleAccountsDate).Count(&total)
  1939. } else {
  1940. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND dialysis_date >= ?", item.PatientId, item.SettleEndTime, item.SettleStartTime).Count(&total)
  1941. }
  1942. fmt.Println(total)
  1943. item.DialysisCount = total
  1944. fmt.Println(item.DialysisCount)
  1945. }
  1946. return
  1947. }
  1948. func GetNewHisPatientInfo(his_patient_id int64) (info models.HisPatient, err error) {
  1949. err = readDb.Model(&models.HisPatient{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
  1950. return
  1951. }
  1952. func GetNewHisOrder(user_org_id int64, mdtrt_id string, patient_id int64) (order models.HisOrder, err error) {
  1953. err = readDb.Model(&models.HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? ", user_org_id, patient_id, mdtrt_id).
  1954. Last(&order).Error
  1955. return
  1956. }
  1957. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1958. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? AND settle_accounts_date = ? ", user_org_id, patient_id, mdtrt_id, record_time).
  1959. Order("ctime desc").
  1960. Find(&order).Error
  1961. return
  1962. }
  1963. type NewCustomPatients struct {
  1964. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1965. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1966. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1967. Number string `gorm:"column:number" json:"number" form:"number"`
  1968. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1969. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1970. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,Number" json:"order"`
  1971. }
  1972. func (NewCustomPatients) TableName() string {
  1973. return "his_patients"
  1974. }
  1975. type NewSZCustomPatients struct {
  1976. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1977. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1978. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1979. Number string `gorm:"column:number" json:"number" form:"number"`
  1980. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1981. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1982. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,MzNumber" json:"order"`
  1983. }
  1984. func (NewSZCustomPatients) TableName() string {
  1985. return "his_patients"
  1986. }
  1987. //
  1988. //func GetNewAllChargeHisPatientList(org_id int64, record_date int64) (patients []*NewSZCustomPatients, err error) {
  1989. // var tempPatients []*NewSZCustomPatients
  1990. // db := readDb.Model(&NewSZCustomPatients{}).Where("his_patients.user_org_id = ? AND his_patients.status = 1", org_id)
  1991. // db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1992. // return tempPatients, err
  1993. //}
  1994. type NewTempPatients struct {
  1995. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1996. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1997. Name string `gorm:"column:name" json:"name" form:"name"`
  1998. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1999. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  2000. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  2001. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  2002. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  2003. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  2004. HisPatient []*HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  2005. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  2006. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  2007. }
  2008. func (NewTempPatients) TableName() string {
  2009. return "xt_patients"
  2010. }
  2011. //"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
  2012. func GetNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*NewTempPatients, err error) {
  2013. db := readDb.Model(&NewTempPatients{})
  2014. if sch_type > 0 {
  2015. db = db.Joins("join xt_schedule as sch on sch.patient_id = xt_patients.id and sch.schedule_date = ? and sch.schedule_type = ? and sch.status = 1", record_date, sch_type)
  2016. }
  2017. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2018. db = db.Preload("Schedule", "status = 1")
  2019. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2020. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  2021. })
  2022. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  2023. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Group("xt_patients.id").Error
  2024. for _, item := range patients {
  2025. for _, sumItem := range item.HisPatient {
  2026. if len(sumItem.VMHisOrders) > 0 {
  2027. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2028. }
  2029. }
  2030. }
  2031. return
  2032. }
  2033. func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*NewTempPatients, err error) {
  2034. db := readDb.Model(&NewTempPatients{})
  2035. fmt.Println("sch_type")
  2036. fmt.Println(sch_type)
  2037. if sch_type > 0 {
  2038. db = db.Joins("join xt_schedule as sch on sch.patient_id = xt_patients.id and sch.schedule_date = ? and sch.schedule_type = ? and sch.status = 1", record_date, sch_type)
  2039. }
  2040. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2041. db = db.Preload("Schedule", "status = 1")
  2042. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2043. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ? ", org_id, record_date)
  2044. })
  2045. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status = 2", org_id, record_date)
  2046. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Group("xt_patients.id").Error
  2047. for _, item := range patients {
  2048. for _, sumItem := range item.HisPatient {
  2049. if len(sumItem.VMHisOrders) > 0 {
  2050. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2051. }
  2052. }
  2053. }
  2054. return
  2055. }
  2056. func GetPrescriptionById(id int64, org_id int64) (prescription models.HisPrescription, err error) {
  2057. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND user_org_id = ? AND status = 1", id, org_id).First(&prescription).Error
  2058. return
  2059. }
  2060. func GetPrescriptionByIdTwo(id int64) (prescription models.HisPrescription, err error) {
  2061. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND status = 1", id).First(&prescription).Error
  2062. return
  2063. }
  2064. type CustomInComeStatistics struct {
  2065. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  2066. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  2067. SettleAccountsDate string `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  2068. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  2069. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  2070. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  2071. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  2072. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  2073. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  2074. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  2075. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  2076. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  2077. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  2078. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  2079. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  2080. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  2081. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  2082. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  2083. }
  2084. func (CustomInComeStatistics) TableName() string {
  2085. return "his_order"
  2086. }
  2087. func GetDayIncomeStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (order []*CustomInComeStatistics, total int64, err error) {
  2088. offset := (page - 1) * limit
  2089. if len(keywords) != 0 {
  2090. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  2091. } else {
  2092. if start_time != 0 && end_time != 0 {
  2093. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 AND settle_accounts_date >= ? AND settle_accounts_date <= ?", org_id, start_time, end_time).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  2094. } else {
  2095. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  2096. }
  2097. }
  2098. return
  2099. }
  2100. func GetDayIncomeDetailStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (cis []*CustomInComeStatistics, total int64, err error) {
  2101. offset := (page - 1) * limit
  2102. if len(keywords) != 0 {
  2103. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  2104. } else {
  2105. if start_time != 0 && end_time != 0 {
  2106. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 AND settle_accounts_date >= ? AND settle_accounts_date <= ? ", org_id, start_time, end_time).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  2107. } else {
  2108. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  2109. }
  2110. }
  2111. return
  2112. }
  2113. //func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  2114. // err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  2115. // return
  2116. //}
  2117. func CreateHisPrescriptionTemplate(template *models.HisPrescriptionTemplate) (err error) {
  2118. err = writeDb.Create(&template).Error
  2119. return
  2120. }
  2121. func CreateHisPrescriptionAdviceTemplate(s *models.HisPrescriptionAdviceTemplate) (err error) {
  2122. err = writeDb.Save(&s).Error
  2123. return
  2124. }
  2125. func CreateHisPrescriptionInfoTemplate(s *models.HisPrescriptionInfoTemplate) (err error) {
  2126. err = writeDb.Save(&s).Error
  2127. return
  2128. }
  2129. func CreateHisPrescriptionProjectTemplate(project *models.HisPrescriptionProjectTemplate) (err error) {
  2130. err = writeDb.Save(&project).Error
  2131. return
  2132. }
  2133. func GetPatientSch(patient_id int64, sch_date int64, org_id int64) (sch models.Schedule, err error) {
  2134. err = readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND patient_id = ? AND schedule_date = ? AND status = 1", org_id, patient_id, sch_date).First(&sch).Error
  2135. return
  2136. }
  2137. func GetHisPrescriptionBySchMode(mode_id int64, patient_id int64, org_id int64) (prescription models.HisPrescriptionTemplate, err error) {
  2138. err = readDb.Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? AND status = 1 AND mode = ? AND patient_id = ?", org_id, mode_id, patient_id).Last(&prescription).Error
  2139. return
  2140. }
  2141. func GetHisPrescriptionTemplate(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplate, err error) {
  2142. err = readDb.Model(&models.HisPrescriptionInfoTemplate{}).
  2143. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  2144. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2145. }).
  2146. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  2147. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  2148. }).
  2149. Where("status = 1 AND p_template_id = ? ", template_id).
  2150. Find(&prescription).Error
  2151. return
  2152. }
  2153. // 组
  2154. func GetHisPrescriptionTemplateL(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplateL, err error) {
  2155. err = readDb.Model(&models.HisPrescriptionInfoTemplateL{}).
  2156. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  2157. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2158. }).
  2159. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  2160. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  2161. }).
  2162. Where("status = 1 AND p_template_id = ? ", template_id).
  2163. Find(&prescription).Error
  2164. return
  2165. }
  2166. func FindHisConsumablesByID(orgID int64, patient_id int64, recordDate int64, good_id int64) (consumables models.DialysisBeforePrepare, err error) {
  2167. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND good_id = ?", orgID, patient_id, recordDate, good_id).First(&consumables).Error
  2168. return
  2169. }
  2170. func UpdateConsumables(consumables *models.DialysisBeforePrepare) (err error) {
  2171. err = writeDb.Save(&consumables).Error
  2172. return
  2173. }
  2174. func GetHisPrescriptionProjectsByID(id int64) (projects []*models.HisPrescriptionProject, err error) {
  2175. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("prescription_id = ? AND status = 1", id).Find(&projects).Error
  2176. return
  2177. }
  2178. func GetHisPrescriptionProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  2179. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND team_id = 0", user_org_id, patient_id, record_time).Find(&projects).Error
  2180. return
  2181. }
  2182. func GetHisPrescriptionTeamProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  2183. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("XtHisProjectTeam", "status = 1 AND user_org_id = ?", user_org_id).Preload("HisProject", "status = 1 AND user_org_id = ?", user_org_id).Preload("GoodInfo", "status = 1 AND org_id = ?", user_org_id).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND team_id > 0", user_org_id, patient_id, record_time).Find(&projects).Error
  2184. return
  2185. }
  2186. func GetHisPrescriptionProjectByID(id int64) (projects models.HisPrescriptionProject, err error) {
  2187. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2188. return
  2189. }
  2190. func GetHisPrescriptionAdviceByID(id int64) (advices []*models.HisDoctorAdviceInfo, err error) {
  2191. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
  2192. return
  2193. }
  2194. func UpdateGoodInfo(good_info *models.GoodInfo) (err error) {
  2195. err = writeDb.Save(&good_info).Error
  2196. return
  2197. }
  2198. func GetUnChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2199. err = readDb.Model(&models.HisPrescription{}).
  2200. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2201. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2202. }).
  2203. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2204. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2205. }).
  2206. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2207. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2208. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2209. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2210. }).
  2211. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? AND order_status <> 2 ", org_id, start_date, end_date, patient_id, p_type).
  2212. Find(&prescription).Error
  2213. return
  2214. }
  2215. func GetChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2216. err = readDb.Model(&models.HisPrescription{}).
  2217. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2218. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2219. }).
  2220. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2221. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2222. }).
  2223. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2224. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2225. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2226. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2227. }).
  2228. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? AND order_status = 2 ", org_id, start_date, end_date, patient_id, p_type).
  2229. Find(&prescription).Error
  2230. return
  2231. }
  2232. func GetChargeHisPrescriptionSeven(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2233. err = readDb.Model(&models.HisPrescription{}).
  2234. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2235. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2236. }).
  2237. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2238. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  2239. }).
  2240. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2241. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  2242. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2243. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2244. }).
  2245. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND order_status = 2 AND batch_number = ? AND p_type = ?", org_id, patient_id, order_number, p_type).
  2246. Find(&prescription).Error
  2247. return
  2248. }
  2249. // 已收费
  2250. func GetChargeMonthHisPrescriptionFive(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2251. err = readDb.Model(&models.HisPrescription{}).
  2252. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2253. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2254. }).
  2255. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2256. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2257. }).
  2258. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2259. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2260. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2261. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2262. }).
  2263. Where("user_org_id = ? AND status = 1 AND batch_number = ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, order_number, patient_id, p_type).
  2264. Find(&prescription).Error
  2265. return
  2266. }
  2267. func UpdataHisPateint(his *models.HisPatient) {
  2268. writeDb.Save(&his)
  2269. }
  2270. func UpdataHisPateintTX(his *models.HisPatient, tx *gorm.DB) {
  2271. tx.Save(&his)
  2272. }
  2273. func SaveHisOrder(his *models.HisOrder) (err error) {
  2274. err = writeDb.Save(&his).Error
  2275. return
  2276. }
  2277. func UpdataHisPateintTwo(his *models.VMHisPatient) {
  2278. writeDb.Save(&his)
  2279. }
  2280. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  2281. err = readDb.Model(&models.HisPrescription{}).
  2282. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2283. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2284. }).
  2285. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2286. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2287. }).
  2288. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2289. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2290. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2291. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2292. }).
  2293. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2294. Find(&prescription).Error
  2295. return
  2296. }
  2297. func GetPrescriptionByIdsTX(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2298. err = tx.Model(&models.HisPrescription{}).
  2299. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2300. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2301. }).
  2302. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2303. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2304. }).
  2305. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2306. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2307. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2308. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2309. }).
  2310. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2311. Find(&prescription).Error
  2312. return
  2313. }
  2314. func GetPrescriptionByIdsTxOne(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2315. err = tx.Model(&models.HisPrescription{}).
  2316. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2317. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2318. }).
  2319. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2320. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  2321. }).
  2322. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2323. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1")
  2324. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2325. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2326. }).
  2327. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2328. Find(&prescription).Error
  2329. return
  2330. }
  2331. func GetNewAllUnChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  2332. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2333. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2334. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ? AND order_status <> 2", org_id, record_date)
  2335. })
  2336. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  2337. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  2338. for _, item := range patients {
  2339. for _, sumItem := range item.HisPatient {
  2340. if len(sumItem.VMHisOrders) > 0 {
  2341. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2342. }
  2343. }
  2344. }
  2345. return
  2346. }
  2347. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  2348. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 2 AND mdtrt_id = ?", org_id, patient_id, record_time, number).Count(&count).Error
  2349. return
  2350. }
  2351. func GetNewHisOrderList(org_id int64) (order []*models.NewHisOrder, err error) {
  2352. err = readDb.Model(&models.NewHisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2", org_id).Preload("HisPatient", "status = 1").Find(&order).Error
  2353. var numbers []string
  2354. for _, item := range order {
  2355. numbers = append(numbers, item.Number)
  2356. }
  2357. return
  2358. }
  2359. func GetNewHisOrderInfoList(order_numbers []string) (order []*models.VMHisOrderInfo, err error) {
  2360. err = readDb.Model(&models.VMHisOrderInfo{}).Where("status = 1 AND order_number in (?)", order_numbers).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2361. return db.Where("status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1")
  2362. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2363. return db.Where("status = 1 ").Preload("Drug", "status =1")
  2364. }).Find(&order).Error
  2365. return
  2366. }
  2367. func FindAllHisDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, drug_id int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2368. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_date > ? AND advice_date <= ? AND drug_id = ? ", orgId, patient_id, end, now, drug_id).Find(&advice).Error
  2369. return
  2370. }
  2371. func FindAllHisProjectByTime(now int64, end int64, patient_id int64, orgId int64, project_id int64) (project []*models.HisPrescriptionProject, err error) {
  2372. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date > ? AND record_date <= ? AND project_id = ? ", orgId, patient_id, end, now, project_id).Find(&project).Error
  2373. return
  2374. }
  2375. func GetProjectByTeamId(user_org_id int64, team_id int64, patient_id int64, record_time int64) (label models.HisLabelPrintInfo, err error) {
  2376. err = readDb.Model(&models.HisLabelPrintInfo{}).Where("user_org_id = ? AND item_id = ? AND patient_id = ? AND record_date = ? AND status = 1", user_org_id, team_id, patient_id, record_time).First(&label).Error
  2377. return
  2378. }
  2379. func GetProjectById(user_org_id int64, p_project_id int64, record_time int64, patient_id int64) (label models.HisLabelPrintInfo, err error) {
  2380. err = readDb.Model(&models.HisLabelPrintInfo{}).Where("user_org_id = ? AND p_project_id = ? AND patient_id = ? AND record_date = ? AND status = 1", user_org_id, p_project_id, patient_id, record_time).First(&label).Error
  2381. return
  2382. }
  2383. func DeletePrintInfo(id int64) {
  2384. writeDb.Model(&models.HisLabelPrintInfo{}).Where("p_project_id = ?", id).Updates(map[string]interface{}{"status": 0})
  2385. }
  2386. func CreateNewHisLabelRecord(label *models.HisLabelPrintInfo, tx *gorm.DB) (err error) {
  2387. if err = tx.Save(&label).Error; err != nil {
  2388. tx.Rollback()
  2389. return
  2390. }
  2391. return
  2392. }
  2393. func CreateHisLabelRecord(label *models.HisLabelPrintInfo) error {
  2394. err := writeDb.Save(&label).Error
  2395. return err
  2396. }
  2397. func CreateHisLabelRecordTwo(label *models.HisLabelPrintInfo) (err error) {
  2398. err = writeDb.Save(&label).Error
  2399. return
  2400. }
  2401. func DeletePsnNCDSRecordById(id int64) (err error) {
  2402. err = writeDb.Model(&models.GdybPsnNcdsRecord{}).Where("id = ?", id).Updates(map[string]interface{}{"user_org_id": 1110000}).Error
  2403. return
  2404. }
  2405. func GetBaiLinOrderData() (order []*models.NewCustomHisOrder) {
  2406. readDb.Model(&models.NewCustomHisOrder{}).Preload("Patients", "status = 1").Preload("NewCustomHisOrderInfo", func(db *gorm.DB) *gorm.DB {
  2407. return db.Where("status = 1 AND project_id > 0").Preload("NewCustomHisPrescriptionProject", "(status = 1 and project_id = 1027 AND type = 2) OR (status = 1 AND project_id = 2036 AND type = 3)")
  2408. }).Where("user_org_id = 10138 AND settle_accounts_date >= 1638288000 AND settle_accounts_date <= 1640880000 AND order_status = 2 AND status = 1 AND (medfee_sumamt = 50 OR medfee_sumamt = 40)").Find(&order)
  2409. return
  2410. }
  2411. func GetHisDoctorAdviceInfo(id int64) (models.HisDoctorAdviceInfo, error) {
  2412. info := models.HisDoctorAdviceInfo{}
  2413. err := readDb.Model(&info).Where("id = ? and status = 1", id).Preload("Drug", "status = 1").Find(&info).Error
  2414. return info, err
  2415. }
  2416. func UpdateBatchHisPrescriptionMedType(ids []string, med_type string, start_time int64, end_time int64, user_org_id int64, old_med_type string) (err error) {
  2417. tx := writeDb.Begin()
  2418. if err = tx.Model(&models.HisPrescription{}).Where("id in (?) AND status = 1 AND user_org_id=? AND med_type = ? AND record_date >= ? AND record_date <= ?", ids, user_org_id, old_med_type, start_time, end_time).Updates(map[string]interface{}{"med_type": med_type}).Error; err != nil {
  2419. tx.Rollback()
  2420. return
  2421. }
  2422. tx.Commit()
  2423. return
  2424. }
  2425. func GetWarehoseInfoByDrugId(drug_id int64, org_id int64) (info OtherDrugWarehouseInfo, err error) {
  2426. err = readDb.Model(&OtherDrugWarehouseInfo{}).Where("(drug_id = ? AND org_id = ? AND status = 1 and stock_max_number > 0) or (drug_id = ? AND org_id = ? AND status = 1 AND stock_min_number >0)", drug_id, org_id, drug_id, org_id).First(&info).Error
  2427. return
  2428. }
  2429. func GetGoodWarehoseInfoByGoodId(good_id int64, org_id int64) (info models.GoodSotckInfo, err error) {
  2430. err = readDb.Model(&models.GoodSotckInfo{}).Where("stock_count > 0 and status = 1 and good_id = ? and org_id = ?", good_id, org_id).First(&info).Error
  2431. return
  2432. }
  2433. type MonthChargePatients struct {
  2434. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2435. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2436. Name string `gorm:"column:name" json:"name" form:"name"`
  2437. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2438. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2439. Number string `gorm:"column:number" json:"number" form:"number"`
  2440. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  2441. }
  2442. func (MonthChargePatients) TableName() string {
  2443. return "his_patient"
  2444. }
  2445. func GetMonthUnChargeHisPatientList(org_id int64, record_date int64, start_time int64, end_time int64) (patients []*MonthChargePatients, err error) {
  2446. db := readDb.Model(&MonthChargePatients{}).Where("his_patient.user_org_id = ? AND his_patient.status = 1 AND his_patient.record_date = ?", org_id, record_date)
  2447. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, start_time, end_time)
  2448. return
  2449. }
  2450. func UpdataOrderStatusThree(number string, user_org_id int64) (err error) {
  2451. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 5, "mtime": time.Now().Unix()}).Error
  2452. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 5, "mtime": time.Now().Unix()}).Error
  2453. return
  2454. }
  2455. func UpDateOrderTwo(order *models.HisOrder, tx *gorm.DB) (err error) {
  2456. err = tx.Save(&order).Error
  2457. return
  2458. }
  2459. type HisOrderInfoTen struct {
  2460. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2461. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2462. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2463. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2464. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2465. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2466. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2467. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2468. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2469. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2470. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2471. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2472. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2473. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2474. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2475. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2476. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2477. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2478. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2479. }
  2480. func (HisOrderInfoTen) TableName() string {
  2481. return "his_order_info"
  2482. }
  2483. func GetHisOrderDetailByNumberTen(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2484. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2485. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2486. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2487. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2488. }).Find(&order).Error
  2489. return
  2490. }
  2491. func GetHisOrderDetailByNumberEleven(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2492. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2493. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2494. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2495. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2496. }).Find(&order).Error
  2497. return
  2498. }
  2499. func GetHisOrderByIDTen(order_id int64) (order models.HisOrder, err error) {
  2500. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2501. return
  2502. }
  2503. func GetHisPrescriptonProjectById(id int64) (models.HisPrescriptionProject, error) {
  2504. project := models.HisPrescriptionProject{}
  2505. err := XTReadDB().Where("id = ? and status = 1", id).Find(&project).Error
  2506. return project, err
  2507. }
  2508. type HisOrderInfoTwo struct {
  2509. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2510. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2511. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2512. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2513. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2514. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2515. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2516. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2517. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2518. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2519. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2520. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2521. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2522. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2523. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2524. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2525. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2526. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2527. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2528. }
  2529. func (HisOrderInfoTwo) TableName() string {
  2530. return "his_order_info"
  2531. }
  2532. func GetHisOrderDetailByNumberTwo(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2533. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2534. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2535. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2536. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2537. }).Find(&order).Error
  2538. return
  2539. }
  2540. func GetHisOrderDetailByNumberThree(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2541. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2542. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2543. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2544. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2545. }).Find(&order).Error
  2546. return
  2547. }
  2548. func GetHisOrderByIDThree(order_id int64) (order models.HisOrder, err error) {
  2549. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2550. return
  2551. }
  2552. func GetDrugSumOutCountByDrugId(drug_id int64, user_org_id int64, storehouse_id int64) (models.XtDrugStockCount, error) {
  2553. drug := models.XtDrugStockCount{}
  2554. err := XTReadDB().Where("drug_id = ? and user_org_id = ? and status = 1 and storehouse_id =?", drug_id, user_org_id, storehouse_id).Find(&drug).Error
  2555. return drug, err
  2556. }
  2557. func GetStockGoodList(good_id int64, org_id int64, storehouse_id int64) (models.XtGoodStockCount, error) {
  2558. stockCount := models.XtGoodStockCount{}
  2559. err = XTReadDB().Where("good_id = ? and user_org_id = ? and status= 1 and storehouse_id = ?", good_id, org_id, storehouse_id).Find(&stockCount).Error
  2560. return stockCount, err
  2561. }
  2562. func GetLastOrderTX(user_org_id int64) (models.HisOrder, error) {
  2563. order := models.HisOrder{}
  2564. err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Last(&order).Error
  2565. return order, err
  2566. }
  2567. func GetPatientPlan(orgid int64) (patient []*models.XtPatients, err error) {
  2568. err = XTReadDB().Where("user_org_id = ? and status= 1", orgid).Find(&patient).Error
  2569. return patient, err
  2570. }
  2571. func UpdatePatienPlan(id int64, trement_plan string) error {
  2572. err := XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status = 1", id).Update(map[string]interface{}{"treatment_plan": trement_plan}).Error
  2573. return err
  2574. }
  2575. func GetDialysisOrderList(orgid int64) (order []*models.XtDialysisOrder, err error) {
  2576. err = XTReadDB().Where("user_org_id = ? and status= 1 and url<>''", orgid).Group("patient_id").Find(&order).Error
  2577. return order, err
  2578. }
  2579. func UpdatePatientDialysisOrder(patient_id int64, url string) error {
  2580. err := XTWriteDB().Model(&models.XtPatients{}).Where("id =? and status=1", patient_id).Updates(map[string]interface{}{"url": url}).Error
  2581. return err
  2582. }
  2583. func GetHisOrderByIDTenOne(order_id string) (order models.HisOrder, err error) {
  2584. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  2585. return
  2586. }
  2587. func GetHisDoctorAdviceInfotwo(id int64) (models.HisDoctorAdviceInfo, error) {
  2588. info := models.HisDoctorAdviceInfo{}
  2589. err := readDb.Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
  2590. return info, err
  2591. }
  2592. func GetHisDoctorAdviceInfothree(org_id int64, record_date int64) (info []*models.HisDoctorAdviceInfo, err error) {
  2593. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&info).Error
  2594. return
  2595. }
  2596. func GetHisPrescriptionProjectByIDFour(org_id int64, record_date int64) (projects []*models.HisPrescriptionProject, err error) {
  2597. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&projects).Error
  2598. return
  2599. }
  2600. func GetHisPrescriptionProjectByIDThree(id int64) (projects models.HisPrescriptionProject, err error) {
  2601. err = readDb.Model(&models.HisPrescriptionProject{}).Where("id = ? AND status = 1", id).First(&projects).Error
  2602. return
  2603. }
  2604. func GetHisPrescriptionProjectByIDTwoone(id int64) (projects models.HisPrescriptionProject, err error) {
  2605. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Preload("HisProject", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2606. return
  2607. }
  2608. func GetMonthNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64, start_date int64, end_date int64) (patients []NewTempPatients, err error) {
  2609. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2610. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2611. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  2612. })
  2613. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1 AND order_status <> 2 AND order_status <> 3 and record_date >= ? and record_date <= ?", org_id, start_date, end_date)
  2614. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  2615. for _, item := range patients {
  2616. for _, sumItem := range item.HisPatient {
  2617. if len(sumItem.VMHisOrders) > 0 {
  2618. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2619. }
  2620. }
  2621. }
  2622. return
  2623. }
  2624. func GetChargeHisPatientList(org_id int64, record_date int64) (order []*HisOrder, err error) {
  2625. err = readDb.Model(&models.HisOrder{}).Preload("Patients", "status = 1").Where("settle_accounts_date = ? and user_org_id = ? AND status = 1 and order_status = 2", record_date, org_id).Find(&order).Error
  2626. return
  2627. }
  2628. func GetGoodByIdIsStop(good_id int64, org_id int64) (models.GoodInfoSeven, error) {
  2629. goodInfoSeven := models.GoodInfoSeven{}
  2630. err = XTReadDB().Where("org_id = ? and status = 1 and find_in_set('停用',good_status) = 0 and id =?", org_id, good_id).Find(&goodInfoSeven).Error
  2631. return goodInfoSeven, err
  2632. }
  2633. func GetHisPrescriptionByBatchNumber(org_id int64, number string) (prescription []*models.HisPrescription, err error) {
  2634. err = readDb.Model(&models.HisPrescription{}).
  2635. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2636. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2637. }).
  2638. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2639. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2640. }).
  2641. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2642. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  2643. }).
  2644. Where("user_org_id = ? AND status = 1 AND batch_number = ?", org_id, number).
  2645. Find(&prescription).Error
  2646. return
  2647. }
  2648. func GetLastHisOrderThree(org_id int64) (err error, o models.HisOrder) {
  2649. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? and status = 1 and order_status = 2", org_id).First(&o).Error
  2650. return
  2651. }
  2652. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  2653. err = readDb.Model(&models.HisOrder{}).Select("max(convert(fa_piao_number,signed)) as fa_piao_number").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Find(&his).Error
  2654. return
  2655. }
  2656. //func GetZuoBiaoNewAllUnChargeHisPatientList(org_id int64, record_date int64) (patients []*NewTempPatients, err error) {
  2657. // db := readDb.Model(&NewTempPatients{})
  2658. //
  2659. // db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2660. // db = db.Preload("Schedule", "status = 1")
  2661. // db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2662. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  2663. // })
  2664. // db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  2665. // err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  2666. //
  2667. // for _, item := range patients {
  2668. // for _, sumItem := range item.HisPatient {
  2669. // if len(sumItem.VMHisOrders) > 0 {
  2670. // sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2671. // }
  2672. // }
  2673. //
  2674. // }
  2675. //
  2676. // return
  2677. //}
  2678. //func GetHisPrescriptionByHisPatientID(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  2679. // err = readDb.Model(&models.HisPrescriptionTen{}).
  2680. // Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = 2 and his_patient_id = 0", org_id, record_date, patient_id).
  2681. // Find(&prescription).Error
  2682. // return
  2683. //}
  2684. func GetHisPrescriptionByHisPatientID(record_date int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  2685. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ? AND p_type = ?", patient_id, org_id, record_date, record_date, 2).
  2686. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  2687. return db.Where("status = 1 AND user_org_id = ?", org_id).
  2688. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2689. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2690. }).
  2691. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2692. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  2693. }).Where("status = 1 and order_status = 1")
  2694. }).Order("record_date desc").Find(&advice).Error
  2695. return
  2696. }
  2697. func GetBatchHisDoctorAdviceByIDs(ids []int64) (list []*models.HisDoctorAdviceInfo, err error) {
  2698. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", ids).Find(&list).Error
  2699. return
  2700. }
  2701. func GetBatchHisProjectByIDs(ids []int64) (list []*models.HisPrescriptionProject, err error) {
  2702. err = readDb.Model(&models.HisPrescriptionProject{}).Where("id in (?) and status = 1", ids).Find(&list).Error
  2703. return
  2704. }
  2705. func UpdatePrescriptionAdvice(drug_id int64, user_org_id int64, price float64, patient_id int64) (models.HisPrescriptionAdviceTemplate, error) {
  2706. adviceTemplate := models.HisPrescriptionAdviceTemplate{}
  2707. err := XTWriteDB().Model(&adviceTemplate).Where("drug_id = ? and user_org_id =? and status =1 and patient_id =?", drug_id, user_org_id, patient_id).Updates(map[string]interface{}{"price": price}).Error
  2708. return adviceTemplate, err
  2709. }
  2710. func UpdateBaseMinPrice(drug_id int64, user_org_id int64, retial_price float64) (models.BaseDrugLib, error) {
  2711. lib := models.BaseDrugLib{}
  2712. err := XTWriteDB().Model(&lib).Where("id = ? and org_id = ?", drug_id, user_org_id).Updates(map[string]interface{}{"min_price": retial_price}).Error
  2713. return lib, err
  2714. }
  2715. func UpdatePrescriptionProject(good_id int64, user_org_id int64, packing_price float64, patient_id int64) (models.HisPrescriptionProjectTemplate, error) {
  2716. projectTemplate := models.HisPrescriptionProjectTemplate{}
  2717. err := XTWriteDB().Model(&projectTemplate).Where("project_id = ? and status=1 and user_org_id =? and patient_id =?", good_id, user_org_id, patient_id).Updates(map[string]interface{}{"price": packing_price}).Error
  2718. return projectTemplate, err
  2719. }
  2720. func UpdateGood(good_id int64, user_org_id int64, packing_price float64) (models.GoodInfo, error) {
  2721. goodInfo := models.GoodInfo{}
  2722. err := XTWriteDB().Model(&goodInfo).Where("id = ? and org_id = ? and status=1", good_id, user_org_id).Updates(map[string]interface{}{"packing_price": packing_price}).Error
  2723. return goodInfo, err
  2724. }
  2725. func GetHistory(id int64, user_org_id int64, tx *gorm.DB) (models.HisDoctorAdviceInfo, error) {
  2726. adviceInfo := models.HisDoctorAdviceInfo{}
  2727. err := tx.Where("id = ? and user_org_id = ? and status=1", id, user_org_id).Find(&adviceInfo).Error
  2728. if err != gorm.ErrRecordNotFound {
  2729. if err != nil {
  2730. tx.Rollback()
  2731. return adviceInfo, err
  2732. }
  2733. }
  2734. return adviceInfo, err
  2735. }
  2736. func GetLastHisDoctorAdviceById(patient_id int64, user_org_id int64, advice_date int64, drug_id int64, tx *gorm.DB) (models.HisDoctorAdviceInfo, error) {
  2737. adviceInfo := models.HisDoctorAdviceInfo{}
  2738. err := tx.Where("patient_id = ? and user_org_id = ? and advice_date = ? and drug_id = ? and status =1", patient_id, user_org_id, advice_date, drug_id).Last(&adviceInfo).Error
  2739. if err != gorm.ErrRecordNotFound {
  2740. if err != nil {
  2741. tx.Rollback()
  2742. return adviceInfo, err
  2743. }
  2744. }
  2745. return adviceInfo, err
  2746. }
  2747. func GetLastHisProjectById(patient_id int64, user_org_id int64, record_date int64, drug_id int64, tx *gorm.DB) (models.HisPrescriptionProject, error) {
  2748. projectInfo := models.HisPrescriptionProject{}
  2749. err := tx.Where("patient_id = ? and user_org_id = ? and record_date = ? and project_id = ? and status =1", patient_id, user_org_id, record_date, drug_id).Last(&projectInfo).Error
  2750. if err != gorm.ErrRecordNotFound {
  2751. if err != nil {
  2752. tx.Rollback()
  2753. return projectInfo, err
  2754. }
  2755. }
  2756. return projectInfo, err
  2757. }
  2758. func GetDrugWarehouseOutInfoByAdviceId(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, tx *gorm.DB) (outInfo []*models.DrugWarehouseOutInfo, err error) {
  2759. err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and drug_id = ? and status=1 and advice_id = 0", patient_id, user_org_id, sys_record_date, drug_id).Find(&outInfo).Error
  2760. if err != gorm.ErrRecordNotFound {
  2761. if err != nil {
  2762. tx.Rollback()
  2763. return outInfo, err
  2764. }
  2765. }
  2766. return outInfo, err
  2767. }
  2768. func GetGoodWarehouseOutInfoByAdviceId(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, tx *gorm.DB) (outInfo []*models.WarehouseOutInfo, err error) {
  2769. err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and good_id = ? and status=1 and project_id = 0", patient_id, user_org_id, sys_record_date, drug_id).Find(&outInfo).Error
  2770. if err != gorm.ErrRecordNotFound {
  2771. if err != nil {
  2772. tx.Rollback()
  2773. return outInfo, err
  2774. }
  2775. }
  2776. return outInfo, err
  2777. }
  2778. func GetDrugWarehouseOutInfoByAdviceIdTwo(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, advice_id int64, tx *gorm.DB) (models.DrugWarehouseOutInfo, error) {
  2779. outInfo := models.DrugWarehouseOutInfo{}
  2780. err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and drug_id = ? and status=1 and advice_id = ?", patient_id, user_org_id, sys_record_date, drug_id, advice_id).Order("id desc").First(&outInfo).Error
  2781. if err != gorm.ErrRecordNotFound {
  2782. if err != nil {
  2783. tx.Rollback()
  2784. return outInfo, err
  2785. }
  2786. }
  2787. return outInfo, err
  2788. }
  2789. func GetDrugAutoOutInfoByAdviceIdTwo(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, advice_id int64, tx *gorm.DB) (models.DrugAutomaticReduceDetail, error) {
  2790. outInfo := models.DrugAutomaticReduceDetail{}
  2791. err = tx.Where("patient_id = ? and org_id =? and record_time = ? and drug_id = ? and status=1 and advice_id = ?", patient_id, user_org_id, sys_record_date, drug_id, advice_id).Order("id desc").First(&outInfo).Error
  2792. if err != gorm.ErrRecordNotFound {
  2793. if err != nil {
  2794. tx.Rollback()
  2795. return outInfo, err
  2796. }
  2797. }
  2798. return outInfo, err
  2799. }
  2800. func GetDrugAutoDetail(patient_id int64, org_id int64, record_time int64, drug_id int64, tx *gorm.DB) (automaticReduceDetail []*models.DrugAutomaticReduceDetail, err error) {
  2801. err = tx.Where("patient_id = ? and org_id = ? and record_time =? and drug_id = ? and status =1 and advice_id = 0", patient_id, org_id, record_time, drug_id).Find(&automaticReduceDetail).Error
  2802. if err != gorm.ErrRecordNotFound {
  2803. if err != nil {
  2804. tx.Rollback()
  2805. return automaticReduceDetail, err
  2806. }
  2807. }
  2808. return automaticReduceDetail, err
  2809. }
  2810. func GetGoodAutoDetail(patient_id int64, org_id int64, record_time int64, good_id int64, tx *gorm.DB) (automaticReduceDetail []*models.AutomaticReduceDetail, err error) {
  2811. err = tx.Where("patient_id = ? and org_id = ? and record_time =? and good_id = ? and status =1 and project_id = 0", patient_id, org_id, record_time, good_id).Find(&automaticReduceDetail).Error
  2812. if err != gorm.ErrRecordNotFound {
  2813. if err != nil {
  2814. tx.Rollback()
  2815. return automaticReduceDetail, err
  2816. }
  2817. }
  2818. return automaticReduceDetail, err
  2819. }
  2820. func UpdateDrugAutoDetail(id int64, advice_id int64, tx *gorm.DB) error {
  2821. drugAutomaticReduceDetail := models.DrugAutomaticReduceDetail{}
  2822. err := tx.Model(&drugAutomaticReduceDetail).Where("id = ? and status=1", id).Updates(map[string]interface{}{"advice_id": advice_id}).Error
  2823. if err != nil {
  2824. tx.Rollback()
  2825. return err
  2826. }
  2827. return err
  2828. }
  2829. func UpdateGoodAutoDetail(id int64, project_id int64, tx *gorm.DB) error {
  2830. automaticReduceDetail := models.AutomaticReduceDetail{}
  2831. err := tx.Model(&automaticReduceDetail).Where("id = ? and status=1", id).Updates(map[string]interface{}{"project_id": project_id}).Error
  2832. if err != nil {
  2833. tx.Rollback()
  2834. return err
  2835. }
  2836. return err
  2837. }
  2838. func UpdateDrugOutInfoByAdviceId(id int64, advice_id int64, tx *gorm.DB) (models.DrugWarehouseOutInfo, error) {
  2839. info := models.DrugWarehouseOutInfo{}
  2840. err := tx.Model(&info).Where("id = ? and status=1", id).Updates(map[string]interface{}{"advice_id": advice_id}).Error
  2841. if err != nil {
  2842. tx.Rollback()
  2843. return info, err
  2844. }
  2845. return info, err
  2846. }
  2847. func UpdateGoodOutInfoByAdviceId(id int64, project_id int64, tx *gorm.DB) (models.WarehouseOutInfo, error) {
  2848. info := models.WarehouseOutInfo{}
  2849. err := tx.Model(&info).Where("id = ? and status=1", id).Updates(map[string]interface{}{"project_id": project_id}).Error
  2850. if err != nil {
  2851. tx.Rollback()
  2852. return info, err
  2853. }
  2854. return info, err
  2855. }
  2856. func ModifyDrugWarehouseOutInfoByNumber(id int64, cha_count int64, tx *gorm.DB) error {
  2857. err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
  2858. err = tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("over_count", gorm.Expr("over_count + ?", cha_count)).Error
  2859. if err != nil {
  2860. tx.Rollback()
  2861. return err
  2862. }
  2863. return err
  2864. }
  2865. func ModifyDrugAuToWarehouseOut(id int64, cha_count int64, tx *gorm.DB) error {
  2866. err := tx.Model(&models.DrugAutomaticReduceDetail{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
  2867. if err != nil {
  2868. tx.Rollback()
  2869. return err
  2870. }
  2871. return err
  2872. }
  2873. func ModifyGoodAuToWarehouseOut(id int64, cha_count int64, tx *gorm.DB) error {
  2874. err := tx.Model(&models.AutomaticReduceDetail{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
  2875. if err != nil {
  2876. tx.Rollback()
  2877. return err
  2878. }
  2879. return err
  2880. }
  2881. func DeleteDrugWarehouseOutInfoByNumber(id int64, tx *gorm.DB) error {
  2882. err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
  2883. if err != nil {
  2884. tx.Rollback()
  2885. return err
  2886. }
  2887. return err
  2888. }
  2889. func DeleteDrugWarehouseAutoByNumber(id int64, tx *gorm.DB) error {
  2890. err := tx.Model(&models.DrugAutomaticReduceDetail{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
  2891. if err != nil {
  2892. tx.Rollback()
  2893. return err
  2894. }
  2895. return err
  2896. }
  2897. func DeleteGoodWarehouseAutoByNumberTwo(id int64, tx *gorm.DB) error {
  2898. err := tx.Model(&models.AutomaticReduceDetail{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
  2899. if err != nil {
  2900. tx.Rollback()
  2901. return err
  2902. }
  2903. return err
  2904. }
  2905. func GetHistoryProject(patient_id int64, user_org_id int64, record_date int64, id int64, good_id int64, tx *gorm.DB) (models.HisPrescriptionProject, error) {
  2906. project := models.HisPrescriptionProject{}
  2907. err := tx.Where("patient_id = ? and user_org_id = ? and record_date = ? and id = ? and project_id = ? and status =1", patient_id, user_org_id, record_date, id, good_id).Find(&project).Error
  2908. if err != gorm.ErrRecordNotFound {
  2909. if err != nil {
  2910. tx.Rollback()
  2911. return project, err
  2912. }
  2913. }
  2914. return project, err
  2915. }
  2916. func GetGoodWarehouseOutInfoByProjectIdTwo(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, advice_id int64, tx *gorm.DB) (models.WarehouseOutInfo, error) {
  2917. outInfo := models.WarehouseOutInfo{}
  2918. err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and good_id = ? and status=1 and project_id = ?", patient_id, user_org_id, sys_record_date, drug_id, advice_id).Order("id desc").First(&outInfo).Error
  2919. if err != gorm.ErrRecordNotFound {
  2920. if err != nil {
  2921. tx.Rollback()
  2922. return outInfo, err
  2923. }
  2924. }
  2925. return outInfo, err
  2926. }
  2927. func GetGoodWarehouseOutInfoByProjectIdThree(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, tx *gorm.DB) (models.WarehouseOutInfo, error) {
  2928. outInfo := models.WarehouseOutInfo{}
  2929. err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and good_id = ? and status=1", patient_id, user_org_id, sys_record_date, drug_id).Order("id desc").Last(&outInfo).Error
  2930. if err != gorm.ErrRecordNotFound {
  2931. if err != nil {
  2932. tx.Rollback()
  2933. return outInfo, err
  2934. }
  2935. }
  2936. return outInfo, err
  2937. }
  2938. func DeleteGoodWarehouseOutInfoByNumber(id int64, tx *gorm.DB) error {
  2939. err := tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
  2940. if err != nil {
  2941. tx.Rollback()
  2942. return err
  2943. }
  2944. return err
  2945. }
  2946. func ModifyGoodWarehouseOutInfoByNumber(id int64, cha_count int64, tx *gorm.DB) error {
  2947. err := tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
  2948. err = tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("over_count", gorm.Expr("over_count + ?", cha_count)).Error
  2949. if err != nil {
  2950. tx.Rollback()
  2951. return err
  2952. }
  2953. return err
  2954. }
  2955. func GetBasedrugById(drug_id int64, user_org_id int64) (models.BaseDrugLib, error) {
  2956. lib := models.BaseDrugLib{}
  2957. err := XTReadDB().Where("id = ? and org_id =? and status=1 AND find_in_set('停用',drug_status) = 1", drug_id, user_org_id).Find(&lib).Error
  2958. return lib, err
  2959. }
  2960. func GetBaseGoodById(good_id int64, user_org_id int64) (models.GoodInfo, error) {
  2961. info := models.GoodInfo{}
  2962. err := XTReadDB().Where("id = ? and org_id =? and status=1 AND find_in_set('停用',good_status) = 1", good_id, user_org_id).Find(&info).Error
  2963. return info, err
  2964. }
  2965. func GetBasedrugByIdOne(drug_id int64, user_org_id int64) (models.BaseDrugLib, error) {
  2966. lib := models.BaseDrugLib{}
  2967. err := XTReadDB().Where("id = ? and org_id =? and status=1", drug_id, user_org_id).Find(&lib).Error
  2968. return lib, err
  2969. }
  2970. //func UpDateOrderT111(order models.histen) (err error) {
  2971. // err = writeDb.Save(&order).Error
  2972. // return
  2973. //}
  2974. func GetDialysisPresriptionById(user_org_id int64, patient_id int64, record_date int64) (models.HisPrescriptionInfo, error) {
  2975. prescriptionInfo := models.HisPrescriptionInfo{}
  2976. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and record_date = ? and status=1", user_org_id, patient_id, record_date).First(&prescriptionInfo).Error
  2977. return prescriptionInfo, err
  2978. }
  2979. func CreateGoodTeam(team models.XtGoodTeam) error {
  2980. err := XTWriteDB().Create(&team).Error
  2981. return err
  2982. }
  2983. func SaveGoodTeam(team models.XtGoodTeam) error {
  2984. err := XTWriteDB().Save(&team).Error
  2985. return err
  2986. }
  2987. func GetLastGoodTeam(org_id int64) (models.XtGoodTeam, error) {
  2988. goodTeam := models.XtGoodTeam{}
  2989. err := XTReadDB().Where("user_org_id = ? and status=1", org_id).Last(&goodTeam).Error
  2990. return goodTeam, err
  2991. }
  2992. func CreateGoodList(list models.XtGoodTeamList) error {
  2993. err := XTWriteDB().Create(&list).Error
  2994. return err
  2995. }
  2996. func SaveGoodList(list models.XtGoodTeamList) error {
  2997. err := XTWriteDB().Save(&list).Error
  2998. return err
  2999. }
  3000. func GetGoodList(user_org_id int64, limit int64, page int64, keyword string) (list []*models.XtGoodTeam, total int64, err error) {
  3001. key := "%" + keyword + "%"
  3002. offset := (page - 1) * limit
  3003. db := XTReadDB().Model(&list).Where("status=1")
  3004. if user_org_id > 0 {
  3005. db = db.Where("user_org_id = ?", user_org_id)
  3006. }
  3007. if len(keyword) > 0 {
  3008. db = db.Where("project_name like ?", key)
  3009. }
  3010. err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Find(&list).Error
  3011. return list, total, err
  3012. }
  3013. func GetGoodNameDetail(id int64, org_id int64) (models.XtGoodTeam, error) {
  3014. goodTeam := models.XtGoodTeam{}
  3015. err := XTReadDB().Where("id = ? and status =1 and user_org_id = ?", id, org_id).Preload("XtGoodTeamList", "status = 1 and user_org_id = ?", org_id).Find(&goodTeam).Error
  3016. return goodTeam, err
  3017. }
  3018. func DeleteGoodTeam(id int64) (models.XtGoodTeamList, error) {
  3019. goodTeamList := models.XtGoodTeamList{}
  3020. err := XTWriteDB().Model(&goodTeamList).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
  3021. return goodTeamList, err
  3022. }
  3023. func DeleteGood(id int64) (models.XtGoodTeam, error) {
  3024. goodTeam := models.XtGoodTeam{}
  3025. err := XTWriteDB().Model(&goodTeam).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3026. return goodTeam, err
  3027. }