his_service.go 135KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188
  1. package service
  2. import (
  3. "fmt"
  4. "gdyb/models"
  5. "github.com/jinzhu/gorm"
  6. "strconv"
  7. "time"
  8. )
  9. type HisPatient struct {
  10. ID int64 `gorm:"column:id" json:"id" form:"id"`
  11. Name string `gorm:"column:name" json:"name" form:"name"`
  12. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  13. Total float64 `gorm:"column:total" json:"total" form:"total"`
  14. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  15. Status int64 `gorm:"column:status" json:"status" form:"status"`
  16. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  17. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  18. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  19. Number string `gorm:"column:number" json:"number" form:"number"`
  20. PatientInfo string `gorm:"column:patient_info" json:"patient_info" form:"patient_info"`
  21. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  22. }
  23. func (HisPatient) TableName() string {
  24. return "his_patient"
  25. }
  26. type Schedule struct {
  27. ID int64 `gorm:"column:id" json:"id" form:"id"`
  28. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  29. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  30. Status int64 `gorm:"column:status" json:"status" form:"status"`
  31. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  32. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  33. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  34. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  35. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  36. }
  37. func (Schedule) TableName() string {
  38. return "xt_schedule"
  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 Patients 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. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  70. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  71. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  72. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  73. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  74. Source int64 `gorm:"column:source" json:"source" form:"source"`
  75. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  76. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  77. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  78. Name string `gorm:"column:name" json:"name" form:"name"`
  79. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  80. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  81. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  82. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  83. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  84. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  85. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  86. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  87. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  88. Height int64 `gorm:"column:height" json:"height" form:"height"`
  89. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  90. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  91. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  92. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  93. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  94. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  95. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  96. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  97. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  98. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  99. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  100. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  101. Children int64 `gorm:"column:children" json:"children" form:"children"`
  102. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  103. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  104. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  105. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  106. PredialysisCondition string `gorm:"column:predialysis_condition" json:"predialysis_condition" form:"predialysis_condition"`
  107. PreHospitalDialysisFrequency string `gorm:"column:pre_hospital_dialysis_frequency" json:"pre_hospital_dialysis_frequency" form:"pre_hospital_dialysis_frequency"`
  108. PreHospitalDialysisTimes int64 `gorm:"column:pre_hospital_dialysis_times" json:"pre_hospital_dialysis_times" form:"pre_hospital_dialysis_times"`
  109. HospitalFirstDialysisDate int64 `gorm:"column:hospital_first_dialysis_date" json:"hospital_first_dialysis_date" form:"hospital_first_dialysis_date"`
  110. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  111. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  112. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  113. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  114. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  115. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  116. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  117. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  118. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  119. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  120. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  121. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  122. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains" form:"patient_complains"`
  123. PresentHistory string `gorm:"column:present_history" json:"present_history" form:"present_history"`
  124. PastHistory string `gorm:"column:past_history" json:"past_history" form:"past_history"`
  125. Temperature float64 `gorm:"column:temperature" json:"temperature" form:"temperature"`
  126. Pulse int64 `gorm:"column:pulse" json:"pulse" form:"pulse"`
  127. Respiratory int64 `gorm:"column:respiratory" json:"respiratory" form:"respiratory"`
  128. Sbp int64 `gorm:"column:sbp" json:"sbp" form:"sbp"`
  129. Dbp int64 `gorm:"column:dbp" json:"dbp" form:"dbp"`
  130. Status int64 `gorm:"column:status" json:"status" form:"status"`
  131. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  132. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  133. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  134. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  135. Age int64 `gorm:"column:age" json:"age" form:"age"`
  136. InfectiousNextRecordTime int64 `gorm:"column:infectious_next_record_time" json:"infectious_next_record_time" form:"infectious_next_record_time"`
  137. IsInfectious int64 `gorm:"column:is_infectious" json:"is_infectious" form:"is_infectious"`
  138. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind" form:"is_open_remind"`
  139. RemindCycle int64 `gorm:"column:remind_cycle" json:"remind_cycle" form:"remind_cycle"`
  140. ResponseResult string `gorm:"column:response_result" json:"response_result" form:"response_result"`
  141. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  142. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  143. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  144. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  145. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  146. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  147. IsExcelExport int64 `gorm:"column:is_excel_export" json:"is_excel_export" form:"is_excel_export"`
  148. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  149. OutReason string `gorm:"column:out_reason" json:"out_reason" form:"out_reason"`
  150. InsuplcAdmdvs string `gorm:"column:insuplc_admdvs" json:"insuplc_admdvs" form:"insuplc_admdvs"`
  151. }
  152. func (Patients) TableName() string {
  153. return "xt_patients"
  154. }
  155. type HisPrescription struct {
  156. ID int64 `gorm:"column:id" json:"id" form:"id"`
  157. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  158. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  159. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  160. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  161. Status int64 `gorm:"column:status" json:"status" form:"status"`
  162. }
  163. func (HisPrescription) TableName() string {
  164. return "his_prescription"
  165. }
  166. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Schedule, err error) {
  167. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  168. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  169. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  170. err = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id).Find(&patients).Error
  171. return
  172. }
  173. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  174. err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
  175. return
  176. }
  177. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  178. 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
  179. return
  180. }
  181. func GetNewHisPatientInfo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  182. 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
  183. return
  184. }
  185. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  186. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  187. return
  188. }
  189. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  190. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  191. return
  192. }
  193. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  194. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  195. err = db.Find(&caseHistorys).Error
  196. return
  197. }
  198. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  199. likekey := "%" + keyword + "%"
  200. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  201. if startime > 0 {
  202. db = db.Where("record_date>=?", startime)
  203. }
  204. if endtime > 0 {
  205. db = db.Where("record_date<=?", endtime)
  206. }
  207. if len(keyword) > 0 {
  208. db = db.Where("template_name like ? ", likekey)
  209. }
  210. err = db.Find(&caseHistorys).Error
  211. return
  212. }
  213. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  214. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  215. return caseHistory, err
  216. }
  217. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  218. err = writeDb.Create(&template).Error
  219. return
  220. }
  221. func GetHisPatientCaseHistoryById(hispatientid int64) (*models.HisPatientCaseHistory, error) {
  222. history := models.HisPatientCaseHistory{}
  223. err := XTReadDB().Model(&history).Where("his_patient_id = ? and status = 1", hispatientid).Find(&history).Error
  224. if err != nil {
  225. if err == gorm.ErrRecordNotFound {
  226. return nil, err
  227. } else {
  228. return nil, err
  229. }
  230. }
  231. return &history, nil
  232. }
  233. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  234. err := writeDb.Create(&caseHistory).Error
  235. return err
  236. }
  237. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  238. err = writeDb.Save(&prescription).Error
  239. return
  240. }
  241. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  242. 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
  243. 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
  244. 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
  245. return
  246. }
  247. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  248. 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
  249. return
  250. }
  251. func DelelteProject(id int64, user_org_id int64) (err error) {
  252. 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
  253. return
  254. }
  255. func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  256. err = readDb.Model(&models.HisPrescription{}).
  257. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  258. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  259. }).
  260. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  261. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  262. }).
  263. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  264. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  265. }).
  266. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1", org_id, record_date, patient_id).
  267. Find(&prescription).Error
  268. return
  269. }
  270. func GetNewHisPrescription(org_id int64, his_patient_id int64, record_date int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  271. err = readDb.Model(&models.HisPrescription{}).
  272. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  273. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  274. }).
  275. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  276. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  277. }).
  278. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  279. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  280. }).
  281. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, record_date, his_patient_id, reg_type).
  282. Find(&prescription).Error
  283. return
  284. }
  285. type OtherDrugWarehouseInfo struct {
  286. ID int64 `gorm:"column:id" json:"id" form:"id"`
  287. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  288. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  289. Status int64 `gorm:"column:status" json:"status" form:"status"`
  290. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  291. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  292. }
  293. func (OtherDrugWarehouseInfo) TableName() string {
  294. return "xt_drug_warehouse_info"
  295. }
  296. type VMDrugSalesReturnInfo struct {
  297. ID int64 `gorm:"column:id" json:"id" form:"id"`
  298. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  299. Count int64 `gorm:"column:count" json:"count" form:"count"`
  300. Status int64 `gorm:"column:status" json:"status" form:"status"`
  301. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  302. }
  303. func (VMDrugSalesReturnInfo) TableName() string {
  304. return "xt_drug_sales_return_info"
  305. }
  306. type VMDrugWarehouseOutInfo struct {
  307. ID int64 `gorm:"column:id" json:"id" form:"id"`
  308. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  309. Count int64 `gorm:"column:count" json:"count" form:"count"`
  310. Status int64 `gorm:"column:status" json:"status" form:"status"`
  311. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  312. }
  313. func (VMDrugWarehouseOutInfo) TableName() string {
  314. return "xt_drug_warehouse_out_info"
  315. }
  316. type VMDrugCancelStockInfo struct {
  317. ID int64 `gorm:"column:id" json:"id" form:"id"`
  318. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  319. Count int64 `gorm:"column:count" json:"count" form:"count"`
  320. Status int64 `gorm:"column:status" json:"status" form:"status"`
  321. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  322. }
  323. func (VMDrugCancelStockInfo) TableName() string {
  324. return "xt_drug_cancel_stock_info"
  325. }
  326. type BaseDrugLib struct {
  327. ID int64 `gorm:"column:id" json:"id" form:"id"`
  328. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  329. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  330. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  331. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  332. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  333. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  334. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  335. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  336. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  337. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  338. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  339. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  340. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  341. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  342. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  343. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  344. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  345. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  346. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  347. Number string `gorm:"column:number" json:"number" form:"number"`
  348. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  349. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  350. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  351. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  352. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  353. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  354. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  355. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  356. Code string `gorm:"column:code" json:"code" form:"code"`
  357. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  358. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  359. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  360. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  361. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  362. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  363. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  364. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  365. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  366. Label int64 `gorm:"column:label" json:"label" form:"label"`
  367. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  368. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  369. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  370. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  371. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  372. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  373. Status int64 `gorm:"column:status" json:"status" form:"status"`
  374. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  375. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  376. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  377. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  378. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  379. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  380. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  381. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  382. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  383. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  384. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  385. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  386. }
  387. func (BaseDrugLib) TableName() string {
  388. return "xt_base_drug"
  389. }
  390. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  391. err = readDb.Model(&BaseDrugLib{}).Preload("OtherDrugWarehouseInfo", "status = 1 AND org_id = ?", org_id).
  392. Preload("VMDrugSalesReturnInfo", "status = 1 AND org_id = ?", org_id).
  393. Preload("VMDrugWarehouseOutInfo", "status = 1 AND org_id = ?", org_id).
  394. Preload("VMDrugCancelStockInfo", "status = 1 AND org_id = ?", org_id).
  395. Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  396. return
  397. }
  398. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  399. err = writeDb.Create(&charge).Error
  400. return
  401. }
  402. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  403. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  404. 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")
  405. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  406. return
  407. }
  408. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  409. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  410. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  411. }).Where("org_id = ? AND status = 1 AND (user_type = 1 OR user_type = 2)", org_id).Find(&doctors).Error
  412. return
  413. }
  414. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  415. err = writeDb.Save(s).Error
  416. return
  417. }
  418. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  419. err = writeDb.Save(project).Error
  420. return
  421. }
  422. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  423. 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
  424. return
  425. }
  426. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  427. err := writeDb.Create(&patient).Error
  428. return err
  429. }
  430. func GetVMHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  431. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  432. return
  433. }
  434. func GetNewVMHisPatientInfo(org_id int64, his_patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  435. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, his_patient_id).First(&info).Error
  436. return
  437. }
  438. func GetNewHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  439. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, id).First(&info).Error
  440. return
  441. }
  442. func GetHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  443. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  444. return
  445. }
  446. func CreateOrder(order *models.HisOrder) (err error) {
  447. err = writeDb.Create(&order).Error
  448. return
  449. }
  450. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  451. err = writeDb.Create(&order).Error
  452. return
  453. }
  454. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  455. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  456. return
  457. }
  458. func FindHisPatientPrescriptionInfo(org_id int64, his_patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  459. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ?", org_id, record_date, his_patient_id).First(&info).Error
  460. return
  461. }
  462. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  463. 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
  464. return
  465. }
  466. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  467. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, patient_id).Last(&info).Error
  468. return
  469. }
  470. func FindLastPatientPrescriptionInfoTwo1(org_id int64, patient_id int64) (info models.HisPrescriptionInfo, err error) {
  471. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? and p_type = 1", org_id, patient_id).Last(&info).Error
  472. return
  473. }
  474. func FindLastPatientPrescriptionInfoTwo2(org_id int64, patient_id int64, start_time string, end_time string) (info []models.HisPrescriptionInfo, err error) {
  475. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? and p_type = 1 and FROM_UNIXTIME(record_date) >= ? and FROM_UNIXTIME(record_date) <= ?", org_id, patient_id, start_time, end_time).Find(&info).Error
  476. return
  477. }
  478. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  479. err = writeDb.Save(&info).Error
  480. return
  481. }
  482. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int64, end_time int64, doctor_id int64, keywords string) (order []*models.HisOrder, err error, total int64) {
  483. offset := (page - 1) * limit
  484. db := readDb.Model(&models.HisOrder{})
  485. if doctor_id > 0 {
  486. 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)
  487. }
  488. if len(keywords) > 0 {
  489. keywords = "%" + keywords + "%"
  490. 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)
  491. }
  492. if start_time != 0 {
  493. db = db.Where("his_order.settle_accounts_date>=?", start_time)
  494. }
  495. if end_time != 0 {
  496. db = db.Where("his_order.settle_accounts_date<=?", end_time)
  497. }
  498. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ?", user_org_id)
  499. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  500. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  501. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  502. Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
  503. return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
  504. })
  505. db = db.Count(&total)
  506. err = db.Limit(limit).Offset(offset).Order("ctime desc").Find(&order).Error
  507. return
  508. }
  509. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  510. 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
  511. return
  512. }
  513. func UpDatePrescriptionOrderStatus(user_org_id int64, ids []int64) (err error) {
  514. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
  515. return
  516. }
  517. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  518. 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": 2, "mtime": time.Now().Unix()}).Error
  519. return
  520. }
  521. func UpDateHisPrescriptionInfoNumber(user_org_id int64, his_patient_id int64, number string, record_time int64) (err error) {
  522. 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": 2, "mtime": time.Now().Unix()}).Error
  523. return
  524. }
  525. type HisOrder struct {
  526. ID int64 `gorm:"column:id" json:"id" form:"id"`
  527. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  528. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  529. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  530. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  531. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  532. Status int64 `gorm:"column:status" json:"status" form:"status"`
  533. Number string `gorm:"column:number" json:"number" form:"number"`
  534. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  535. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  536. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  537. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  538. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  539. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  540. Certno string `gorm:"column:certno" json:"certno" form:"certno"`
  541. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  542. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  543. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  544. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  545. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  546. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  547. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  548. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  549. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  550. MedType int64 `gorm:"column:med_type" json:"med_type" form:"med_type"`
  551. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  552. SzChargeInfo string `gorm:"column:sz_charge_info" json:"sz_charge_info" form:"sz_charge_info"`
  553. SzProjectInfo string `gorm:"column:sz_project_info" json:"sz_project_info" form:"sz_project_info"`
  554. SzMedicineInsuranceInfo string `gorm:"column:sz_medicine_insurance_info" json:"sz_medicine_insurance_info" form:"sz_medicine_insurance_info"`
  555. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  556. OrgSetlNumber string `gorm:"column:org_setl_number" json:"org_setl_number" form:"org_setl_number"`
  557. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  558. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  559. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  560. FaPiaoSn string `gorm:"column:fa_piao_sn" json:"fa_piao_sn" form:"fa_piao_sn"`
  561. //FaPiaoSn string `gorm:"column:fa_piao_sn" json:"fa_piao_sn" form:"fa_piao_sn"`
  562. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  563. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  564. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  565. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  566. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  567. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  568. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  569. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  570. }
  571. func (HisOrder) TableName() string {
  572. return "his_order"
  573. }
  574. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  575. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  576. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  577. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  578. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  579. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  580. Order("ctime desc").
  581. Find(&order).Error
  582. return
  583. }
  584. func GetHisPrescriptionThree(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  585. err = readDb.Model(&models.HisPrescription{}).
  586. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  587. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  588. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  589. }).
  590. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  591. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND batch_number=?", org_id, record_date, patient_id, number).
  592. Find(&prescription).Error
  593. return
  594. }
  595. type HisPrescriptionInfo struct {
  596. ID int64 `gorm:"column:id" json:"id" form:"id"`
  597. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  598. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  599. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  600. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  601. Status int64 `gorm:"column:status" json:"status" form:"status"`
  602. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  603. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  604. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  605. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  606. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  607. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  608. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  609. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  610. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  611. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  612. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  613. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  614. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  615. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  616. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  617. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  618. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  619. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  620. }
  621. func (HisPrescriptionInfo) TableName() string {
  622. return "his_prescription_info"
  623. }
  624. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  625. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  626. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  627. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  628. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  629. Order("ctime desc").Find(&prescriptionOrder).Error
  630. return
  631. }
  632. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  633. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ? ", id, org_id).
  634. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  635. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  636. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  637. return
  638. }
  639. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  640. err = readDb.Model(&models.HisPrescription{}).
  641. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  642. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  643. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  644. }).
  645. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  646. Find(&prescription).Error
  647. return
  648. }
  649. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  650. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  651. return
  652. }
  653. func UpdataOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  654. 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(), "refund_request_log": log, "refund_log": result, "status": 0}).Error
  655. 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
  656. 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
  657. return
  658. }
  659. func UpdataOrderStatusThree(id int64, number string, user_org_id int64, log string, result string) (err error) {
  660. 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(), "refund_request_log": log, "refund_log": result, "status": 0}).Error
  661. 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
  662. 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
  663. return
  664. }
  665. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  666. 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()})
  667. //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
  668. //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
  669. }
  670. func UpdataRegStatusTwo(his_patient_id int64, record_time int64, org_id int64) {
  671. writeDb.Model(&models.HisPatient{}).Where("status = 1 AND record_date =? AND user_org_id = ? AND id = ?", record_time, org_id, his_patient_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  672. writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", org_id, his_patient_id).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  673. writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", org_id, his_patient_id).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  674. }
  675. func UpdataRegStatus2(id int64) error {
  676. err := writeDb.Model(&models.HisPatient{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  677. return err
  678. }
  679. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  680. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  681. return
  682. }
  683. func GetAdminUserInfo(org_id int64) (role models.UserAdminRole, err error) {
  684. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1", org_id).First(&role).Error
  685. return
  686. }
  687. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  688. err = readDb.Model(&HisOrder{}).Where("user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  689. First(&order).Error
  690. return
  691. }
  692. func UpDateOrder(order models.HisOrder) (err error) {
  693. err = writeDb.Save(&order).Error
  694. return
  695. }
  696. func UpDateOrderTwo(order *models.HisOrder) (err error) {
  697. err = writeDb.Save(&order).Error
  698. return
  699. }
  700. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  701. 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
  702. 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
  703. return
  704. }
  705. func CreateErrMsgLog(log *models.HisOrderError) {
  706. writeDb.Model(&models.HisOrderError{}).Create(&log)
  707. }
  708. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  709. 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
  710. return
  711. }
  712. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  713. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  714. return
  715. }
  716. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  717. db := readDb.Model(&models.OutpatientServiceSick{})
  718. db = db.Where("user_org_id = ? AND status = 1", orgId)
  719. err = db.Order("ctime desc").Find(&list).Error
  720. return
  721. }
  722. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  723. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  724. db = db.Where("user_org_id = ? AND status = 1", orgId)
  725. err = db.Order("ctime desc").Find(&list).Error
  726. return
  727. }
  728. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  729. db := readDb.Model(&models.XtHisAddtionConfig{})
  730. db = db.Where("user_org_id = ? AND status = 1", orgId)
  731. err = db.Order("ctime desc").Find(&list).Error
  732. return
  733. }
  734. type XtHisOrder struct {
  735. ID int64 `gorm:"column:id" json:"id" form:"id"`
  736. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  737. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  738. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  739. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  740. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  741. Status int64 `gorm:"column:status" json:"status" form:"status"`
  742. Number string `gorm:"column:number" json:"number" form:"number"`
  743. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  744. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  745. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  746. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  747. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  748. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  749. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  750. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  751. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  752. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  753. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  754. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  755. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  756. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  757. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  758. }
  759. func (XtHisOrder) TableName() string {
  760. return "his_order"
  761. }
  762. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  763. err = readDb.Model(&models.HisPrescription{}).
  764. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  765. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  766. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  767. }).
  768. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  769. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  770. Find(&prescription).Error
  771. return
  772. }
  773. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  774. 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
  775. return
  776. }
  777. func DelelteAddition(id int64, user_org_id int64) (err error) {
  778. 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
  779. return
  780. }
  781. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*Schedule, err error, total int64) {
  782. offset := (page - 1) * limit
  783. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  784. if len(keywords) > 0 {
  785. keywords = "%" + keywords + "%"
  786. 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)
  787. 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 ?", org_id, record_date, keywords)
  788. }
  789. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  790. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  791. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).
  792. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id)
  793. db = db.Count(&total)
  794. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  795. return
  796. }
  797. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  798. patient := models.VMHisPatient{}
  799. 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
  800. return patient, err
  801. }
  802. type VMOtherHisPrescriptionInfo struct {
  803. ID int64 `gorm:"column:id" json:"id" form:"id"`
  804. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  805. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  806. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  807. Status int64 `gorm:"column:status" json:"status" form:"status"`
  808. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  809. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  810. }
  811. func (VMOtherHisPrescriptionInfo) TableName() string {
  812. return "his_prescription_info"
  813. }
  814. type VMHisPrescription struct {
  815. ID int64 `gorm:"column:id" json:"id" form:"id"`
  816. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  817. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  818. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  819. Status int64 `gorm:"column:status" json:"status" form:"status"`
  820. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  821. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  822. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  823. Type int64 `gorm:"column:type" json:"type" form:"type"`
  824. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  825. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  826. }
  827. func (VMHisPrescription) TableName() string {
  828. return "his_prescription"
  829. }
  830. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  831. 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).
  832. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  833. return db.Where("status = 1 AND user_org_id = ?", org_id).
  834. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  835. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  836. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  837. })
  838. }).Find(&advice).Error
  839. return
  840. }
  841. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  842. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  843. return
  844. }
  845. func GetFaPiaoHisOrderByID(order_id int64) (order models.HisFaPiaoOrder, err error) {
  846. str := strconv.FormatInt(order_id, 10)
  847. key := "%" + str + "%"
  848. err = readDb.Model(&models.HisFaPiaoOrder{}).Where("order_ids like ? and status = 1", key).First(&order).Error
  849. return
  850. }
  851. func GetHisOrderByIDTwo(order_id int64) (order models.HisOrder, err error) {
  852. err = readDb.Model(&models.HisOrder{}).Preload("HisOrderInfo", "status = 1").Preload("HisPatient", "status = 1").Where("id = ? AND status = 1", order_id).First(&order).Error
  853. return
  854. }
  855. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  856. db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  857. return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  858. })
  859. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  860. return
  861. }
  862. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfo, err error) {
  863. db := readDb.Model(&models.HisOrderInfo{})
  864. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  865. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  866. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  867. })
  868. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  869. return
  870. }
  871. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfo, err error) {
  872. db := readDb.Model(&models.HisOrderInfo{})
  873. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  874. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  875. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  876. })
  877. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  878. return
  879. }
  880. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_org string, clr_type string, mdtrtareaAdmvs string) (orders []*models.HisOrder, err error) {
  881. db := readDb.Model(&models.HisOrder{})
  882. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype)
  883. if len(clr_org) > 0 {
  884. db = db.Where("clr_optins = ?", clr_org)
  885. }
  886. if len(clr_type) > 0 {
  887. if mdtrtareaAdmvs == "150499" {
  888. if clr_type == "11" {
  889. db = db.Where("clr_type = ?", clr_type)
  890. }
  891. } else {
  892. db = db.Where("clr_type = ?", clr_type)
  893. }
  894. } else {
  895. if len(clr_type) == 0 {
  896. db = db.Where("clr_type = ?", "")
  897. } else {
  898. db = db.Where("clr_type = ?", "9903")
  899. }
  900. }
  901. err = db.Find(&orders).Error
  902. return
  903. }
  904. func GetOrderByTimeFive(start_time int64, end_time int64, org_id int64, insutype string, clr_org string, clr_type string, mdtrtareaAdmvs string) (orders []*models.HisOrder, err error) {
  905. db := readDb.Model(&models.HisOrder{})
  906. db = db.Where("user_org_id = ? AND order_status = 3 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype)
  907. if len(clr_org) > 0 {
  908. db = db.Where("clr_optins = ?", clr_org)
  909. }
  910. if len(clr_type) > 0 {
  911. if mdtrtareaAdmvs == "150499" {
  912. if clr_type == "11" {
  913. db = db.Where("clr_type = ?", clr_type)
  914. }
  915. } else {
  916. db = db.Where("clr_type = ?", clr_type)
  917. }
  918. }
  919. err = db.Find(&orders).Error
  920. return
  921. }
  922. func GetOrderByTimeFour(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  923. db := readDb.Model(&models.HisOrder{})
  924. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? ", org_id, end_time, start_time)
  925. err = db.Find(&orders).Error
  926. return
  927. }
  928. func GetOrderByTimeTenaaa(start_time int64, end_time int64, org_id int64, org string) (orders []*models.HisOrder, err error) {
  929. db := readDb.Model(&models.HisOrder{})
  930. db = db.Where("clr_options = ? and user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? ", org, org_id, end_time, start_time)
  931. err = db.Find(&orders).Error
  932. return
  933. }
  934. func GetOrderByTime11222(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  935. db := readDb.Model(&models.HisOrder{})
  936. db = db.Where("psn_name = '付云芳' and user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ?", org_id, end_time, start_time)
  937. err = db.Find(&orders).Error
  938. return
  939. }
  940. func GetOrderByTimeFourfor11(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  941. db := readDb.Model(&models.HisOrder{})
  942. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? and med_type = 11", org_id, end_time, start_time)
  943. err = db.Find(&orders).Error
  944. return
  945. }
  946. func GetOrderByTimeThree(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  947. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype).Find(&orders).Error
  948. return
  949. }
  950. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  951. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ?", org_id, end_time, start_time).Find(&orders).Error
  952. return
  953. }
  954. func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  955. var patient models.Patients
  956. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  957. if err != nil {
  958. if err == gorm.ErrRecordNotFound {
  959. return nil, nil
  960. } else {
  961. return nil, err
  962. }
  963. }
  964. return &patient, nil
  965. }
  966. func FindDiagnoseById(id int64) (models.HisXtDiagnoseConfig, error) {
  967. dealer := models.HisXtDiagnoseConfig{}
  968. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? and status = 1", id).First(&dealer).Error
  969. return dealer, err
  970. }
  971. func FindDiagnoseByIdtwo(id string) (models.HisXtDiagnoseConfig, error) {
  972. dealer := models.HisXtDiagnoseConfig{}
  973. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? and status = 1", id).First(&dealer).Error
  974. return dealer, err
  975. }
  976. func FindDiagnoseByIds(ids []string) ([]*models.HisXtDiagnoseConfig, error) {
  977. dealer := []*models.HisXtDiagnoseConfig{}
  978. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id IN (?) AND status = 1", ids).Find(&dealer).Error
  979. return dealer, err
  980. }
  981. func FindSickById(id int64) (*models.OutpatientServiceSick, error) {
  982. outPatient := &models.OutpatientServiceSick{}
  983. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&outPatient).Error
  984. return outPatient, err
  985. }
  986. //
  987. //type MonthHisPrescription struct {
  988. // ID int64 `gorm:"column:id" json:"id" form:"id"`
  989. // UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  990. // RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  991. // PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  992. // HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  993. // Status int64 `gorm:"column:status" json:"status" form:"status"`
  994. // Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  995. // Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  996. // Number string `gorm:"column:number" json:"number" form:"number"`
  997. // Type int64 `gorm:"column:type" json:"type" form:"type"`
  998. // Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  999. // Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1000. // Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1001. // OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1002. // BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1003. // PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1004. // Patients Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1005. // HisPatient models.VMHisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:patient_id" json:"hisPatient"`
  1006. // HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1007. // HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1008. // HisAdditionalCharge []*models.HisAdditionalCharge `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"addition"`
  1009. // VMHisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  1010. //}
  1011. //
  1012. //func (MonthHisPrescription) TableName() string {
  1013. // return "his_prescription"
  1014. //}
  1015. func GetMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  1016. err = readDb.Model(&models.HisPrescription{}).
  1017. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1018. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1019. }).
  1020. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1021. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1022. }).
  1023. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1024. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1025. }).
  1026. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND status = 1 AND p_type <> 1 AND med_type = ?", org_id, start_time, end_time, patient_id, reg_type).
  1027. Find(&prescription).Error
  1028. return
  1029. }
  1030. func GetPatientByNumber(number string, user_org_id int64) (patient Patients, err error) {
  1031. err = readDb.Model(&Patients{}).Where("(health_care_no = ? OR id_card_no = ?) AND user_org_id = ?", number, number, user_org_id).First(&patient).Error
  1032. return
  1033. }
  1034. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1035. err = readDb.Model(&Patients{}).Where("(health_care_no = ? or id_card_no = ?) AND user_org_id = ?", id_card_no, id_card_no, user_org_id).First(&patient).Error
  1036. return
  1037. }
  1038. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1039. 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
  1040. return
  1041. }
  1042. func GetAppRole(orgID int64) (models.App_Role, error) {
  1043. var appRole models.App_Role
  1044. err := readUserDb.Model(models.App_Role{}).Where("org_id = ? AND user_type = 2", orgID).First(&appRole).Error
  1045. return appRole, err
  1046. }
  1047. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1048. var patient Patients
  1049. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1050. return patient, err
  1051. }
  1052. func GetDrugList(orgID int64) (drug []*models.BaseDrugList, err error) {
  1053. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1054. table := XTReadDB().Table("xt_manufacturer as m")
  1055. fmt.Print(table)
  1056. if orgID > 0 {
  1057. db = db.Where("x.org_id = ? and x.id = 397", orgID)
  1058. }
  1059. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  1060. return drug, err
  1061. }
  1062. func GetDrugDosageForm(orgid int64) (dataconfig []*models.XtDrugDataConfig, err error) {
  1063. err = XTReadDB().Where("(org_id = ? or org_id = 0) and parent_id = 4 and status = 1", orgid).Find(&dataconfig).Error
  1064. return dataconfig, err
  1065. }
  1066. func GetDoctorList(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1067. //err = UserReadDB().Model(&role).Where("org_id = ? and status = 1 and user_type = 2", orgid).Find(&role).Error
  1068. //return role, err
  1069. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1070. table := UserReadDB().Table("sgj_user_admin as a")
  1071. fmt.Println(table)
  1072. err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.age,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1073. return role, err
  1074. }
  1075. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  1076. err = readDb.Model(&models.HisPrescription{}).
  1077. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1078. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1079. }).
  1080. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1081. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1082. }).
  1083. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1084. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1085. }).
  1086. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  1087. Find(&prescription).Error
  1088. return
  1089. }
  1090. func GetDoctorListTwo(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1091. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1 AND x.user_type = 2 AND x.org_id = ?", orgid)
  1092. //table := UserReadDB().Table("sgj_user_admin as a")
  1093. //fmt.Println(table)
  1094. err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.age,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1095. return role, err
  1096. }
  1097. func GetRoleList(orgid int64) (role []*models.SgjUserRole, err error) {
  1098. err = UserReadDB().Model(&role).Where("org_id = ? and status =1", orgid).Find(&role).Error
  1099. return role, err
  1100. }
  1101. func GetDrugListByDetail(orgID int64, id int64) (drug []*models.BaseDrugList, err error) {
  1102. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1103. table := XTReadDB().Table("xt_manufacturer as m")
  1104. fmt.Print(table)
  1105. if orgID > 0 {
  1106. db = db.Where("x.org_id = ? and x.id = ?", orgID, id)
  1107. }
  1108. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  1109. return drug, err
  1110. }
  1111. func GetGoodInformationList(orgid int64) (good []*models.GoodInformation, err error) {
  1112. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1113. table := XTReadDB().Table("xt_manufacturer as m")
  1114. fmt.Println(table)
  1115. if orgid > 0 {
  1116. db = db.Where("x.org_id = ?", orgid)
  1117. }
  1118. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  1119. return good, err
  1120. }
  1121. func GetGoodListByDetail(orgid int64, id int64) (good []*models.GoodInformation, err error) {
  1122. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1123. table := XTReadDB().Table("xt_manufacturer as m")
  1124. fmt.Println(table)
  1125. if orgid > 0 {
  1126. db = db.Where("x.org_id = ? and x.id= ?", orgid, id)
  1127. }
  1128. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  1129. return good, err
  1130. }
  1131. func GetDoctorListByDetail(orgid int64, id int64) (role []*models.SgjUserAdminRole, err error) {
  1132. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1133. table := UserReadDB().Table("sgj_user_admin as a")
  1134. fmt.Println(table)
  1135. if id > 0 {
  1136. db = db.Where("x.status = 1 and x.admin_user_id = ? and x.org_id = ?", id, orgid)
  1137. }
  1138. err = db.Select("x.age,x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1139. return role, err
  1140. }
  1141. func GetMyPorjecgList(orgid int64) (project []*models.MyHisProject, err error) {
  1142. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1143. return project, err
  1144. }
  1145. func GetMyPorjecgListDetail(orgid int64, id int64) (project []*models.MyHisProject, err error) {
  1146. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1 and id = ?", orgid, id).Find(&project).Error
  1147. return project, err
  1148. }
  1149. func GetBathchMyPorjecgList(idss []int64) (project []*models.MyHisProject, err error) {
  1150. db := XTReadDB().Table("xt_his_project")
  1151. if len(idss) == 1 {
  1152. err = db.Where("status = 1 and id = ?", idss[0]).Find(&project).Error
  1153. } else {
  1154. err = db.Where("status = 1 and id IN(?)", idss).Find(&project).Error
  1155. }
  1156. return project, err
  1157. }
  1158. func GetBathchMyPorjecgListtwo(org_id int64) (project []*models.MyHisProject, err error) {
  1159. db := XTReadDB().Table("xt_his_project")
  1160. err = db.Where("status = 1 and user_org_id = ?", org_id).Find(&project).Error
  1161. return project, err
  1162. }
  1163. func GetBatchDoctorList(idss []int64) (role []*models.SgjUserAdminRole, err error) {
  1164. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1165. table := UserReadDB().Table("sgj_user_admin as a")
  1166. fmt.Println(table)
  1167. if len(idss) == 1 {
  1168. db = db.Where("x.status = 1 and x.admin_user_id = ?", idss[0])
  1169. } else {
  1170. db = db.Where("x.status = 1 and x.admin_user_id IN(?)", idss)
  1171. }
  1172. err = db.Select("x.age,x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1173. return role, err
  1174. }
  1175. func GetAllPatient(org_id int64) (patients []*models.Patients, err error) {
  1176. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", org_id).Find(&patients).Error
  1177. return
  1178. }
  1179. func UpdateHisPrescriptionHisID(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1180. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1181. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1182. return
  1183. }
  1184. func UpdateHisPrescriptionHisIDTwo(his_patient_id int64, patient_id int64, record_time int64, org_id int64, start_time int64) {
  1185. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date <= ? AND record_date >= ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1186. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1187. return
  1188. }
  1189. func UpdateHisPrescriptionHisID1111(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1190. //XTWriteDB().Model(&models.HisPrescription{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1191. //XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1192. return
  1193. }
  1194. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1195. 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
  1196. return
  1197. }
  1198. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1199. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1200. return
  1201. }
  1202. func GetNewHisPrescriptionByNumber(number string) (pre models.HisPrescription, err error) {
  1203. err = readDb.Model(&models.HisPrescription{}).Where("batch_number = ? AND status = 1", number).First(&pre).Error
  1204. return
  1205. }
  1206. func CreateUploadRecord(result *models.HisFundSettleListResult) (err error) {
  1207. err = writeDb.Create(&result).Error
  1208. return
  1209. }
  1210. func GetUploadRecord(order_id int64) (result models.HisFundSettleListResult, err error) {
  1211. err = readDb.Model(&models.HisFundSettleListResult{}).Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1212. return
  1213. }
  1214. func UpdateRecord(result *models.HisFundSettleListResult) (err error) {
  1215. err = writeDb.Save(&result).Error
  1216. return
  1217. }
  1218. func GetDeviceNumberByID(bed_id int64, org_id int64) (device_number models.DeviceNumber, err error) {
  1219. err = readDb.Model(&models.DeviceNumber{}).Where("id = ? AND org_id = ?", bed_id, org_id).First(&device_number).Error
  1220. return
  1221. }
  1222. func UpdateHisPatientStatus(his *models.VMHisPatient) {
  1223. writeDb.Save(&his)
  1224. }
  1225. func UpdateHisPatient123(his *Patients) {
  1226. writeDb.Save(&his)
  1227. }
  1228. func GetLastHisOrder(org_id int64) (his models.HisOrder, err error) {
  1229. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND fa_piao_code <> '' AND fa_piao_number <> ''", org_id).Last(&his).Error
  1230. return
  1231. }
  1232. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  1233. err = readDb.Model(&models.HisOrder{}).Select("max(convert(fa_piao_number,signed)) as fa_piao_number").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Find(&his).Error
  1234. return
  1235. }
  1236. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1237. 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
  1238. return
  1239. }
  1240. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1241. 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).
  1242. Order("ctime desc").
  1243. Find(&order).Error
  1244. return
  1245. }
  1246. func GetNewHisOrderThree(mdtrt_id string) (order HisOrder, err error) {
  1247. err = readDb.Model(&HisOrder{}).Where("status = 1 AND mdtrt_id=? ", mdtrt_id).First(&order).Error
  1248. return
  1249. }
  1250. func UpdateHisPatientThree(his *models.HisPatient) {
  1251. writeDb.Save(&his)
  1252. }
  1253. func GetNewHisPrescriptionTwo(org_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1254. err = readDb.Model(&models.HisPrescription{}).
  1255. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1256. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1257. }).
  1258. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1259. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1260. }).
  1261. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1262. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1263. }).
  1264. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, record_date, his_patient_id, med_type).
  1265. Find(&prescription).Error
  1266. return
  1267. }
  1268. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_time int64, end_time int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1269. err = readDb.Model(&models.HisPrescription{}).
  1270. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1271. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1272. }).
  1273. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1274. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1275. }).
  1276. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1277. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1278. }).
  1279. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND status = 1 AND p_type <> 1 AND med_type = ?", org_id, start_time, end_time, patient_id, med_type).
  1280. Find(&prescription).Error
  1281. return
  1282. }
  1283. func GetNewHisPatientInfoFour(org_id int64, id int64) (info models.HisPatient, err error) {
  1284. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  1285. return
  1286. }
  1287. func GetTodayHisOrder(org_id int64, patient_id int64, record_time int64, number string) (order models.HisOrder, err error) {
  1288. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 1 AND mdtrt_id = ?", org_id, patient_id, record_time, number).First(&order).Error
  1289. return
  1290. }
  1291. func GetLastFundList(org_id int64) (order models.HisFundSettleListResult, err error) {
  1292. err = readDb.Model(&models.HisFundSettleListResult{}).Where("user_org_id = ? AND status = 1 ", org_id).Last(&order).Error
  1293. return
  1294. }
  1295. func GetOrderError(org_id int64) (order []*models.HisOrderError, err error) {
  1296. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = ? AND status = 1 AND stage = 10106 ", org_id).Find(&order).Error
  1297. return
  1298. }
  1299. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  1300. 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
  1301. return
  1302. }
  1303. func CreateHisPsn(psn *models.HisPsn) {
  1304. writeDb.Save(&psn)
  1305. }
  1306. func GetPsnByPatientId(patient_id int64) (psn models.HisPsn, err error) {
  1307. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1308. return
  1309. }
  1310. func GetPsnByPatientIdtWO(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1311. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ?", patient_id, record_date).Last(&psn).Error
  1312. return
  1313. }
  1314. func GetHisPatientByPatientId(patient_id int64) (psn models.HisPatient, err error) {
  1315. err = readDb.Model(&models.HisPatient{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1316. return
  1317. }
  1318. //func GetPsnByPatientIdTwo(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1319. // err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ? AND stage = 1", patient_id, record_date).Last(&psn).Error
  1320. // return
  1321. //}
  1322. func GetPsnByPatientIdTwo(patient_id int64) (psn models.HisPsn, err error) {
  1323. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1324. return
  1325. }
  1326. func GetAllHisOrder(org_id int64) (his []*models.HisOrder, err error) {
  1327. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2022-12-15 00:00:00'", org_id).Order("setl_time asc").Find(&his).Error
  1328. fmt.Println(err)
  1329. return
  1330. }
  1331. func GetAllHisOrderTwo(org_id int64) (his []*models.HisOrder, err error) {
  1332. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND id >= 247903", org_id).Order("setl_time asc").Find(&his).Error
  1333. fmt.Println(err)
  1334. return
  1335. }
  1336. func GetAllHisOrder10106(org_id int64) (his []*models.HisOrder, err error) {
  1337. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10106 AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2023-08-01 00:00:00' AND setl_time <= '2023-08-31 23:59:00'").Order("setl_time asc").Find(&his).Error
  1338. fmt.Println(err)
  1339. return
  1340. }
  1341. func GetAllHisOrder10138() (his []*models.HisOrder, err error) {
  1342. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10028 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-01-01 00:00:00' and mdtrt_id not like '%out%'").Order("setl_time asc").Find(&his).Error
  1343. fmt.Println(err)
  1344. return
  1345. }
  1346. func GetOrderError10138() (order []*models.HisOrderError, err error) {
  1347. err = readDb.Model(&models.HisOrderError{}).Where("status = 1 AND stage = 10138500").Find(&order).Error
  1348. return
  1349. }
  1350. func GetAllHisOrder10278() (his []*models.HisOrder, err error) {
  1351. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10537 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-09-01 00:00:00' AND setl_time <= '2024-10-31 23:00:00' and mdtrt_id not like '%out%'").Order("setl_time asc").Find(&his).Error
  1352. fmt.Println(err)
  1353. return
  1354. }
  1355. func GetAllHisOrder10265() (his []*models.HisOrder, err error) {
  1356. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10265 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-09-01 00:00:00' AND setl_time <= '2024-09-30 23:59:00'").Order("setl_time asc").Find(&his).Error
  1357. fmt.Println(err)
  1358. return
  1359. }
  1360. //func GetAllHisOrder10265() (his []*models.HisOrder, err error) {
  1361. // err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10265 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2023-09-01 00:00:00'").Order("setl_time asc").Find(&his).Error
  1362. // fmt.Println(err)
  1363. // return
  1364. //}
  1365. // func GetAllHisOrder2(org_id int64) (his []models.HisOrder, err error) {
  1366. // err = readDb.Model(&models.HisOrder{}).Where("id = 180753").Order("setl_time asc").First(&his).Error
  1367. // return
  1368. // }
  1369. func GetAllHisOrderErr10278() (his []*models.HisOrderError, err error) {
  1370. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = 10278 AND status = 1 AND stage = 10276").Find(&his).Error
  1371. return
  1372. }
  1373. func GetHisOrderInfoByNumberFour(order_number string) (order []*models.HisOrderInfo, err error) {
  1374. db := readDb.Model(&models.HisOrderInfo{})
  1375. err = db.Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1376. return
  1377. }
  1378. func UpdataOrderStatusByNumber(number string) (err error) {
  1379. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND number = ?", number).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  1380. return
  1381. }
  1382. func UpdataHospitalOrderStatus(number string, user_org_id int64) (err error) {
  1383. err = writeDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND order_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
  1384. 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
  1385. 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
  1386. return
  1387. }
  1388. func GetHisFundSettleListResult(order_id int64) (result models.HisFundSettleListResult, err error) {
  1389. db := readDb.Model(&models.HisFundSettleListResult{})
  1390. err = db.Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1391. return
  1392. }
  1393. func SaveClearRecord(record *models.HisYidiClearRecord) {
  1394. writeDb.Save(&record)
  1395. }
  1396. func GetClearRecordById(id int64) (record models.HisYidiClearRecord, err error) {
  1397. err = readDb.Model(&models.HisYidiClearRecord{}).Where("id = ? AND status = 1").First(&record).Error
  1398. return
  1399. }
  1400. func UpdateOrder(order models.HisOrder) (err error) {
  1401. err = writeDb.Save(&order).Error
  1402. return
  1403. }
  1404. func UpdateOrderTwo(order models.NewHisOrder111) (err error) {
  1405. err = writeDb.Save(&order).Error
  1406. return
  1407. }
  1408. func GetNewHisPrescriptionTen(org_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  1409. err = readDb.Model(&models.HisPrescriptionTen{}).
  1410. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1411. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1412. }).
  1413. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1414. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1415. }).
  1416. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND p_type <> 1 ", org_id, record_date, his_patient_id).
  1417. Find(&prescription).Error
  1418. return
  1419. }
  1420. func GetHisOrderByIDTwo1111(order_id int64) (order models.NewHisOrder111, err error) {
  1421. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1422. return
  1423. }
  1424. func GetHisPrescriptionForMedType(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  1425. err = readDb.Model(&models.HisPrescription{}).
  1426. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1427. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1428. }).
  1429. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1430. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1431. }).
  1432. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1433. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  1434. }).
  1435. Where("(user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 and med_type = 148801) or (user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 and med_type = 118801)", org_id, record_date, patient_id, org_id, record_date, patient_id).
  1436. Find(&prescription).Error
  1437. return
  1438. }
  1439. func GetOrderByTimeTen(start_time string, end_time string, org_id int64) (orders []*models.FixMonRecDetailFileIn, err error) {
  1440. err = readDb.Raw("select CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') END AS fund_key, his_order.insutype, '99' as `psn_type` , his_order.`med_type`, COUNT(DISTINCT his_order.`certno`) AS psn_cnt, count(*) as psn_time, sum(his_order.medfee_sumamt) as sumamt, sum(his_order.inscp_scp_amt) as amt, sum(his_order.fund_pay_sumamt) + sum(his_order.acct_pay) as fund FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 1 and his_order.order_status = 2 and his_order.setl_time >= ? and his_order.setl_time <= ? and his_order.setl_id <> '' GROUP BY fund_key", org_id, start_time+" 00:00:00", end_time+" 23:00:00").Scan(&orders).Error
  1441. return
  1442. }
  1443. func GetOrderByTimeTentwo(start_time string, end_time string, org_id int64) (orders []*models.FixMonRecDetailFileIn, err error) {
  1444. err = readDb.Raw("select CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') END AS fund_key, his_order.insutype, '99' as `psn_type` , his_order.`med_type`, COUNT(DISTINCT his_order.`certno`) AS psn_cnt, count(*) as psn_time, sum(his_order.medfee_sumamt) as sumamt, sum(his_order.inscp_scp_amt) as amt, sum(his_order.fund_pay_sumamt) + sum(his_order.acct_pay) as fund FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 0 and his_order.order_status = 3 and his_order.setl_time >= ? and his_order.setl_time <= ? and his_order.setl_id <> '' GROUP BY fund_key", org_id, start_time+" 00:00:00", end_time+" 23:00:00").Scan(&orders).Error
  1445. return
  1446. }
  1447. func GetOrderDetailByTimeTen(start_time string, end_time string, org_id int64, fund_key string) (fund []models.FundDetail, err error) {
  1448. err = readDb.Raw("SELECT CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') end AS fund_key, his_order.`setl_detail` FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 1 and his_order.order_status = 2 and his_order.setl_time >= ? and his_order.setl_time <= ? and CONCAT(his_order.insutype, '99', his_order.med_type, '555555') = ?", org_id, start_time+" 00:00:00", end_time+" 23:59:00", fund_key).Scan(&fund).Error
  1449. return
  1450. }
  1451. func Saveflow(flow models.HisPrescriptionFlow) {
  1452. writeDb.Save(&flow)
  1453. }
  1454. func Createflow(flow *models.HisPrescriptionFlow) {
  1455. writeDb.Create(&flow)
  1456. }
  1457. func GetNewHisPrescriptionTenone(org_id int64, number string) (prescription []*models.HisPrescriptionTen, err error) {
  1458. err = readDb.Model(&models.HisPrescriptionTen{}).
  1459. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1460. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1461. }).
  1462. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1463. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1464. }).
  1465. Where("user_org_id = ? AND status = 1 AND batch_number = ? and order_status = 4 ", org_id, number).
  1466. Find(&prescription).Error
  1467. return
  1468. }
  1469. func GetHisOrderByIDThree(start_time string) (his []*models.HisOrder, err error) {
  1470. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10265 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= ?", start_time).Order("setl_time asc").Find(&his).Error
  1471. fmt.Println(err)
  1472. return
  1473. }
  1474. func UpDatePrescriptionNumber111(user_org_id int64, start_time int64, end_time int64, number string, patient_id int64) (err error) {
  1475. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND record_date >= ? and record_date <= ? and patient_id = ? and order_status = 1", user_org_id, start_time, end_time, patient_id).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1476. return
  1477. }
  1478. func UpDatePrescriptionNumber222(user_org_id int64, id int64, number string, patient_id int64) (err error) {
  1479. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id = ? and patient_id = ?", user_org_id, id, patient_id).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1480. return
  1481. }
  1482. func GetAllHisOrderTwo10485() (his []*models.HisOrder, err error) {
  1483. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10485 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-01-01 00:00:00' ").Order("setl_time asc").Find(&his).Error
  1484. fmt.Println(err)
  1485. return
  1486. }
  1487. func GetNewDrugWarehouseInfo(org_id int64, id_arr []string) (newDrugWarehouse []*models.NewDrugWarehouseInfo, err error) {
  1488. readDb.Model(&models.NewDrugWarehouseInfo{}).Where("org_id = ? and status = 1 and id in (?) ", org_id, id_arr).Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&newDrugWarehouse)
  1489. return
  1490. }
  1491. func GetNewDrugWarehouseInfobytime(org_id int64, s_time int64, e_time int64) (newDrugWarehouse []*models.NewDrugWarehouseInfo, err error) {
  1492. readDb.Model(&models.NewDrugWarehouseInfo{}).Where("org_id = ? and status = 1 and ctime > ? and ctime < ? and drug_code <> '' ", org_id, s_time, e_time).Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&newDrugWarehouse)
  1493. return
  1494. }
  1495. func GetNewDrugFlowInfo(org_id int64, id_arr []string) (flows []*models.DrugFlow, err error) {
  1496. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = ? and status = 1 and id in (?)", org_id, id_arr).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1497. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1498. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1499. return
  1500. }
  1501. func GetNewDrugFlowInfoByPatient(patient_id int64, drug_id int64, time int64, org_id int64) (flows []*models.DrugFlow, err error) {
  1502. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = ? and status = 1 and patient_id = ? and drug_id = ? and system_time = ?", org_id, patient_id, drug_id, time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1503. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1504. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1505. return
  1506. }
  1507. func GetNewUploadDrugFlowInfoByPatientTwo(patient_id int64, advice_id int64, time int64, org_id int64) (flows []*models.DrugFlow, err error) {
  1508. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = ? and status = 1 and patient_id = ? and drug_id = ? and system_time = ? and is_sale = 1", org_id, patient_id, advice_id, time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1509. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1510. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1511. return
  1512. }
  1513. func GetNewDrugFlowInfotwo() (flows []*models.DrugFlow, err error) {
  1514. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = 10188 and status = 1 and id >= ? and consumable_type = 3 and is_sale = 0", 2394762).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1515. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1516. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1517. return
  1518. }
  1519. func GetNewDrugFlowInfothree() (flows []*models.DrugFlow, err error) {
  1520. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = 10217 and status = 1 and id >= ? and consumable_type = 3 and is_sale = 0", 2328112).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1521. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1522. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1523. return
  1524. }
  1525. func GetNewDrugFlowInfothree123() (flows []*models.DrugFlow, err error) {
  1526. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = 10217 and status = 1 and length(drug_code) > 0 and consumable_type = 3 and is_sale = 0 and id > 2739716").Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1527. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1528. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1529. return
  1530. }
  1531. func GetNewDrugFlowInforTen(system_time int64, org_id int64) (flows []*models.DrugFlow, err error) {
  1532. err = readDb.Model(&models.DrugFlow{}).Joins("join his_doctor_advice_info info on info.patient_id = xt_drug_flow.patient_id and info.drug_id = xt_drug_flow.drug_id and info.record_date = xt_drug_flow.system_time").Where("xt_drug_flow.user_org_id = ? and xt_drug_flow.status = 1 and xt_drug_flow.consumable_type = 3 and xt_drug_flow.is_sale = 0 and xt_drug_flow.system_time = ?", org_id, system_time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1533. return db.Where("status = 1 and drug_code <> ''").Preload("BaseDrugLib", "status=1")
  1534. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1535. return
  1536. }
  1537. func GetNewDrugFlowInforTenone(start_system_time int64, end_system_time int64, org_id int64) (flows []*models.DrugFlow, err error) {
  1538. err = readDb.Model(&models.DrugFlow{}).Joins("join his_doctor_advice_info info on info.patient_id = xt_drug_flow.patient_id and info.drug_id = xt_drug_flow.drug_id and info.record_date = xt_drug_flow.system_time").Where("xt_drug_flow.user_org_id = ? and xt_drug_flow.status = 1 and xt_drug_flow.consumable_type = 3 and xt_drug_flow.is_sale = 0 and xt_drug_flow.system_time >= ? and xt_drug_flow.system_time <= ?", org_id, start_system_time, end_system_time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1539. return db.Where("status = 1 and drug_code <> ''").Preload("BaseDrugLib", "status=1")
  1540. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1541. return
  1542. }
  1543. func GetHisPrescriptionByID(id int64) (pre models.HisPrescription) {
  1544. err = readDb.Model(&models.HisPrescription{}).Where("id = ? and status = 1", id).Find(&pre).Error
  1545. return
  1546. }
  1547. func GetHisOrderByNumber(number string) (order models.HisOrder) {
  1548. err = readDb.Model(&models.HisOrder{}).Where("number = ? and status = 1", number).First(&order).Error
  1549. return
  1550. }
  1551. func SaveDF(df *models.DrugFlow) (err error) {
  1552. //err = writeDb.(&df).Error
  1553. err = XTWriteDB().Model(&models.DrugFlow{}).Where("id = ? ", df.ID).Updates(map[string]interface{}{
  1554. "is_sale": df.IsSale,
  1555. "sale_date": df.SaleDate,
  1556. "bchno": df.Bchno,
  1557. //"is_change"
  1558. }).Error
  1559. return
  1560. }
  1561. func SaveDF2(df *models.DrugFlow) (err error) {
  1562. //err = writeDb.(&df).Error
  1563. err = XTWriteDB().Model(&models.DrugFlow{}).Where("id = ? ", df.ID).Updates(map[string]interface{}{
  1564. "is_change": df.IsChange,
  1565. "bg_bchno": df.BgBchno,
  1566. //"is_change"
  1567. }).Error
  1568. return
  1569. }
  1570. func GetDrugByID(drug_id int64) (drug models.BaseDrugLib, err error) {
  1571. err = readDb.Model(&models.BaseDrugLib{}).Where("id = ?", drug_id).First(&drug).Error
  1572. return
  1573. }
  1574. func GetBbx01ByTeamID(team_id int64) (team models.XtHisProjectTeam) {
  1575. err = readDb.Model(&models.XtHisProjectTeam{}).Where("id = ?", team_id).First(&team).Error
  1576. return
  1577. }
  1578. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1579. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1580. 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)
  1581. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1582. 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)
  1583. }).Find(&order).Error
  1584. return
  1585. }
  1586. type HisOrderInfo struct {
  1587. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1588. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1589. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1590. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1591. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1592. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1593. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1594. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1595. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1596. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1597. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1598. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1599. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1600. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1601. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1602. SelfpayProp float64 `gorm:"column:selfpay_prop" json:"selfpay_prop" form:"selfpay_prop"`
  1603. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1604. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1605. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1606. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1607. }
  1608. func (HisOrderInfo) TableName() string {
  1609. return "his_order_info"
  1610. }
  1611. type HisDoctorAdviceInfo struct {
  1612. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1613. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1614. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1615. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1616. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1617. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1618. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1619. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1620. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1621. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1622. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1623. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1624. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1625. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1626. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1627. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1628. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1629. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1630. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1631. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1632. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1633. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1634. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1635. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  1636. IsUpload int64 `gorm:"column:is_upload" json:"is_upload" form:"is_upload"`
  1637. }
  1638. type Drug struct {
  1639. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1640. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  1641. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1642. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1643. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  1644. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  1645. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  1646. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  1647. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1648. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  1649. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  1650. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  1651. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  1652. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  1653. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  1654. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  1655. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  1656. Dose string `gorm:"column:dose" json:"dose" form:"dose"`
  1657. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  1658. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  1659. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  1660. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  1661. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  1662. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  1663. Number string `gorm:"column:number" json:"number" form:"number"`
  1664. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  1665. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  1666. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  1667. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  1668. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  1669. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  1670. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  1671. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  1672. Code string `gorm:"column:code" json:"code" form:"code"`
  1673. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  1674. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  1675. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  1676. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  1677. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  1678. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1679. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1680. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1681. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1682. Label int64 `gorm:"column:label" json:"label" form:"label"`
  1683. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  1684. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  1685. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  1686. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  1687. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  1688. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  1689. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1690. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1691. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1692. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1693. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  1694. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  1695. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  1696. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1697. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  1698. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  1699. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  1700. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  1701. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  1702. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  1703. Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  1704. Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  1705. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  1706. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  1707. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  1708. Total float64 `gorm:"column:total" json:"total" form:"total"`
  1709. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1710. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  1711. Bck01b string `gorm:"column:bck01b" json:"bck01b" form:"bck01b"`
  1712. Bby01 string `gorm:"column:bby01" json:"bby01" form:"bby01"`
  1713. Bbx01 string `gorm:"column:bbx01" json:"bbx01" form:"bbx01"`
  1714. }
  1715. func (Drug) TableName() string {
  1716. return "xt_base_drug"
  1717. }
  1718. type VMHisProject struct {
  1719. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1720. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1721. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1722. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1723. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1724. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1725. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1726. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1727. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1728. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1729. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1730. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1731. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1732. }
  1733. func (VMHisProject) TableName() string {
  1734. return "xt_his_project"
  1735. }
  1736. type VMGoodInfo struct {
  1737. ID int64 `gorm:"column:id" json:"id"`
  1738. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  1739. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  1740. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  1741. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  1742. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  1743. Total float64 `gorm:"column:total" json:"total" form:"total"`
  1744. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  1745. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  1746. }
  1747. func (VMGoodInfo) TableName() string {
  1748. return "xt_good_information"
  1749. }
  1750. func (HisDoctorAdviceInfo) TableName() string {
  1751. return "his_doctor_advice_info"
  1752. }
  1753. type VMHisPatient struct {
  1754. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1755. BalanceAccountsType int64 `gorm:"column:balance_accounts_type" json:"balance_accounts_type" form:"balance_accounts_type"`
  1756. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  1757. Name string `gorm:"column:name" json:"name" form:"name"`
  1758. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  1759. IdType int64 `gorm:"column:id_type" json:"id_type" form:"id_type"`
  1760. MedicalTreatmentType int64 `gorm:"column:medical_treatment_type" json:"medical_treatment_type" form:"medical_treatment_type"`
  1761. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  1762. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1763. Age float64 `gorm:"column:age" json:"age" form:"age"`
  1764. PhoneNumber string `gorm:"column:phone_number" json:"phone_number" form:"phone_number"`
  1765. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1766. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  1767. AdminUserId int64 `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
  1768. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1769. IsNeedCostOfProduction int64 `gorm:"column:is_need_cost_of_production" json:"is_need_cost_of_production" form:"is_need_cost_of_production"`
  1770. RegisterCost float64 `gorm:"column:register_cost" json:"register_cost" form:"register_cost"`
  1771. TreatmentCost float64 `gorm:"column:treatment_cost" json:"treatment_cost" form:"treatment_cost"`
  1772. CostOfProduction float64 `gorm:"column:cost_of_production" json:"cost_of_production" form:"cost_of_production"`
  1773. Total float64 `gorm:"column:total" json:"total" form:"total"`
  1774. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1775. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1776. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1777. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1778. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1779. Number string `gorm:"column:number" json:"number" form:"number"`
  1780. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1781. IsReturn int64 `gorm:"column:is_return" json:"is_return" form:"is_return"`
  1782. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1783. PsnCertType string `gorm:"column:psn_cert_type" json:"psn_cert_type" form:"psn_cert_type"`
  1784. Certno string `gorm:"column:certno" json:"certno" form:"certno"`
  1785. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1786. Gend string `gorm:"column:gend" json:"gend" form:"gend"`
  1787. Naty string `gorm:"column:naty" json:"naty" form:"naty"`
  1788. Brdy string `gorm:"column:brdy" json:"brdy" form:"brdy"`
  1789. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1790. Idetinfo string `gorm:"column:idetinfo" json:"idetinfo" form:"idetinfo"`
  1791. IptOtpNo string `gorm:"column:ipt_otp_no" json:"ipt_otp_no" form:"ipt_otp_no"`
  1792. PType string `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1793. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1794. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1795. PatientInfo string `gorm:"column:patient_info" json:"patient_info" form:"patient_info"`
  1796. }
  1797. func (VMHisPatient) TableName() string {
  1798. return "his_patient"
  1799. }
  1800. type HisPrescriptionProject struct {
  1801. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1802. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1803. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1804. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1805. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1806. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1807. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1808. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1809. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1810. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1811. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1812. Count string `gorm:"column:count" json:"count" form:"count"`
  1813. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1814. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1815. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1816. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1817. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1818. Day string `gorm:"column:day" json:"day" form:"day"`
  1819. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1820. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1821. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1822. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1823. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1824. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1825. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1826. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1827. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1828. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1829. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1830. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1831. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1832. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1833. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  1834. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  1835. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  1836. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1837. }
  1838. func (HisPrescriptionProject) TableName() string {
  1839. return "his_prescription_project"
  1840. }
  1841. func FindeHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  1842. db := XTReadDB().Model(&advice).Where("status= 1 and drug_code <> ''")
  1843. if orgid > 0 {
  1844. db = db.Where("user_org_id = ?", orgid)
  1845. }
  1846. if patient_id > 0 {
  1847. db = db.Where("patient_id = ?", patient_id)
  1848. }
  1849. if stime > 0 {
  1850. db = db.Where("advice_date >=?", stime)
  1851. }
  1852. if etime > 0 {
  1853. db = db.Where("advice_date<=?", etime)
  1854. }
  1855. err = db.Find(&advice).Error
  1856. return advice, err
  1857. }
  1858. func FindUploadHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  1859. db := XTReadDB().Model(&advice).Where("status= 1")
  1860. if orgid > 0 {
  1861. db = db.Where("user_org_id = ?", orgid)
  1862. }
  1863. if patient_id > 0 {
  1864. db = db.Where("patient_id = ?", patient_id)
  1865. }
  1866. if stime > 0 {
  1867. db = db.Where("advice_date >=?", stime)
  1868. }
  1869. if etime > 0 {
  1870. db = db.Where("advice_date<=?", etime)
  1871. }
  1872. db = db.Where("is_upload = 1")
  1873. err = db.Find(&advice).Error
  1874. return advice, err
  1875. }
  1876. func SaveDoctoradviceStatus(id int64) {
  1877. writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", id).Updates(map[string]interface{}{"is_upload": 1})
  1878. }
  1879. func SaveDoctoradviceStatusTwo(id int64) {
  1880. writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", id).Updates(map[string]interface{}{"is_upload": 0})
  1881. }
  1882. func FindHisAdviceDocAdvice(id int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  1883. db := XTReadDB().Model(&advice).Where("status= 1 and id = ?", id)
  1884. err = db.Find(&advice).Error
  1885. return advice, err
  1886. }