his_service.go 173KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strings"
  7. "time"
  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. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  108. HisPatient HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  109. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  110. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  111. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
  112. }
  113. func (Patients) TableName() string {
  114. return "xt_patients"
  115. }
  116. type HisPrescription struct {
  117. ID int64 `gorm:"column:id" json:"id" form:"id"`
  118. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  119. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  120. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  121. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  122. Status int64 `gorm:"column:status" json:"status" form:"status"`
  123. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  124. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  125. }
  126. func (HisPrescription) TableName() string {
  127. return "his_prescription"
  128. }
  129. func GetScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*Patients, err error) {
  130. db := readDb.Model(&Patients{}).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)
  131. if sch_type != 0 {
  132. 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)
  133. } else {
  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 = ? ", record_date, org_id)
  135. }
  136. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  137. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  138. 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
  139. return
  140. }
  141. func GetChargeHisPatientListOne(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  142. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  143. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  144. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  145. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  146. return
  147. }
  148. func GetAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  149. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  150. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  151. db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  152. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  153. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  154. return
  155. }
  156. func GetChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  157. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  158. 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)
  159. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  160. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  161. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  162. return
  163. }
  164. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  165. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  166. 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)
  167. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  168. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  169. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  170. return
  171. }
  172. type PatientTwo struct {
  173. ID int64 `gorm:"column:id" json:"id" form:"id"`
  174. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  175. Name string `gorm:"column:name" json:"name" form:"name"`
  176. Status int64 `gorm:"column:status" json:"status" form:"status"`
  177. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  178. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  179. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  180. HisPatient []*HisPatientTwo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  181. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  182. }
  183. func (PatientTwo) TableName() string {
  184. return "xt_patients"
  185. }
  186. type HisPatientTwo struct {
  187. ID int64 `gorm:"column:id" json:"id" form:"id"`
  188. Name string `gorm:"column:name" json:"name" form:"name"`
  189. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  190. Total float64 `gorm:"column:total" json:"total" form:"total"`
  191. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  192. Status int64 `gorm:"column:status" json:"status" form:"status"`
  193. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  194. HisPrescriptionTwo []*HisPrescriptionTwo `gorm:"ForeignKey:PatientId,HisPatientId;AssociationForeignKey:PatientId,ID" json:"prescription"`
  195. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  196. Number string `gorm:"column:number" json:"number" form:"number"`
  197. }
  198. func (HisPatientTwo) TableName() string {
  199. return "his_patient"
  200. }
  201. type HisPrescriptionTwo struct {
  202. ID int64 `gorm:"column:id" json:"id" form:"id"`
  203. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  204. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  205. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  206. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  207. Status int64 `gorm:"column:status" json:"status" form:"status"`
  208. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  209. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  210. Number string `gorm:"column:number" json:"number" form:"number"`
  211. Type int64 `gorm:"column:type" json:"type" form:"type"`
  212. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  213. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  214. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  215. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  216. PreTime int64 `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
  217. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  218. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  219. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  220. }
  221. func (HisPrescriptionTwo) TableName() string {
  222. return "his_prescription"
  223. }
  224. func GetNewHisPatientList(org_id int64, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  225. db := readDb.Model(&PatientTwo{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  226. 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)
  227. if sch_type > 0 {
  228. 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)
  229. }
  230. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  231. 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)
  232. })
  233. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("id").Find(&patients).Error
  234. return
  235. }
  236. func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  237. 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)
  238. if sch_type != 0 {
  239. 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)
  240. } else {
  241. 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)
  242. }
  243. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  244. 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
  245. return
  246. }
  247. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  248. err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&drugs).Error
  249. return
  250. }
  251. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  252. 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
  253. return
  254. }
  255. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  256. 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
  257. return
  258. }
  259. func GetHisPatientInfoThree(org_id int64, number string) (info models.HisPatient, err error) {
  260. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND number = ?", org_id, number).First(&info).Error
  261. return
  262. }
  263. func GetHisPatientInfoTen(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  264. 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
  265. return
  266. }
  267. func GetHisPatientInfoFour(org_id int64, patient_id int64, record_date int64, his_patient_id int64) (info models.HisPatient, err error) {
  268. 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
  269. return
  270. }
  271. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  272. 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
  273. return
  274. }
  275. func GetNewHisPatientInfoTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  276. 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
  277. return
  278. }
  279. func GetNewHisHosptialRecordTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  280. 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
  281. return
  282. }
  283. func GetHisPatientCount(org_id int64, patient_id int64, record_date int64) (total int64, err error) {
  284. 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
  285. return
  286. }
  287. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  288. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  289. return
  290. }
  291. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  292. 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
  293. return
  294. }
  295. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  296. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  297. err = db.Find(&caseHistorys).Error
  298. return
  299. }
  300. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  301. likekey := "%" + keyword + "%"
  302. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  303. if startime > 0 {
  304. db = db.Where("record_date>=?", startime)
  305. }
  306. if endtime > 0 {
  307. db = db.Where("record_date<=?", endtime)
  308. }
  309. if len(keyword) > 0 {
  310. db = db.Where("template_name like ? ", likekey)
  311. }
  312. err = db.Find(&caseHistorys).Error
  313. return
  314. }
  315. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  316. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  317. return caseHistory, err
  318. }
  319. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  320. err = writeDb.Create(&template).Error
  321. return
  322. }
  323. func GetHisPatientCaseHistoryById(patient_id int64, record_date int64, user_org_id int64) (*models.HisPatientCaseHistory, error) {
  324. history := models.HisPatientCaseHistory{}
  325. 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
  326. if err != nil {
  327. if err == gorm.ErrRecordNotFound {
  328. return nil, err
  329. } else {
  330. return nil, err
  331. }
  332. }
  333. return &history, nil
  334. }
  335. func GetLastHisPatientCaseHistoryById(patient_id int64) (models.HisPatientCaseHistory, error) {
  336. history := models.HisPatientCaseHistory{}
  337. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1", patient_id).Last(&history).Error
  338. return history, err
  339. }
  340. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  341. err := writeDb.Create(&caseHistory).Error
  342. return err
  343. }
  344. func UpdatePatientCaseHistory(patient_id int64, record_date int64, user_org_id int64, his *models.HisPatientCaseHistory) error {
  345. 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
  346. return err
  347. }
  348. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  349. tx := writeDb.Begin()
  350. if err = tx.Model(&models.HisPrescription{}).Save(prescription).Error; err != nil {
  351. tx.Rollback()
  352. return
  353. }
  354. tx.Commit()
  355. return
  356. }
  357. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  358. 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
  359. 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
  360. 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
  361. return
  362. }
  363. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  364. 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
  365. return
  366. }
  367. func DelelteProject(id int64, user_org_id int64) (err error) {
  368. 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
  369. return
  370. }
  371. func GetHisPrescription(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  372. err = readDb.Model(&models.HisPrescription{}).
  373. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  374. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  375. }).
  376. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  377. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  378. }).
  379. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  380. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  381. }).
  382. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ?", org_id, record_date, patient_id, p_type).
  383. Find(&prescription).Error
  384. return
  385. }
  386. func GetNewHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  387. err = readDb.Model(&models.HisPrescription{}).
  388. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  389. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  390. }).
  391. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  392. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  393. }).
  394. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  395. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  396. }).
  397. 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).
  398. Find(&prescription).Error
  399. return
  400. }
  401. func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  402. err = readDb.Model(&models.HisPrescription{}).
  403. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  404. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  405. }).
  406. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  407. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  408. }).
  409. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  410. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  411. }).
  412. 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).
  413. Find(&prescription).Error
  414. return
  415. }
  416. func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  417. err = readDb.Model(&models.HisPrescription{}).
  418. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  419. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  420. }).
  421. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  422. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  423. }).
  424. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  425. 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")
  426. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  427. return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3 AND order_status <> 2 ", org_id)
  428. }).
  429. 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).
  430. Find(&prescription).Error
  431. return
  432. }
  433. func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  434. err = readDb.Model(&models.HisPrescription{}).
  435. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  436. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  437. }).
  438. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  439. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  440. }).
  441. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  442. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  443. }).
  444. 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).
  445. Find(&prescription).Error
  446. return
  447. }
  448. 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) {
  449. err = tx.Model(&models.HisPrescription{}).
  450. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  451. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  452. }).
  453. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  454. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  455. }).
  456. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  457. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  458. }).
  459. 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).
  460. Find(&prescription).Error
  461. return
  462. }
  463. 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) {
  464. err = tx.Model(&models.HisPrescription{}).
  465. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  466. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  467. }).
  468. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  469. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  470. }).
  471. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  472. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  473. }).
  474. 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).
  475. Find(&prescription).Error
  476. return
  477. }
  478. func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  479. err = readDb.Model(&models.HisPrescription{}).
  480. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  481. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  482. }).
  483. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  484. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  485. }).
  486. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  487. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  488. }).
  489. 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).
  490. Find(&prescription).Error
  491. return
  492. }
  493. 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) {
  494. err = tx.Model(&models.HisPrescription{}).
  495. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  496. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  497. }).
  498. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  499. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  500. }).
  501. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  502. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  503. }).
  504. 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).
  505. Find(&prescription).Error
  506. return
  507. }
  508. 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) {
  509. err = tx.Model(&models.HisPrescription{}).
  510. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  511. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  512. }).
  513. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  514. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  515. }).
  516. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  517. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  518. }).
  519. 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).
  520. Find(&prescription).Error
  521. return
  522. }
  523. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  524. err = readDb.Model(&models.HisPrescription{}).
  525. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  526. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  527. }).
  528. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  529. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  530. }).
  531. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  532. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  533. }).
  534. 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).
  535. Find(&prescription).Error
  536. return
  537. }
  538. func GetMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  539. err = readDb.Model(&models.HisPrescription{}).
  540. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  541. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  542. }).
  543. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  544. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  545. }).
  546. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  547. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  548. }).
  549. 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).
  550. Find(&prescription).Error
  551. return
  552. }
  553. // 未收费
  554. func GetUnChargeMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  555. err = readDb.Model(&models.HisPrescription{}).
  556. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  557. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  558. }).
  559. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  560. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  561. }).
  562. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  563. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  564. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  565. return db.Where("status = 1 AND user_org_id = ?", org_id)
  566. }).
  567. 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).
  568. Find(&prescription).Error
  569. return
  570. }
  571. // 已收费
  572. func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  573. err = readDb.Model(&models.HisPrescription{}).
  574. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  575. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  576. }).
  577. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  578. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  579. }).
  580. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  581. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  582. }).
  583. 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).
  584. Find(&prescription).Error
  585. return
  586. }
  587. func GetUnChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
  588. err = readDb.Model(&models.HisPrescription{}).
  589. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  590. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  591. }).
  592. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  593. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  594. }).
  595. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  596. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  597. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  598. return db.Where("status = 1 AND user_org_id = ?", org_id)
  599. }).
  600. 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).
  601. Find(&prescription).Error
  602. return
  603. }
  604. type OtherDrugWarehouseInfo struct {
  605. ID int64 `gorm:"column:id" json:"id" form:"id"`
  606. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  607. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  608. Status int64 `gorm:"column:status" json:"status" form:"status"`
  609. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  610. StockMaxNumber int64 `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
  611. StockMinNumber int64 `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
  612. Price float64 `gorm:"column:price" json:"price" form:"price"`
  613. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  614. }
  615. func (OtherDrugWarehouseInfo) TableName() string {
  616. return "xt_drug_warehouse_info"
  617. }
  618. type VMDrugSalesReturnInfo struct {
  619. ID int64 `gorm:"column:id" json:"id" form:"id"`
  620. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  621. Count int64 `gorm:"column:count" json:"count" form:"count"`
  622. Status int64 `gorm:"column:status" json:"status" form:"status"`
  623. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  624. }
  625. func (VMDrugSalesReturnInfo) TableName() string {
  626. return "xt_drug_sales_return_info"
  627. }
  628. type VMDrugWarehouseOutInfo struct {
  629. ID int64 `gorm:"column:id" json:"id" form:"id"`
  630. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  631. Count int64 `gorm:"column:count" json:"count" form:"count"`
  632. Status int64 `gorm:"column:status" json:"status" form:"status"`
  633. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  634. }
  635. func (VMDrugWarehouseOutInfo) TableName() string {
  636. return "xt_drug_warehouse_out_info"
  637. }
  638. type VMDrugCancelStockInfo struct {
  639. ID int64 `gorm:"column:id" json:"id" form:"id"`
  640. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  641. Count int64 `gorm:"column:count" json:"count" form:"count"`
  642. Status int64 `gorm:"column:status" json:"status" form:"status"`
  643. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  644. }
  645. func (VMDrugCancelStockInfo) TableName() string {
  646. return "xt_drug_cancel_stock_info"
  647. }
  648. type BaseDrugLib struct {
  649. ID int64 `gorm:"column:id" json:"id" form:"id"`
  650. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  651. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  652. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  653. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  654. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  655. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  656. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  657. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  658. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  659. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  660. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  661. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  662. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  663. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  664. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  665. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  666. Dose string `gorm:"column:dose" json:"dose" form:"dose"`
  667. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  668. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  669. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  670. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  671. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  672. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  673. Number string `gorm:"column:number" json:"number" form:"number"`
  674. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  675. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  676. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  677. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  678. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  679. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  680. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  681. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  682. Code string `gorm:"column:code" json:"code" form:"code"`
  683. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  684. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  685. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  686. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  687. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  688. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  689. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  690. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  691. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  692. Label int64 `gorm:"column:label" json:"label" form:"label"`
  693. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  694. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  695. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  696. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  697. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  698. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  699. Status int64 `gorm:"column:status" json:"status" form:"status"`
  700. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  701. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  702. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  703. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  704. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  705. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  706. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  707. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  708. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  709. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  710. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  711. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  712. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  713. Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  714. Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  715. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  716. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  717. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  718. Total float64 `gorm:"column:total" json:"total" form:"total"`
  719. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  720. BatchRetaiPrice float64 `gorm:"column:batch_retai_price" json:"batch_retai_price" form:"batch_retai_price"`
  721. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  722. SumCount int64 `gorm:"column:sum_count" json:"sum_count" form:"sum_count"`
  723. SumInCount int64 `gorm:"column:sum_in_count" json:"sum_in_count" form:"sum_in_count"`
  724. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  725. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  726. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  727. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  728. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  729. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  730. }
  731. func (BaseDrugLib) TableName() string {
  732. return "xt_base_drug"
  733. }
  734. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  735. 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 {
  736. return db.Where("(status = 1 and stock_max_number > 0) or (status = 1 AND stock_min_number >0)")
  737. }).Find(&list).Error
  738. //err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Find(&list).Error
  739. return
  740. }
  741. func GetAllDrugLibListSix(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  742. 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 {
  743. 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)
  744. }).Find(&list).Error
  745. return
  746. }
  747. func GetAllDrugLibListSeven(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  748. 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 {
  749. return db.Where("(status = 1 and storehouse_id = ? ) or (status = 1 and storehouse_id = ?)", storehouse_id, storehouse_id)
  750. }).Find(&list).Error
  751. return
  752. }
  753. func GetAllDrugLibs(org_id int64) (drugs []*Drugs, err error) {
  754. 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")
  755. err = db.Find(&drugs).Error
  756. return
  757. }
  758. func GetAllProjectList(org_id int64, keyword string) (list []*models.HisProject, err error) {
  759. if len(keyword) != 0 {
  760. key := "%" + keyword + "%"
  761. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 AND project_name Like ? ", org_id, key).Find(&list).Error
  762. } else {
  763. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 ", org_id).Find(&list).Error
  764. }
  765. return
  766. }
  767. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  768. err = writeDb.Create(&charge).Error
  769. return
  770. }
  771. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  772. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  773. 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")
  774. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  775. return
  776. }
  777. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  778. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  779. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  780. }).Where("org_id = ? AND status = 1 AND user_type = 2", org_id).Find(&doctors).Error
  781. return
  782. }
  783. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  784. tx := writeDb.Begin()
  785. if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
  786. tx.Rollback()
  787. return
  788. }
  789. tx.Commit()
  790. return
  791. }
  792. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  793. tx := writeDb.Begin()
  794. if err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error; err != nil {
  795. tx.Rollback()
  796. return
  797. }
  798. tx.Commit()
  799. return
  800. }
  801. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  802. err = writeDb.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
  803. return
  804. }
  805. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  806. err := writeDb.Create(&patient).Error
  807. return err
  808. }
  809. func GetVMHisPatientInfo(org_id int64, id int64, record_date int64) (info models.VMHisPatient, err error) {
  810. 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
  811. return
  812. }
  813. func CreateOrder(order *models.HisOrder) (err error) {
  814. err = writeDb.Create(&order).Error
  815. return
  816. }
  817. func CreateOrderTX(order *models.HisOrder, tx *gorm.DB) (err error) {
  818. err = tx.Create(&order).Error
  819. return
  820. }
  821. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  822. err = writeDb.Create(&order).Error
  823. return
  824. }
  825. func CreateOrderInfoTX(order *models.HisOrderInfo, tx *gorm.DB) (err error) {
  826. err = tx.Create(&order).Error
  827. return
  828. }
  829. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  830. 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
  831. return
  832. }
  833. func FindPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  834. 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
  835. return
  836. }
  837. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  838. 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
  839. return
  840. }
  841. func FindHisPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  842. 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
  843. return
  844. }
  845. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  846. 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
  847. return
  848. }
  849. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  850. tx := writeDb.Begin()
  851. if err = tx.Model(&models.HisPrescription{}).Save(&info).Error; err != nil {
  852. tx.Rollback()
  853. return
  854. }
  855. tx.Commit()
  856. return
  857. }
  858. 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) (order []*models.HisOrder, err error, total int64) {
  859. offset := (page - 1) * limit
  860. db := readDb.Model(&models.HisOrder{})
  861. if doctor_id > 0 {
  862. 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)
  863. }
  864. if len(keywords) > 0 {
  865. keywords = "%" + keywords + "%"
  866. 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)
  867. }
  868. if sch_type > 0 && zone_type > 0 {
  869. 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)
  870. }
  871. if sch_type > 0 && zone_type == 0 {
  872. 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)
  873. }
  874. if sch_type == 0 && zone_type > 0 {
  875. 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)
  876. }
  877. //if zone_type > 0 {
  878. // 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)
  879. //}
  880. if sort_type == 1 {
  881. if start_time_timestamp != 0 {
  882. db = db.Where("his_order.settle_accounts_date>=?", start_time_timestamp)
  883. }
  884. if end_time_timestamp != 0 {
  885. db = db.Where("his_order.settle_accounts_date<=?", end_time_timestamp)
  886. }
  887. } else {
  888. if len(start_time) != 0 {
  889. db = db.Where("his_order.setl_time>=?", start_time+" 00:00:00")
  890. }
  891. if len(end_time) != 0 {
  892. db = db.Where("his_order.setl_time<=?", end_time+" 23:59:59")
  893. }
  894. }
  895. if p_type > 0 {
  896. 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)
  897. } else {
  898. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2", user_org_id)
  899. }
  900. if charge_type > 0 {
  901. if charge_type == 2 {
  902. db = db.Where("his_order.is_medicine_insurance = 0")
  903. } else {
  904. db = db.Where("his_order.is_medicine_insurance = ?", charge_type)
  905. }
  906. }
  907. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  908. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  909. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  910. Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ?", user_org_id)
  911. db = db.Preload("HisFundSettleListResult", "status = 1")
  912. db = db.Count(&total)
  913. db = db.Limit(limit).Offset(offset)
  914. if user_org_id == 10215 {
  915. if sort_type == 1 {
  916. err = db.Order("settle_accounts_date asc,ctime asc").Group("his_order.id").Find(&order).Error
  917. }
  918. if sort_type == 2 {
  919. err = db.Order("setl_time asc,ctime asc").Group("his_order.id").Find(&order).Error
  920. }
  921. } else {
  922. if sort_type == 1 {
  923. err = db.Order("settle_accounts_date desc,ctime desc").Group("his_order.id").Find(&order).Error
  924. }
  925. if sort_type == 2 {
  926. err = db.Order("setl_time desc,ctime desc").Group("his_order.id").Find(&order).Error
  927. }
  928. }
  929. return
  930. }
  931. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  932. 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
  933. return
  934. }
  935. func UpDatePrescriptionNumberTX(user_org_id int64, ids []int64, number string, tx *gorm.DB) (err error) {
  936. 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
  937. return
  938. }
  939. func UpDateAddtionNumber(user_org_id int64, ids []int64, number string) (err error) {
  940. 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
  941. return
  942. }
  943. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  944. 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
  945. return
  946. }
  947. func UpDateHisPrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64) (err error) {
  948. 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
  949. return
  950. }
  951. func UpDateHisPrescriptionInfoNumberTX(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64, tx *gorm.DB) (err error) {
  952. 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
  953. return
  954. }
  955. func UpDateHospitalHisPrescriptionInfoNumber(user_org_id int64, number string, start_time int64, end_time int64) (err error) {
  956. 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
  957. return
  958. }
  959. type HisOrder struct {
  960. ID int64 `gorm:"column:id" json:"id" form:"id"`
  961. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  962. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  963. Number string `gorm:"column:number" json:"number" form:"number"`
  964. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  965. Status int64 `gorm:"column:status" json:"status" form:"status"`
  966. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  967. Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"`
  968. WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
  969. Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
  970. ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
  971. RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
  972. InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
  973. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  974. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  975. SetlId string `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
  976. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  977. PsnType string `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
  978. CvlservFlag string `gorm:"column:cvlserv_flag" json:"cvlserv_flag" form:"cvlserv_flag"`
  979. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  980. MdtrtCertType string `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
  981. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  982. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  983. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  984. OverlmtSelfPay float64 `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
  985. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  986. InscpScpAmt float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
  987. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  988. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  989. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  990. PoolPropSelfpay float64 `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
  991. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  992. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  993. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  994. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  995. OthPay float64 `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
  996. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  997. PsnPartAmt float64 `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
  998. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  999. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1000. HospPartAmt float64 `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
  1001. Balc float64 `gorm:"column:balc" json:"balc" form:"balc"`
  1002. AcctMulaidPay float64 `gorm:"column:acct_mulaid_pay" json:"acct_mulaid_pay" form:"acct_mulaid_pay"`
  1003. MedinsSetlId string `gorm:"column:medins_setl_id" json:"medins_setl_id" form:"medins_setl_id"`
  1004. ClrOptins string `gorm:"column:clr_optins" json:"clr_optins" form:"clr_optins"`
  1005. ClrWay string `gorm:"column:clr_way" json:"clr_way" form:"clr_way"`
  1006. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1007. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1008. IsMedicineInsurance int64 `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
  1009. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1010. SettleType int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
  1011. SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
  1012. SettleEndTime int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
  1013. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1014. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1015. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1016. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1017. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1018. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1019. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1020. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1021. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1022. }
  1023. func (HisOrder) TableName() string {
  1024. return "his_order"
  1025. }
  1026. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  1027. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1028. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1029. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  1030. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  1031. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1032. Order("ctime desc").
  1033. Find(&order).Error
  1034. return
  1035. }
  1036. func GetHisPrescriptionThree(org_id int64, patient_id int64, number string) (prescription []*models.HisPrescription, err error) {
  1037. err = readDb.Model(&models.HisPrescription{}).
  1038. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1039. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1040. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1041. }).
  1042. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1043. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND batch_number=?", org_id, patient_id, number).
  1044. Find(&prescription).Error
  1045. return
  1046. }
  1047. type HisPrescriptionInfo struct {
  1048. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1049. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1050. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1051. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1052. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1053. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1054. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1055. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1056. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1057. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1058. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1059. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  1060. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1061. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1062. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  1063. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1064. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  1065. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  1066. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1067. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1068. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  1069. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1070. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1071. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1072. }
  1073. func (HisPrescriptionInfo) TableName() string {
  1074. return "his_prescription_info"
  1075. }
  1076. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  1077. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  1078. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1079. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1080. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  1081. Order("ctime desc").Find(&prescriptionOrder).Error
  1082. return
  1083. }
  1084. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  1085. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, org_id).
  1086. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1087. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1088. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  1089. return
  1090. }
  1091. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  1092. err = readDb.Model(&models.HisPrescription{}).
  1093. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1094. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1095. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  1096. }).
  1097. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  1098. Find(&prescription).Error
  1099. return
  1100. }
  1101. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  1102. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  1103. return
  1104. }
  1105. func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
  1106. 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
  1107. 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
  1108. 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
  1109. return
  1110. }
  1111. func UpdataHospitalOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  1112. 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
  1113. 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
  1114. 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
  1115. return
  1116. }
  1117. func UpdataOrderInfoStatus(id int64, number string, user_org_id int64) {
  1118. 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
  1119. 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
  1120. return
  1121. }
  1122. func SaveHisPatient(his models.HisPatient) (err error) {
  1123. 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()})
  1124. 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()})
  1125. 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()})
  1126. return
  1127. }
  1128. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  1129. 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()})
  1130. }
  1131. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  1132. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  1133. return
  1134. }
  1135. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  1136. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1137. First(&order).Error
  1138. return
  1139. }
  1140. func UpDateOrder(order models.HisOrder) (err error) {
  1141. err = writeDb.Save(&order).Error
  1142. return
  1143. }
  1144. func UpDateOrderTX(order models.HisOrder, tx *gorm.DB) (err error) {
  1145. err = writeDb.Save(&order).Error
  1146. return
  1147. }
  1148. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  1149. 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
  1150. 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
  1151. return
  1152. }
  1153. func UpdataOrderStatusTwoTX(number string, user_org_id int64, tx *gorm.DB) (err error) {
  1154. 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
  1155. 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
  1156. return
  1157. }
  1158. func CreateErrMsgLog(log *models.HisOrderError) {
  1159. writeDb.Model(&models.HisOrderError{}).Create(&log)
  1160. }
  1161. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  1162. 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
  1163. return
  1164. }
  1165. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  1166. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  1167. return
  1168. }
  1169. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  1170. db := readDb.Model(&models.OutpatientServiceSick{})
  1171. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1172. err = db.Order("ctime desc").Find(&list).Error
  1173. return
  1174. }
  1175. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  1176. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  1177. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1178. err = db.Order("ctime desc").Find(&list).Error
  1179. return
  1180. }
  1181. func FindPatientDianose(orgId int64) (list []*models.XtPatientDiagnose, err error) {
  1182. err = readDb.Where("user_org_id =?", orgId).Find(&list).Error
  1183. return list, err
  1184. }
  1185. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  1186. db := readDb.Model(&models.XtHisAddtionConfig{})
  1187. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1188. err = db.Order("ctime desc").Find(&list).Error
  1189. return
  1190. }
  1191. type XtHisOrder struct {
  1192. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1193. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1194. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1195. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1196. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1197. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1198. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1199. Number string `gorm:"column:number" json:"number" form:"number"`
  1200. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1201. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1202. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1203. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1204. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1205. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1206. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1207. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1208. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1209. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1210. }
  1211. func (XtHisOrder) TableName() string {
  1212. return "his_order"
  1213. }
  1214. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  1215. err = readDb.Model(&models.HisPrescription{}).
  1216. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  1217. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1218. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1219. }).
  1220. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1221. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  1222. Find(&prescription).Error
  1223. return
  1224. }
  1225. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  1226. 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
  1227. return
  1228. }
  1229. func DelelteAddition(id int64, user_org_id int64) (err error) {
  1230. 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
  1231. return
  1232. }
  1233. func GetNewHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64, sch_type int64) (patients []*VMHisHospitalPrescriptionInfo, err error, total int64) {
  1234. offset := (page - 1) * limit
  1235. 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)
  1236. if len(keywords) > 0 {
  1237. keywords = "%" + keywords + "%"
  1238. db = db.Joins("JOIN xt_patients On his_prescription_info.patient_id = xt_patients.id AND xt_patients.name like ?", keywords)
  1239. }
  1240. if sch_type > 0 {
  1241. 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)
  1242. }
  1243. db = db.Preload("Patients", "xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1244. db = db.Preload("HisPrescription", "his_prescription.user_org_id = ? AND his_prescription.status = 1 AND his_prescription.p_type <> 1", org_id)
  1245. db = db.Count(&total)
  1246. err = db.Limit(limit).Offset(offset).Group("his_prescription_info.id").Find(&patients).Error
  1247. return
  1248. }
  1249. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
  1250. offset := (page - 1) * limit
  1251. db := readDb.Model(&VMSchedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  1252. if len(keywords) > 0 {
  1253. keywords = "%" + keywords + "%"
  1254. 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)
  1255. 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)
  1256. }
  1257. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  1258. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  1259. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id).
  1260. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id)
  1261. db = db.Count(&total)
  1262. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  1263. return
  1264. }
  1265. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  1266. patient := models.VMHisPatient{}
  1267. 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
  1268. return patient, err
  1269. }
  1270. type VMOtherHisPrescriptionInfo struct {
  1271. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1272. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1273. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1274. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1275. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1276. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  1277. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1278. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1279. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  1280. }
  1281. func (VMOtherHisPrescriptionInfo) TableName() string {
  1282. return "his_prescription_info"
  1283. }
  1284. type VMHisPrescription struct {
  1285. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1286. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1287. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1288. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1289. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1290. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1291. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1292. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1293. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1294. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  1295. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1296. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1297. }
  1298. func (VMHisPrescription) TableName() string {
  1299. return "his_prescription"
  1300. }
  1301. func GetHisPrescriptionByType(change_type int64, record_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1302. if change_type == 1 { //根据日期取出上一方数据
  1303. var Id AdviceDate
  1304. 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
  1305. 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).
  1306. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1307. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1308. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1309. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1310. }).
  1311. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1312. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1313. })
  1314. }).Find(&advice).Error
  1315. } else if change_type == 2 {
  1316. var Id AdviceDate
  1317. 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
  1318. 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).
  1319. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1320. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1321. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1322. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1323. }).
  1324. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1325. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1326. })
  1327. }).Find(&advice).Error
  1328. }
  1329. return
  1330. }
  1331. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1332. 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).
  1333. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1334. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1335. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1336. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1337. }).
  1338. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1339. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1340. })
  1341. }).Order("record_date desc").Find(&advice).Error
  1342. return
  1343. }
  1344. func GetMobileCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1345. 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).
  1346. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1347. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1348. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1349. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1350. }).
  1351. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1352. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1353. })
  1354. }).Find(&advice).Error
  1355. return
  1356. }
  1357. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1358. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1359. return
  1360. }
  1361. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  1362. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1363. return
  1364. }
  1365. func GetHisOrderByIDTX(order_id int64, tx *gorm.DB) (order models.HisOrder, err error) {
  1366. err = tx.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1367. return
  1368. }
  1369. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1370. err = readDb.Model(&models.HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1371. return
  1372. }
  1373. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  1374. 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
  1375. return
  1376. }
  1377. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  1378. 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
  1379. return
  1380. }
  1381. func GetHisDoctorAdvicesById(id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1382. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND id = ?", id).First(&advice).Error
  1383. return
  1384. }
  1385. func GetAdditionChargeByID(org_id int64, id int64) (addition models.XtHisAddtionConfig, err error) {
  1386. err = readDb.Model(&models.XtHisAddtionConfig{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&addition).Error
  1387. return
  1388. }
  1389. func GetHisPrescriptionByID(org_id int64, id int64) (pre models.HisPrescription, err error) {
  1390. err = readDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&pre).Error
  1391. return
  1392. }
  1393. func GetHisProjectByID(id int64) (project models.HisPrescriptionProject, err error) {
  1394. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id = ?", id).First(&project).Error
  1395. return
  1396. }
  1397. func GetHisAdditionByID(id int64) (addition models.HisAdditionalCharge, err error) {
  1398. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND id = ?", id).First(&addition).Error
  1399. return
  1400. }
  1401. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1402. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  1403. return
  1404. }
  1405. func GetPatientByIDCardAndName(id_card_no string, user_org_id int64, name string) (patient Patients, err error) {
  1406. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ? AND name = ?", id_card_no, user_org_id, name).First(&patient).Error
  1407. return
  1408. }
  1409. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1410. 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
  1411. return
  1412. }
  1413. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1414. var patient Patients
  1415. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1416. return patient, err
  1417. }
  1418. func GetPatientByIDTenTwo(orgID int64, patientID int64) (models.PatientTwos, error) {
  1419. var patient models.PatientTwos
  1420. err := readDb.Model(&models.PatientTwos{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1421. return patient, err
  1422. }
  1423. func GetHisPrescriptionByPatientID(patientID int64, orgID int64) (info models.HisPrescriptionInfo, err error) {
  1424. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND patient_id = ? AND status = 1", orgID, patientID).Preload("XtHisDepartment", "status = 1").Last(&info).Error
  1425. return
  1426. }
  1427. type VMHisProjectTeam struct {
  1428. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1429. ProjectTeam string `gorm:"column:project_team" json:"project_team" form:"project_team"`
  1430. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1431. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1432. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1433. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  1434. TeamType int64 `gorm:"column:team_type" json:"team_type" form:"team_type"`
  1435. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1436. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1437. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1438. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1439. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1440. ProjectId string `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1441. VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
  1442. ItemId string `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1443. }
  1444. func (VMHisProjectTeam) TableName() string {
  1445. return "xt_his_project_team"
  1446. }
  1447. type VMHisProject struct {
  1448. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1449. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1450. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1451. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1452. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1453. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1454. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1455. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1456. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1457. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1458. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1459. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1460. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1461. }
  1462. func (VMHisProject) TableName() string {
  1463. return "xt_his_project"
  1464. }
  1465. type VMItemProjectList struct {
  1466. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1467. Number int64 `gorm:"column:number" json:"number" form:"number"`
  1468. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1469. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1470. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1471. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1472. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1473. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1474. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1475. VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1476. GoodInfo GoodInfo `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good_info"`
  1477. }
  1478. func (VMItemProjectList) TableName() string {
  1479. return "xt_his_project_list"
  1480. }
  1481. type VMHisPrescriptionTwo struct {
  1482. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1483. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1484. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1485. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1486. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1487. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1488. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1489. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1490. }
  1491. func (VMHisPrescriptionTwo) TableName() string {
  1492. return "his_prescription"
  1493. }
  1494. func GetAllProjectTeamList(orgid int64) (project []*VMHisProjectTeam, err error) {
  1495. err = XTReadDB().Model(&VMHisProjectTeam{}).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1496. for _, item := range project {
  1497. var project_item []*VMItemProjectList
  1498. ids := strings.Split(item.ItemId, ",")
  1499. 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)
  1500. item.VMItemProjectList = append(item.VMItemProjectList, project_item...)
  1501. }
  1502. return
  1503. }
  1504. type HisDoctorAdviceInfo struct {
  1505. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1506. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1507. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1508. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1509. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1510. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1511. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1512. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1513. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1514. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1515. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1516. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1517. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1518. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1519. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1520. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1521. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1522. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1523. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1524. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1525. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1526. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1527. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1528. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1529. }
  1530. func (HisDoctorAdviceInfo) TableName() string {
  1531. return "his_doctor_advice_info"
  1532. }
  1533. type HisPrescriptionProject struct {
  1534. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1535. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1536. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1537. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1538. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1539. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1540. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1541. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1542. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1543. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1544. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1545. Count string `gorm:"column:count" json:"count" form:"count"`
  1546. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1547. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1548. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1549. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1550. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1551. Day string `gorm:"column:day" json:"day" form:"day"`
  1552. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1553. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1554. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1555. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1556. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1557. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1558. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1559. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1560. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1561. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1562. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1563. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1564. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1565. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1566. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1567. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  1568. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  1569. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  1570. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1571. }
  1572. func (HisPrescriptionProject) TableName() string {
  1573. return "his_prescription_project"
  1574. }
  1575. type HisOrderInfo struct {
  1576. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1577. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1578. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1579. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1580. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1581. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1582. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1583. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1584. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1585. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1586. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1587. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1588. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1589. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1590. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1591. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1592. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1593. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1594. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1595. }
  1596. func (HisOrderInfo) TableName() string {
  1597. return "his_order_info"
  1598. }
  1599. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1600. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1601. 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)
  1602. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1603. 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)
  1604. }).Find(&order).Error
  1605. return
  1606. }
  1607. //func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1608. // db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1609. // return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  1610. // })
  1611. // err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1612. // return
  1613. //}
  1614. func GetHisOrderInfoByNumberOne(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1615. db := readDb.Model(&models.HisOrderInfoTwo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1616. return db.Preload("Drug", "status = 1").Where("status = 1")
  1617. })
  1618. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1619. return
  1620. }
  1621. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1622. db := readDb.Model(&models.HisOrderInfoTwo{})
  1623. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  1624. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1625. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1626. })
  1627. 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
  1628. return
  1629. }
  1630. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1631. db := readDb.Model(&models.HisOrderInfoTwo{})
  1632. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  1633. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1634. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1635. })
  1636. 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
  1637. return
  1638. }
  1639. type MedicalInsuranceCostCompare struct {
  1640. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1641. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1642. EndTime int64 `gorm:"column:end_time" json:"end_time" form:"end_time"`
  1643. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1644. CheckType int64 `gorm:"column:check_type" json:"check_type" form:"check_type"`
  1645. Num int64 `gorm:"column:num" json:"num" form:"num"`
  1646. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1647. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1648. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1649. CostTotal float64 `gorm:"column:cost_total" json:"cost_total" form:"cost_total"`
  1650. FuncTotal float64 `gorm:"column:func_total" json:"func_total" form:"func_total"`
  1651. PsnPay float64 `gorm:"column:psn_pay" json:"psn_pay" form:"psn_pay"`
  1652. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1653. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1654. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1655. }
  1656. func (MedicalInsuranceCostCompare) TableName() string {
  1657. return "medical_insurance_cost_compare"
  1658. }
  1659. func GetMedicalInsuranceCostCompareList(orgID, page, limit int64, keywords string, insutype string, start_time int64, end_time int64) (list []*MedicalInsuranceCostCompare, total int, err error) {
  1660. offset := (page - 1) * limit
  1661. db := readDb.Model(&MedicalInsuranceCostCompare{}).Where("medical_insurance_cost_compare.user_org_id = ?", orgID)
  1662. if len(keywords) == 0 {
  1663. db = db.Where("status=1")
  1664. if len(insutype) != 0 {
  1665. db = db.Where("insutype = ?", insutype)
  1666. }
  1667. if start_time != 0 {
  1668. db = db.Where("ctime >= ? ", start_time)
  1669. }
  1670. if end_time != 0 {
  1671. db = db.Where("ctime <= ? ", end_time)
  1672. }
  1673. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1674. } else {
  1675. keywords = "%" + keywords + "%"
  1676. 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)
  1677. db = db.Where("medical_insurance_cost_compare.status=1 ")
  1678. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1679. }
  1680. return
  1681. }
  1682. type TempPatients struct {
  1683. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1684. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1685. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1686. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  1687. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1688. Name string `gorm:"column:name" json:"name" form:"name"`
  1689. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1690. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  1691. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  1692. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  1693. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1694. GdybPsnNcdsRecord GdybPsnNcdsRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"record"`
  1695. }
  1696. func (TempPatients) TableName() string {
  1697. return "xt_patients"
  1698. }
  1699. type GdybPsnNcdsRecord struct {
  1700. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1701. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1702. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1703. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1704. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1705. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1706. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1707. IsCancel int64 `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
  1708. TrtDclaDetlSn string `gorm:"column:trt_dcla_detl_sn" json:"trt_dcla_detl_sn" form:"trt_dcla_detl_sn"`
  1709. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1710. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1711. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1712. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1713. OrgName string `gorm:"column:org_name" json:"org_name" form:"org_name"`
  1714. }
  1715. func (GdybPsnNcdsRecord) TableName() string {
  1716. return "gdyb_psn_ncds_record"
  1717. }
  1718. func GetGdybPsnNcdsRecordList(orgID, page, limit int64, keywords string, is_cancel int64) (list []*TempPatients, total int64, err error) {
  1719. offset := (page - 1) * limit
  1720. db := readDb.Model(&TempPatients{})
  1721. db = db.Preload("GdybPsnNcdsRecord", func(db *gorm.DB) *gorm.DB {
  1722. return db.Model(&GdybPsnNcdsRecord{}).Where("user_org_id = ?", orgID).Order("id asc")
  1723. })
  1724. fmt.Println(is_cancel)
  1725. if len(keywords) == 0 {
  1726. if is_cancel == 1 {
  1727. 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)
  1728. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1729. } else if is_cancel == 0 {
  1730. db = db.Preload("GdybPsnNcdsRecord", "user_org_id = ?", orgID)
  1731. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1732. } else if is_cancel == 2 {
  1733. 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)")
  1734. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1735. }
  1736. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1737. } else {
  1738. keywords = "%" + keywords + "%"
  1739. 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)
  1740. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1741. }
  1742. return
  1743. }
  1744. type CustomAccountFormData struct {
  1745. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1746. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1747. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1748. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1749. MdtrtiId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1750. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1751. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1752. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1753. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1754. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1755. CashPay float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
  1756. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  1757. Sumamt float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
  1758. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1759. DiagnosisId string `gorm:"column:diagnosis_id" json:"diagnosis_id" form:"diagnosis_id"`
  1760. DialysisCount int64 `gorm:"-"`
  1761. PatientId int64 `gorm:"column:patient_id" json:"dialysis_count" form:"dialysis_count"`
  1762. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1763. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1764. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1765. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1766. MayPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1767. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1768. }
  1769. func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (cus []*CustomAccountFormData, err error) {
  1770. if clr_type == "9903" {
  1771. 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 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
  1772. } else {
  1773. 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 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
  1774. }
  1775. for _, item := range cus {
  1776. var total int64
  1777. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND dialysis_date >= ?", item.PatientId, end_time, start_time).Count(&total)
  1778. fmt.Println(total)
  1779. item.DialysisCount = total
  1780. fmt.Println(item.DialysisCount)
  1781. }
  1782. return
  1783. }
  1784. func GetNewHisPatientInfo(his_patient_id int64) (info models.HisPatient, err error) {
  1785. err = readDb.Model(&models.HisPatient{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
  1786. return
  1787. }
  1788. func GetNewHisOrder(user_org_id int64, mdtrt_id string, patient_id int64) (order models.HisOrder, err error) {
  1789. 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).
  1790. Last(&order).Error
  1791. return
  1792. }
  1793. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1794. 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).
  1795. Order("ctime desc").
  1796. Find(&order).Error
  1797. return
  1798. }
  1799. type NewCustomPatients struct {
  1800. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1801. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1802. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1803. Number string `gorm:"column:number" json:"number" form:"number"`
  1804. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1805. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1806. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,Number" json:"order"`
  1807. }
  1808. func (NewCustomPatients) TableName() string {
  1809. return "his_patients"
  1810. }
  1811. type NewSZCustomPatients struct {
  1812. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1813. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1814. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1815. Number string `gorm:"column:number" json:"number" form:"number"`
  1816. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1817. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1818. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,MzNumber" json:"order"`
  1819. }
  1820. func (NewSZCustomPatients) TableName() string {
  1821. return "his_patients"
  1822. }
  1823. //
  1824. //func GetNewAllChargeHisPatientList(org_id int64, record_date int64) (patients []*NewSZCustomPatients, err error) {
  1825. // var tempPatients []*NewSZCustomPatients
  1826. // db := readDb.Model(&NewSZCustomPatients{}).Where("his_patients.user_org_id = ? AND his_patients.status = 1", org_id)
  1827. // db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1828. // return tempPatients, err
  1829. //}
  1830. type NewTempPatients struct {
  1831. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1832. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1833. Name string `gorm:"column:name" json:"name" form:"name"`
  1834. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1835. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1836. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  1837. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  1838. HisPatient []*HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  1839. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  1840. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  1841. }
  1842. func (NewTempPatients) TableName() string {
  1843. return "xt_patients"
  1844. }
  1845. //"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
  1846. func GetNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  1847. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1848. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1849. 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)
  1850. })
  1851. 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)
  1852. 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
  1853. for _, item := range patients {
  1854. for _, sumItem := range item.HisPatient {
  1855. if len(sumItem.VMHisOrders) > 0 {
  1856. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1857. }
  1858. }
  1859. }
  1860. return
  1861. }
  1862. func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  1863. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1864. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1865. 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)
  1866. })
  1867. 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)
  1868. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  1869. for _, item := range patients {
  1870. for _, sumItem := range item.HisPatient {
  1871. if len(sumItem.VMHisOrders) > 0 {
  1872. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1873. }
  1874. }
  1875. }
  1876. return
  1877. }
  1878. func GetPrescriptionById(id int64, org_id int64) (prescription models.HisPrescription, err error) {
  1879. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND user_org_id = ? AND status = 1", id, org_id).First(&prescription).Error
  1880. return
  1881. }
  1882. type CustomInComeStatistics struct {
  1883. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1884. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  1885. SettleAccountsDate string `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1886. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1887. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1888. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1889. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1890. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1891. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1892. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1893. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1894. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  1895. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  1896. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1897. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1898. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1899. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1900. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1901. }
  1902. func (CustomInComeStatistics) TableName() string {
  1903. return "his_order"
  1904. }
  1905. func GetDayIncomeStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (order []*CustomInComeStatistics, total int64, err error) {
  1906. offset := (page - 1) * limit
  1907. if len(keywords) != 0 {
  1908. 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
  1909. } else {
  1910. if start_time != 0 && end_time != 0 {
  1911. 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
  1912. } else {
  1913. 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
  1914. }
  1915. }
  1916. return
  1917. }
  1918. func GetDayIncomeDetailStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (cis []*CustomInComeStatistics, total int64, err error) {
  1919. offset := (page - 1) * limit
  1920. if len(keywords) != 0 {
  1921. 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
  1922. } else {
  1923. if start_time != 0 && end_time != 0 {
  1924. 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
  1925. } else {
  1926. 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
  1927. }
  1928. }
  1929. return
  1930. }
  1931. //func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1932. // 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
  1933. // return
  1934. //}
  1935. func CreateHisPrescriptionTemplate(template *models.HisPrescriptionTemplate) (err error) {
  1936. err = writeDb.Create(&template).Error
  1937. return
  1938. }
  1939. func CreateHisPrescriptionAdviceTemplate(s *models.HisPrescriptionAdviceTemplate) (err error) {
  1940. err = writeDb.Save(&s).Error
  1941. return
  1942. }
  1943. func CreateHisPrescriptionInfoTemplate(s *models.HisPrescriptionInfoTemplate) (err error) {
  1944. err = writeDb.Save(&s).Error
  1945. return
  1946. }
  1947. func CreateHisPrescriptionProjectTemplate(project *models.HisPrescriptionProjectTemplate) (err error) {
  1948. err = writeDb.Save(&project).Error
  1949. return
  1950. }
  1951. func GetPatientSch(patient_id int64, sch_date int64, org_id int64) (sch models.Schedule, err error) {
  1952. 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
  1953. return
  1954. }
  1955. func GetHisPrescriptionBySchMode(mode_id int64, patient_id int64, org_id int64) (prescription models.HisPrescriptionTemplate, err error) {
  1956. 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
  1957. return
  1958. }
  1959. func GetHisPrescriptionTemplate(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplate, err error) {
  1960. err = readDb.Model(&models.HisPrescriptionInfoTemplate{}).
  1961. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  1962. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1963. }).
  1964. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  1965. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  1966. }).
  1967. Where("status = 1 AND p_template_id = ? ", template_id).
  1968. Find(&prescription).Error
  1969. return
  1970. }
  1971. // 组
  1972. func GetHisPrescriptionTemplateL(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplateL, err error) {
  1973. err = readDb.Model(&models.HisPrescriptionInfoTemplateL{}).
  1974. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  1975. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1976. }).
  1977. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  1978. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  1979. }).
  1980. Where("status = 1 AND p_template_id = ? ", template_id).
  1981. Find(&prescription).Error
  1982. return
  1983. }
  1984. func FindHisConsumablesByID(orgID int64, patient_id int64, recordDate int64, good_id int64) (consumables models.DialysisBeforePrepare, err error) {
  1985. 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
  1986. return
  1987. }
  1988. func UpdateConsumables(consumables *models.DialysisBeforePrepare) (err error) {
  1989. err = writeDb.Save(&consumables).Error
  1990. return
  1991. }
  1992. func GetHisPrescriptionProjectsByID(id int64) (projects []*models.HisPrescriptionProject, err error) {
  1993. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("prescription_id = ? AND status = 1", id).Find(&projects).Error
  1994. return
  1995. }
  1996. func GetHisPrescriptionProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  1997. 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
  1998. return
  1999. }
  2000. func GetHisPrescriptionTeamProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  2001. 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
  2002. return
  2003. }
  2004. func GetHisPrescriptionProjectByID(id int64) (projects models.HisPrescriptionProject, err error) {
  2005. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2006. return
  2007. }
  2008. func GetHisPrescriptionAdviceByID(id int64) (advices []*models.HisDoctorAdviceInfo, err error) {
  2009. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
  2010. return
  2011. }
  2012. func UpdateGoodInfo(good_info *models.GoodInfo) (err error) {
  2013. err = writeDb.Save(&good_info).Error
  2014. return
  2015. }
  2016. func GetUnChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2017. err = readDb.Model(&models.HisPrescription{}).
  2018. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2019. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2020. }).
  2021. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2022. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2023. }).
  2024. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2025. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2026. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2027. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2028. }).
  2029. 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).
  2030. Find(&prescription).Error
  2031. return
  2032. }
  2033. func GetChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2034. err = readDb.Model(&models.HisPrescription{}).
  2035. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2036. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2037. }).
  2038. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2039. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2040. }).
  2041. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2042. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2043. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2044. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2045. }).
  2046. 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).
  2047. Find(&prescription).Error
  2048. return
  2049. }
  2050. func GetChargeHisPrescriptionSeven(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2051. err = readDb.Model(&models.HisPrescription{}).
  2052. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2053. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2054. }).
  2055. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2056. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  2057. }).
  2058. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2059. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  2060. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2061. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2062. }).
  2063. 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).
  2064. Find(&prescription).Error
  2065. return
  2066. }
  2067. // 已收费
  2068. func GetChargeMonthHisPrescriptionFive(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2069. err = readDb.Model(&models.HisPrescription{}).
  2070. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2071. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2072. }).
  2073. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2074. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2075. }).
  2076. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2077. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2078. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2079. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2080. }).
  2081. 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).
  2082. Find(&prescription).Error
  2083. return
  2084. }
  2085. func UpdataHisPateint(his *models.HisPatient) {
  2086. writeDb.Save(&his)
  2087. }
  2088. func UpdataHisPateintTX(his *models.HisPatient, tx *gorm.DB) {
  2089. tx.Save(&his)
  2090. }
  2091. func SaveHisOrder(his *models.HisOrder) (err error) {
  2092. err = writeDb.Save(&his).Error
  2093. return
  2094. }
  2095. func UpdataHisPateintTwo(his *models.VMHisPatient) {
  2096. writeDb.Save(&his)
  2097. }
  2098. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  2099. err = readDb.Model(&models.HisPrescription{}).
  2100. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2101. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2102. }).
  2103. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2104. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2105. }).
  2106. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2107. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2108. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2109. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2110. }).
  2111. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2112. Find(&prescription).Error
  2113. return
  2114. }
  2115. func GetPrescriptionByIdsTX(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2116. err = tx.Model(&models.HisPrescription{}).
  2117. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2118. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2119. }).
  2120. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2121. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2122. }).
  2123. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2124. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2125. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2126. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2127. }).
  2128. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2129. Find(&prescription).Error
  2130. return
  2131. }
  2132. func GetPrescriptionByIdsTxOne(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2133. err = tx.Model(&models.HisPrescription{}).
  2134. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2135. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2136. }).
  2137. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2138. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  2139. }).
  2140. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2141. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1")
  2142. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2143. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2144. }).
  2145. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2146. Find(&prescription).Error
  2147. return
  2148. }
  2149. func GetNewAllUnChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  2150. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2151. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2152. 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)
  2153. })
  2154. 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)
  2155. 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
  2156. for _, item := range patients {
  2157. for _, sumItem := range item.HisPatient {
  2158. if len(sumItem.VMHisOrders) > 0 {
  2159. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2160. }
  2161. }
  2162. }
  2163. return
  2164. }
  2165. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  2166. 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
  2167. return
  2168. }
  2169. func GetNewHisOrderList(org_id int64) (order []*models.NewHisOrder, err error) {
  2170. 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
  2171. var numbers []string
  2172. for _, item := range order {
  2173. numbers = append(numbers, item.Number)
  2174. }
  2175. return
  2176. }
  2177. func GetNewHisOrderInfoList(order_numbers []string) (order []*models.VMHisOrderInfo, err error) {
  2178. err = readDb.Model(&models.VMHisOrderInfo{}).Where("status = 1 AND order_number in (?)", order_numbers).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2179. return db.Where("status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1")
  2180. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2181. return db.Where("status = 1 ").Preload("Drug", "status =1")
  2182. }).Find(&order).Error
  2183. return
  2184. }
  2185. func FindAllHisDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, drug_id int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2186. 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
  2187. return
  2188. }
  2189. func FindAllHisProjectByTime(now int64, end int64, patient_id int64, orgId int64, project_id int64) (project []*models.HisPrescriptionProject, err error) {
  2190. 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
  2191. return
  2192. }
  2193. func GetProjectByTeamId(user_org_id int64, team_id int64, patient_id int64, record_time int64) (label models.HisLabelPrintInfo, err error) {
  2194. 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
  2195. return
  2196. }
  2197. func GetProjectById(user_org_id int64, p_project_id int64, record_time int64, patient_id int64) (label models.HisLabelPrintInfo, err error) {
  2198. 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
  2199. return
  2200. }
  2201. func DeletePrintInfo(id int64) {
  2202. writeDb.Model(&models.HisLabelPrintInfo{}).Where("p_project_id = ?", id).Updates(map[string]interface{}{"status": 0})
  2203. }
  2204. func CreateHisLabelRecord(label *models.HisLabelPrintInfo) error {
  2205. err := writeDb.Save(&label).Error
  2206. return err
  2207. }
  2208. func DeletePsnNCDSRecordById(id int64) (err error) {
  2209. err = writeDb.Model(&models.GdybPsnNcdsRecord{}).Where("id = ?", id).Updates(map[string]interface{}{"user_org_id": 1110000}).Error
  2210. return
  2211. }
  2212. func GetBaiLinOrderData() (order []*models.NewCustomHisOrder) {
  2213. readDb.Model(&models.NewCustomHisOrder{}).Preload("Patients", "status = 1").Preload("NewCustomHisOrderInfo", func(db *gorm.DB) *gorm.DB {
  2214. 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)")
  2215. }).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)
  2216. return
  2217. }
  2218. func GetHisDoctorAdviceInfo(id int64) (models.HisDoctorAdviceInfo, error) {
  2219. info := models.HisDoctorAdviceInfo{}
  2220. err := readDb.Model(&info).Where("id = ? and status = 1", id).Preload("Drug", "status = 1").Find(&info).Error
  2221. return info, err
  2222. }
  2223. func UpdateBatchHisPrescriptionMedType(ids []string, med_type string, start_time int64, end_time int64, user_org_id int64, old_med_type string) (err error) {
  2224. tx := writeDb.Begin()
  2225. 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 {
  2226. tx.Rollback()
  2227. return
  2228. }
  2229. tx.Commit()
  2230. return
  2231. }
  2232. func GetWarehoseInfoByDrugId(drug_id int64, org_id int64) (info OtherDrugWarehouseInfo, err error) {
  2233. 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
  2234. return
  2235. }
  2236. func GetGoodWarehoseInfoByGoodId(good_id int64, org_id int64) (info models.GoodSotckInfo, err error) {
  2237. 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
  2238. return
  2239. }
  2240. type MonthChargePatients struct {
  2241. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2242. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2243. Name string `gorm:"column:name" json:"name" form:"name"`
  2244. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2245. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2246. Number string `gorm:"column:number" json:"number" form:"number"`
  2247. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  2248. }
  2249. func (MonthChargePatients) TableName() string {
  2250. return "his_patient"
  2251. }
  2252. func GetMonthUnChargeHisPatientList(org_id int64, record_date int64, start_time int64, end_time int64) (patients []*MonthChargePatients, err error) {
  2253. db := readDb.Model(&MonthChargePatients{}).Where("his_patient.user_org_id = ? AND his_patient.status = 1 AND his_patient.record_date = ?", org_id, record_date)
  2254. 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)
  2255. return
  2256. }
  2257. func UpdataOrderStatusThree(number string, user_org_id int64) (err error) {
  2258. 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
  2259. 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
  2260. return
  2261. }
  2262. func UpDateOrderTwo(order *models.HisOrder, tx *gorm.DB) (err error) {
  2263. err = tx.Save(&order).Error
  2264. return
  2265. }
  2266. type HisOrderInfoTen struct {
  2267. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2268. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2269. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2270. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2271. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2272. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2273. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2274. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2275. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2276. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2277. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2278. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2279. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2280. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2281. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2282. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2283. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2284. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2285. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2286. }
  2287. func (HisOrderInfoTen) TableName() string {
  2288. return "his_order_info"
  2289. }
  2290. func GetHisOrderDetailByNumberTen(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2291. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2292. 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)
  2293. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2294. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2295. }).Find(&order).Error
  2296. return
  2297. }
  2298. func GetHisOrderDetailByNumberEleven(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2299. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2300. 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)
  2301. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2302. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2303. }).Find(&order).Error
  2304. return
  2305. }
  2306. func GetHisOrderByIDTen(order_id int64) (order models.HisOrder, err error) {
  2307. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2308. return
  2309. }
  2310. func GetHisPrescriptonProjectById(id int64) (models.HisPrescriptionProject, error) {
  2311. project := models.HisPrescriptionProject{}
  2312. err := XTReadDB().Where("id = ? and status = 1", id).Find(&project).Error
  2313. return project, err
  2314. }
  2315. type HisOrderInfoTwo struct {
  2316. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2317. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2318. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2319. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2320. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2321. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2322. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2323. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2324. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2325. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2326. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2327. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2328. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2329. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2330. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2331. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2332. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2333. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2334. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2335. }
  2336. func (HisOrderInfoTwo) TableName() string {
  2337. return "his_order_info"
  2338. }
  2339. func GetHisOrderDetailByNumberTwo(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2340. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2341. 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)
  2342. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2343. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2344. }).Find(&order).Error
  2345. return
  2346. }
  2347. func GetHisOrderDetailByNumberThree(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2348. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2349. 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)
  2350. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2351. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2352. }).Find(&order).Error
  2353. return
  2354. }
  2355. func GetHisOrderByIDThree(order_id int64) (order models.HisOrder, err error) {
  2356. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2357. return
  2358. }
  2359. func GetDrugSumOutCountByDrugId(drug_id int64, user_org_id int64, storehouse_id int64) (models.XtDrugStockCount, error) {
  2360. drug := models.XtDrugStockCount{}
  2361. 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
  2362. return drug, err
  2363. }
  2364. func GetStockGoodList(good_id int64, org_id int64, storehouse_id int64) (models.XtGoodStockCount, error) {
  2365. stockCount := models.XtGoodStockCount{}
  2366. err = XTReadDB().Where("good_id = ? and user_org_id = ? and status= 1 and storehouse_id = ?", good_id, org_id, storehouse_id).Find(&stockCount).Error
  2367. return stockCount, err
  2368. }
  2369. func GetLastOrderTX(user_org_id int64) (models.HisOrder, error) {
  2370. order := models.HisOrder{}
  2371. err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Last(&order).Error
  2372. return order, err
  2373. }
  2374. func GetPatientPlan(orgid int64) (patient []*models.XtPatients, err error) {
  2375. err = XTReadDB().Where("user_org_id = ? and status= 1", orgid).Find(&patient).Error
  2376. return patient, err
  2377. }
  2378. func UpdatePatienPlan(id int64, trement_plan string) error {
  2379. err := XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status = 1", id).Update(map[string]interface{}{"treatment_plan": trement_plan}).Error
  2380. return err
  2381. }
  2382. func GetDialysisOrderList(orgid int64) (order []*models.XtDialysisOrder, err error) {
  2383. err = XTReadDB().Where("user_org_id = ? and status= 1 and url<>''", orgid).Group("patient_id").Find(&order).Error
  2384. return order, err
  2385. }
  2386. func UpdatePatientDialysisOrder(patient_id int64, url string) error {
  2387. err := XTWriteDB().Model(&models.XtPatients{}).Where("id =? and status=1", patient_id).Updates(map[string]interface{}{"url": url}).Error
  2388. return err
  2389. }
  2390. func GetHisOrderByIDTenOne(order_id string) (order models.HisOrder, err error) {
  2391. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  2392. return
  2393. }
  2394. func GetHisDoctorAdviceInfotwo(id int64) (models.HisDoctorAdviceInfo, error) {
  2395. info := models.HisDoctorAdviceInfo{}
  2396. err := readDb.Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
  2397. return info, err
  2398. }
  2399. func GetHisDoctorAdviceInfothree(org_id int64, record_date int64) (info []*models.HisDoctorAdviceInfo, err error) {
  2400. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&info).Error
  2401. return
  2402. }
  2403. func GetHisPrescriptionProjectByIDFour(org_id int64, record_date int64) (projects []*models.HisPrescriptionProject, err error) {
  2404. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&projects).Error
  2405. return
  2406. }
  2407. func GetHisPrescriptionProjectByIDThree(id int64) (projects models.HisPrescriptionProject, err error) {
  2408. err = readDb.Model(&models.HisPrescriptionProject{}).Where("id = ? AND status = 1", id).First(&projects).Error
  2409. return
  2410. }
  2411. func GetHisPrescriptionProjectByIDTwoone(id int64) (projects models.HisPrescriptionProject, err error) {
  2412. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Preload("HisProject", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2413. return
  2414. }
  2415. func GetMonthNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64, start_date int64, end_date int64) (patients []NewTempPatients, err error) {
  2416. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2417. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2418. 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)
  2419. })
  2420. 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)
  2421. 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
  2422. for _, item := range patients {
  2423. for _, sumItem := range item.HisPatient {
  2424. if len(sumItem.VMHisOrders) > 0 {
  2425. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2426. }
  2427. }
  2428. }
  2429. return
  2430. }
  2431. func GetChargeHisPatientList(org_id int64, record_date int64) (order []*HisOrder, err error) {
  2432. 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
  2433. return
  2434. }