|
|
|
|
3
|
import (
|
3
|
import (
|
4
|
"XT_New/models"
|
4
|
"XT_New/models"
|
5
|
"errors"
|
5
|
"errors"
|
6
|
- "fmt"
|
|
|
7
|
"strings"
|
6
|
"strings"
|
8
|
"time"
|
7
|
"time"
|
9
|
)
|
8
|
)
|
|
|
|
|
17
|
} else {
|
16
|
} else {
|
18
|
err = readDb.Model(&models.InspectionReference{}).Where("org_id=0 and status=1 and inspection_type = 0").Order("project_id,created_time").Find(&reference).Error
|
17
|
err = readDb.Model(&models.InspectionReference{}).Where("org_id=0 and status=1 and inspection_type = 0").Order("project_id,created_time").Find(&reference).Error
|
19
|
}
|
18
|
}
|
20
|
-
|
|
|
21
|
} else {
|
19
|
} else {
|
22
|
-
|
|
|
23
|
var count int
|
20
|
var count int
|
24
|
err = readDb.Model(&models.InspectionReference{}).Where("org_id=? and status=1 and inspection_type = ?", orgId, inspect_type).Count(&count).Error
|
21
|
err = readDb.Model(&models.InspectionReference{}).Where("org_id=? and status=1 and inspection_type = ?", orgId, inspect_type).Count(&count).Error
|
25
|
if count > 0 {
|
22
|
if count > 0 {
|
|
|
|
|
27
|
} else {
|
24
|
} else {
|
28
|
err = readDb.Model(&models.InspectionReference{}).Where("org_id=0 and status=1 and inspection_type = ?", inspect_type).Order("project_id,created_time").Find(&reference).Error
|
25
|
err = readDb.Model(&models.InspectionReference{}).Where("org_id=0 and status=1 and inspection_type = ?", inspect_type).Order("project_id,created_time").Find(&reference).Error
|
29
|
}
|
26
|
}
|
30
|
-
|
|
|
31
|
}
|
27
|
}
|
32
|
-
|
|
|
33
|
return
|
28
|
return
|
34
|
}
|
29
|
}
|
35
|
|
30
|
|
|
|
|
|
44
|
}
|
39
|
}
|
45
|
|
40
|
|
46
|
func GetAdvices(orgid int64, patientid int64, recorddate int64) (advcie []*models.DoctorAdvice, err error) {
|
41
|
func GetAdvices(orgid int64, patientid int64, recorddate int64) (advcie []*models.DoctorAdvice, err error) {
|
47
|
-
|
|
|
48
|
err = XTReadDB().Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and record_date = ? and status =1", patientid, orgid, recorddate).Find(&advcie).Error
|
42
|
err = XTReadDB().Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and record_date = ? and status =1", patientid, orgid, recorddate).Find(&advcie).Error
|
49
|
return
|
43
|
return
|
50
|
}
|
44
|
}
|
|
|
|
|
53
|
err = XTReadDB().Where("patient_id = ? and user_org_id = ? and record_date = ? and status =1 and is_prescription = 1", patientid, orgid, recorddate).Find(&advice).Error
|
47
|
err = XTReadDB().Where("patient_id = ? and user_org_id = ? and record_date = ? and status =1 and is_prescription = 1", patientid, orgid, recorddate).Find(&advice).Error
|
54
|
return advice, err
|
48
|
return advice, err
|
55
|
}
|
49
|
}
|
56
|
-
|
|
|
57
|
func UpdateDoctorAdvieById(id int64, prescription_number float64) (models.DoctorAdvice, error) {
|
50
|
func UpdateDoctorAdvieById(id int64, prescription_number float64) (models.DoctorAdvice, error) {
|
58
|
-
|
|
|
59
|
advice := models.DoctorAdvice{}
|
51
|
advice := models.DoctorAdvice{}
|
60
|
err := XTWriteDB().Model(&advice).Where("id=? and status= 1", id).Updates(map[string]interface{}{"prescribing_number": prescription_number}).Error
|
52
|
err := XTWriteDB().Model(&advice).Where("id=? and status= 1", id).Updates(map[string]interface{}{"prescribing_number": prescription_number}).Error
|
61
|
return advice, err
|
53
|
return advice, err
|
62
|
}
|
54
|
}
|
63
|
-
|
|
|
64
|
func UpdateDoctorAdvieByIdOne(id int64, prescription_number float64, single_dose float64) (models.DoctorAdvice, error) {
|
55
|
func UpdateDoctorAdvieByIdOne(id int64, prescription_number float64, single_dose float64) (models.DoctorAdvice, error) {
|
65
|
-
|
|
|
66
|
advice := models.DoctorAdvice{}
|
56
|
advice := models.DoctorAdvice{}
|
67
|
err := XTWriteDB().Model(&advice).Where("id=? and status= 1 ", id).Updates(map[string]interface{}{"prescribing_number": prescription_number, "single_dose": single_dose}).Error
|
57
|
err := XTWriteDB().Model(&advice).Where("id=? and status= 1 ", id).Updates(map[string]interface{}{"prescribing_number": prescription_number, "single_dose": single_dose}).Error
|
68
|
return advice, err
|
58
|
return advice, err
|
69
|
}
|
59
|
}
|
70
|
-
|
|
|
71
|
func CreatePatientInspection(inspectins []models.Inspection) (err error) {
|
60
|
func CreatePatientInspection(inspectins []models.Inspection) (err error) {
|
72
|
if len(inspectins) == 0 {
|
61
|
if len(inspectins) == 0 {
|
73
|
err = errors.New("Inspections Cant be nil.")
|
62
|
err = errors.New("Inspections Cant be nil.")
|
74
|
return
|
63
|
return
|
75
|
}
|
64
|
}
|
76
|
-
|
|
|
77
|
thisSQL := "INSERT INTO xt_inspection (patient_id, org_id, project_id, item_id, item_name, project_name, inspect_type, inspect_value, inspect_date, status, created_time, updated_time) VALUES "
|
65
|
thisSQL := "INSERT INTO xt_inspection (patient_id, org_id, project_id, item_id, item_name, project_name, inspect_type, inspect_value, inspect_date, status, created_time, updated_time) VALUES "
|
78
|
insertParams := make([]string, 0)
|
66
|
insertParams := make([]string, 0)
|
79
|
insertData := make([]interface{}, 0)
|
67
|
insertData := make([]interface{}, 0)
|
|
|
|
|
96
|
err = writeDb.Exec(thisSQL, insertData...).Error
|
84
|
err = writeDb.Exec(thisSQL, insertData...).Error
|
97
|
return
|
85
|
return
|
98
|
}
|
86
|
}
|
99
|
-
|
|
|
100
|
func SavePatientInspection(inspectin models.Inspection) (err error) {
|
87
|
func SavePatientInspection(inspectin models.Inspection) (err error) {
|
101
|
err = writeDb.Save(&inspectin).Error
|
88
|
err = writeDb.Save(&inspectin).Error
|
102
|
return
|
89
|
return
|
|
|
|
|
105
|
err = writeDb.Model(&models.Inspection{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0}).Error
|
92
|
err = writeDb.Model(&models.Inspection{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0}).Error
|
106
|
return
|
93
|
return
|
107
|
}
|
94
|
}
|
108
|
-
|
|
|
109
|
func EditPatientInspection(add []models.Inspection, edit []models.Inspection, noDeleteIDs []int64, patientId, orgId, projectId, date int64) (err error) {
|
95
|
func EditPatientInspection(add []models.Inspection, edit []models.Inspection, noDeleteIDs []int64, patientId, orgId, projectId, date int64) (err error) {
|
110
|
if len(add) == 0 && len(edit) == 0 && len(noDeleteIDs) == 0 {
|
96
|
if len(add) == 0 && len(edit) == 0 && len(noDeleteIDs) == 0 {
|
111
|
err = errors.New(" Cant be nil.")
|
97
|
err = errors.New(" Cant be nil.")
|
|
|
|
|
168
|
}
|
154
|
}
|
169
|
|
155
|
|
170
|
func GetPatientInspections(orgId, patientId, projectId, page int64) (inspections []*models.Inspection, total int64, date int64, err error) {
|
156
|
func GetPatientInspections(orgId, patientId, projectId, page int64) (inspections []*models.Inspection, total int64, date int64, err error) {
|
171
|
-
|
|
|
172
|
var projectCount models.UserInspectionProjectCount
|
157
|
var projectCount models.UserInspectionProjectCount
|
173
|
err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id=? and status=1", patientId, orgId, projectId).Select("count(distinct inspect_date) as count, project_id, patient_id").Order("inspect_date desc").Scan(&projectCount).Error
|
158
|
err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id=? and status=1", patientId, orgId, projectId).Select("count(distinct inspect_date) as count, project_id, patient_id").Order("inspect_date desc").Scan(&projectCount).Error
|
174
|
-
|
|
|
175
|
if err != nil {
|
159
|
if err != nil {
|
176
|
return
|
160
|
return
|
177
|
}
|
161
|
}
|
178
|
-
|
|
|
179
|
total = projectCount.Count
|
162
|
total = projectCount.Count
|
180
|
if total == 0 || page > total {
|
163
|
if total == 0 || page > total {
|
181
|
return
|
164
|
return
|
182
|
}
|
165
|
}
|
183
|
-
|
|
|
184
|
var Id models.InspectionDate
|
166
|
var Id models.InspectionDate
|
185
|
err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id=? and status=1", patientId, orgId, projectId).Select("inspect_date").Group("inspect_date").Order("inspect_date desc").Offset(page - 1).Limit(1).Scan(&Id).Error
|
167
|
err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id=? and status=1", patientId, orgId, projectId).Select("inspect_date").Group("inspect_date").Order("inspect_date desc").Offset(page - 1).Limit(1).Scan(&Id).Error
|
186
|
if err != nil {
|
168
|
if err != nil {
|
|
|
|
|
291
|
return
|
273
|
return
|
292
|
}
|
274
|
}
|
293
|
|
275
|
|
|
|
276
|
+func GetInspectionReferenceFour(project_id int64, item_id int64) (reference models.InspectionReference, err error) {
|
|
|
277
|
+ err = readDb.Model(&models.InspectionReference{}).Where("project_id = ? and item_id = ? and status = 1", project_id, item_id).Order("project_id").Find(&reference).Error
|
|
|
278
|
+ return
|
|
|
279
|
+}
|
|
|
280
|
+
|
294
|
func GetInspectionTwo(startime int64, endtime int64, orgid int64, projectid int64, itemid int64) (inspection []*models.Inspection, total int64, err error) {
|
281
|
func GetInspectionTwo(startime int64, endtime int64, orgid int64, projectid int64, itemid int64) (inspection []*models.Inspection, total int64, err error) {
|
295
|
db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
|
282
|
db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
|
296
|
db = db.Where("project_id = ? and item_id = ?", projectid, itemid)
|
283
|
db = db.Where("project_id = ? and item_id = ?", projectid, itemid)
|
|
|
|
|
318
|
}
|
305
|
}
|
319
|
|
306
|
|
320
|
func GetLastInspection(patientid int64, date int64, projectid int64, orgid int64) (models.Inspection, error) {
|
307
|
func GetLastInspection(patientid int64, date int64, projectid int64, orgid int64) (models.Inspection, error) {
|
321
|
-
|
|
|
322
|
inspection := models.Inspection{}
|
308
|
inspection := models.Inspection{}
|
323
|
err := XTReadDB().Group("inspect_date").Order("inspect_date asc").Where("patient_id = ? and inspect_date < ? and project_id =? and status=1 and org_id= ?", patientid, date, projectid, orgid).Limit(1).Find(&inspection).Error
|
309
|
err := XTReadDB().Group("inspect_date").Order("inspect_date asc").Where("patient_id = ? and inspect_date < ? and project_id =? and status=1 and org_id= ?", patientid, date, projectid, orgid).Limit(1).Find(&inspection).Error
|
324
|
return inspection, err
|
310
|
return inspection, err
|
|
|
|
|
326
|
}
|
312
|
}
|
327
|
|
313
|
|
328
|
func GetNextInspection(patientid int64, date int64, projectid int64, orgid int64) (models.Inspection, error) {
|
314
|
func GetNextInspection(patientid int64, date int64, projectid int64, orgid int64) (models.Inspection, error) {
|
329
|
-
|
|
|
330
|
inspection := models.Inspection{}
|
315
|
inspection := models.Inspection{}
|
331
|
err := XTReadDB().Group("inspect_date").Order("inspect_date asc").Where("patient_id = ? and inspect_date > ? and project_id =? and status=1 and org_id= ?", patientid, date, projectid, orgid).Limit(1).Find(&inspection).Error
|
316
|
err := XTReadDB().Group("inspect_date").Order("inspect_date asc").Where("patient_id = ? and inspect_date > ? and project_id =? and status=1 and org_id= ?", patientid, date, projectid, orgid).Limit(1).Find(&inspection).Error
|
332
|
return inspection, err
|
317
|
return inspection, err
|
333
|
}
|
318
|
}
|
334
|
|
319
|
|
335
|
func GetLastInspectionDetail(patientid int64, date int64, projectid int64, orgid int64) (inspection []*models.Inspections, err error) {
|
320
|
func GetLastInspectionDetail(patientid int64, date int64, projectid int64, orgid int64) (inspection []*models.Inspections, err error) {
|
336
|
-
|
|
|
337
|
db := XTReadDB().Table("xt_inspection as x").Where("x.status =1")
|
321
|
db := XTReadDB().Table("xt_inspection as x").Where("x.status =1")
|
338
|
- table := XTReadDB().Table("xt_inspection_reference as r")
|
|
|
339
|
- fmt.Print("table", table)
|
|
|
340
|
if patientid > 0 {
|
322
|
if patientid > 0 {
|
341
|
db = db.Where("x.patient_id = ?", patientid)
|
323
|
db = db.Where("x.patient_id = ?", patientid)
|
342
|
}
|
324
|
}
|
343
|
-
|
|
|
344
|
if date > 0 {
|
325
|
if date > 0 {
|
345
|
db = db.Where("x.inspect_date = ?", date)
|
326
|
db = db.Where("x.inspect_date = ?", date)
|
346
|
}
|
327
|
}
|
347
|
if orgid > 0 {
|
328
|
if orgid > 0 {
|
348
|
-
|
|
|
349
|
db = db.Where("x.org_id = ?", orgid)
|
329
|
db = db.Where("x.org_id = ?", orgid)
|
350
|
-
|
|
|
351
|
}
|
330
|
}
|
352
|
if projectid > 0 {
|
331
|
if projectid > 0 {
|
353
|
db = db.Where("x.project_id = ?", projectid)
|
332
|
db = db.Where("x.project_id = ?", projectid)
|
|
|
|
|
355
|
err = db.Order("inspect_date asc").Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id = x.org_id) OR ( x.item_id = r.id AND r.org_id = 0) ").Scan(&inspection).Error
|
334
|
err = db.Order("inspect_date asc").Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id = x.org_id) OR ( x.item_id = r.id AND r.org_id = 0) ").Scan(&inspection).Error
|
356
|
return inspection, err
|
335
|
return inspection, err
|
357
|
}
|
336
|
}
|
|
|
337
|
+
|
|
|
338
|
+func GetInsepctionConfigurationList(orgid int64) (standard []*models.QualityControlStandard, err error) {
|
|
|
339
|
+ db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
|
|
|
340
|
+ db = db.Where("x.user_org_id = ? and x.is_status =1", orgid)
|
|
|
341
|
+ err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,x.range_value,x.range_type,s.unit,s.project_name,s.item_name,x.is_status").
|
|
|
342
|
+ Joins("left join xt_inspection_reference as s on s.item_id = x.inspection_minor and s.project_id = x.inspection_major").Where("s.org_id = ? and s.status = 1", orgid).Scan(&standard).Error
|
|
|
343
|
+ return standard, err
|
|
|
344
|
+}
|