陈少旭 2 miesięcy temu
rodzic
commit
ef7ebb2d34
1 zmienionych plików z 13 dodań i 26 usunięć
  1. 13 26
      service/inspection_service.go

+ 13 - 26
service/inspection_service.go Wyświetl plik

@@ -3,7 +3,6 @@ package service
3 3
 import (
4 4
 	"XT_New/models"
5 5
 	"errors"
6
-	"fmt"
7 6
 	"strings"
8 7
 	"time"
9 8
 )
@@ -17,9 +16,7 @@ func GetInspectionReference(orgId int64, inspect_type int64) (reference []*model
17 16
 		} else {
18 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 19
 	} else {
22
-
23 20
 		var count int
24 21
 		err = readDb.Model(&models.InspectionReference{}).Where("org_id=? and status=1 and inspection_type = ?", orgId, inspect_type).Count(&count).Error
25 22
 		if count > 0 {
@@ -27,9 +24,7 @@ func GetInspectionReference(orgId int64, inspect_type int64) (reference []*model
27 24
 		} else {
28 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 28
 	return
34 29
 }
35 30
 
@@ -44,7 +39,6 @@ func GetPatientInspectionByDate(orgId, patientId, date, projectId int64) (inspec
44 39
 }
45 40
 
46 41
 func GetAdvices(orgid int64, patientid int64, recorddate int64) (advcie []*models.DoctorAdvice, err error) {
47
-
48 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 43
 	return
50 44
 }
@@ -53,27 +47,21 @@ func GetAdvicesByPrescription(orgid int64, patientid int64, recorddate int64) (m
53 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 48
 	return advice, err
55 49
 }
56
-
57 50
 func UpdateDoctorAdvieById(id int64, prescription_number float64) (models.DoctorAdvice, error) {
58
-
59 51
 	advice := models.DoctorAdvice{}
60 52
 	err := XTWriteDB().Model(&advice).Where("id=? and status= 1", id).Updates(map[string]interface{}{"prescribing_number": prescription_number}).Error
61 53
 	return advice, err
62 54
 }
63
-
64 55
 func UpdateDoctorAdvieByIdOne(id int64, prescription_number float64, single_dose float64) (models.DoctorAdvice, error) {
65
-
66 56
 	advice := models.DoctorAdvice{}
67 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 58
 	return advice, err
69 59
 }
70
-
71 60
 func CreatePatientInspection(inspectins []models.Inspection) (err error) {
72 61
 	if len(inspectins) == 0 {
73 62
 		err = errors.New("Inspections Cant be nil.")
74 63
 		return
75 64
 	}
76
-
77 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 66
 	insertParams := make([]string, 0)
79 67
 	insertData := make([]interface{}, 0)
@@ -96,7 +84,6 @@ func CreatePatientInspection(inspectins []models.Inspection) (err error) {
96 84
 	err = writeDb.Exec(thisSQL, insertData...).Error
97 85
 	return
98 86
 }
99
-
100 87
 func SavePatientInspection(inspectin models.Inspection) (err error) {
101 88
 	err = writeDb.Save(&inspectin).Error
102 89
 	return
@@ -105,7 +92,6 @@ func DeleteInspectionTwo(id int64) {
105 92
 	err = writeDb.Model(&models.Inspection{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0}).Error
106 93
 	return
107 94
 }
108
-
109 95
 func EditPatientInspection(add []models.Inspection, edit []models.Inspection, noDeleteIDs []int64, patientId, orgId, projectId, date int64) (err error) {
110 96
 	if len(add) == 0 && len(edit) == 0 && len(noDeleteIDs) == 0 {
111 97
 		err = errors.New(" Cant be nil.")
@@ -168,19 +154,15 @@ func DeletePatientInspection(orgId, patientId, projectId, date int64) (err error
168 154
 }
169 155
 
170 156
 func GetPatientInspections(orgId, patientId, projectId, page int64) (inspections []*models.Inspection, total int64, date int64, err error) {
171
-
172 157
 	var projectCount models.UserInspectionProjectCount
173 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 159
 	if err != nil {
176 160
 		return
177 161
 	}
178
-
179 162
 	total = projectCount.Count
180 163
 	if total == 0 || page > total {
181 164
 		return
182 165
 	}
183
-
184 166
 	var Id models.InspectionDate
185 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 168
 	if err != nil {
@@ -291,6 +273,11 @@ func GetInspectionReferenceThree(project_id int64, item_id int64) (reference mod
291 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 281
 func GetInspectionTwo(startime int64, endtime int64, orgid int64, projectid int64, itemid int64) (inspection []*models.Inspection, total int64, err error) {
295 282
 	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
296 283
 	db = db.Where("project_id = ? and item_id = ?", projectid, itemid)
@@ -318,7 +305,6 @@ func GetAllInspectionRemind(org_id int64, patient_id int64) (check []models.XtCh
318 305
 }
319 306
 
320 307
 func GetLastInspection(patientid int64, date int64, projectid int64, orgid int64) (models.Inspection, error) {
321
-
322 308
 	inspection := models.Inspection{}
323 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 310
 	return inspection, err
@@ -326,28 +312,21 @@ func GetLastInspection(patientid int64, date int64, projectid int64, orgid int64
326 312
 }
327 313
 
328 314
 func GetNextInspection(patientid int64, date int64, projectid int64, orgid int64) (models.Inspection, error) {
329
-
330 315
 	inspection := models.Inspection{}
331 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 317
 	return inspection, err
333 318
 }
334 319
 
335 320
 func GetLastInspectionDetail(patientid int64, date int64, projectid int64, orgid int64) (inspection []*models.Inspections, err error) {
336
-
337 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 322
 	if patientid > 0 {
341 323
 		db = db.Where("x.patient_id = ?", patientid)
342 324
 	}
343
-
344 325
 	if date > 0 {
345 326
 		db = db.Where("x.inspect_date = ?", date)
346 327
 	}
347 328
 	if orgid > 0 {
348
-
349 329
 		db = db.Where("x.org_id = ?", orgid)
350
-
351 330
 	}
352 331
 	if projectid > 0 {
353 332
 		db = db.Where("x.project_id = ?", projectid)
@@ -355,3 +334,11 @@ func GetLastInspectionDetail(patientid int64, date int64, projectid int64, orgid
355 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 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
+}