|
@@ -8,12 +8,17 @@ import (
|
8
|
8
|
"XT_New/utils"
|
9
|
9
|
"bytes"
|
10
|
10
|
"encoding/json"
|
|
11
|
+ "fmt"
|
11
|
12
|
"github.com/astaxie/beego"
|
|
13
|
+ "io/ioutil"
|
12
|
14
|
"log"
|
|
15
|
+ "net/http"
|
|
16
|
+ "net/url"
|
13
|
17
|
"os"
|
14
|
18
|
"path"
|
15
|
19
|
"regexp"
|
16
|
20
|
"runtime"
|
|
21
|
+ "strconv"
|
17
|
22
|
"time"
|
18
|
23
|
)
|
19
|
24
|
|
|
@@ -198,7 +203,7 @@ func (this *MobileRegistController) CreateOrg() {
|
198
|
203
|
|
199
|
204
|
orgType := service.GetOrgTypeByName(org_type)
|
200
|
205
|
|
201
|
|
- org := models.Org{
|
|
206
|
+ org := &models.Org{
|
202
|
207
|
Creator: adminUser.Id,
|
203
|
208
|
OrgName: name,
|
204
|
209
|
OrgShortName: shortName,
|
|
@@ -216,17 +221,294 @@ func (this *MobileRegistController) CreateOrg() {
|
216
|
221
|
ModifyTime: time.Now().Unix(),
|
217
|
222
|
}
|
218
|
223
|
|
219
|
|
- createErr := service.CreateOrg(&org, adminUser.Mobile, openXT, openCDM, openSCRM, openMall)
|
220
|
|
- var ids []int64
|
|
224
|
+ createErr := service.CreateOrg(org, adminUser.Mobile, openXT, openCDM, openSCRM, openMall)
|
|
225
|
+
|
|
226
|
+ if createErr != nil {
|
|
227
|
+ utils.ErrorLog("mobile=%v的超级管理员创建机构失败:%v", adminUser.Mobile, createErr)
|
|
228
|
+ this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
|
|
229
|
+ this.ServeJSON()
|
|
230
|
+ } else {
|
221
|
231
|
|
|
232
|
+
|
|
233
|
+ InitPatientAndSchedule(org)
|
|
234
|
+
|
|
235
|
+ InitSystemPrescrption(org)
|
|
236
|
+
|
|
237
|
+ InitAdviceTemplate(org)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+ ip := utils.GetIP(this.Ctx.Request)
|
|
246
|
+ ssoDomain := beego.AppConfig.String("sso_domain")
|
|
247
|
+ api := ssoDomain + "/m/login/pwd"
|
|
248
|
+ values := make(url.Values)
|
|
249
|
+ values.Set("mobile", adminUser.Mobile)
|
|
250
|
+ values.Set("password", adminUser.Password)
|
|
251
|
+ values.Set("app_type", "3")
|
|
252
|
+ values.Set("ip", ip)
|
|
253
|
+ resp, requestErr := http.PostForm(api, values)
|
|
254
|
+
|
|
255
|
+ if requestErr != nil {
|
|
256
|
+ utils.ErrorLog("请求SSO登录接口失败: %v", requestErr)
|
|
257
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
258
|
+ return
|
|
259
|
+ }
|
|
260
|
+ defer resp.Body.Close()
|
|
261
|
+ body, ioErr := ioutil.ReadAll(resp.Body)
|
|
262
|
+ if ioErr != nil {
|
|
263
|
+ utils.ErrorLog("SSO登录接口返回数据读取失败: %v", ioErr)
|
|
264
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
265
|
+ return
|
|
266
|
+ }
|
|
267
|
+ var respJSON map[string]interface{}
|
|
268
|
+ utils.InfoLog(string(body))
|
|
269
|
+ if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
|
|
270
|
+ utils.ErrorLog("SSO登录接口返回数据解析JSON失败: %v", err)
|
|
271
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
272
|
+ return
|
|
273
|
+ }
|
|
274
|
+
|
|
275
|
+ if respJSON["state"].(float64) != 1 {
|
|
276
|
+ msg := respJSON["msg"].(string)
|
|
277
|
+ utils.ErrorLog("SSO登录接口请求失败: %v", msg)
|
|
278
|
+ if int(respJSON["code"].(float64)) == 609 {
|
|
279
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
|
|
280
|
+ return
|
|
281
|
+ }
|
|
282
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
283
|
+ return
|
|
284
|
+ } else {
|
|
285
|
+ utils.SuccessLog("SSO登录成功")
|
|
286
|
+
|
|
287
|
+ userJSON := respJSON["data"].(map[string]interface{})["admin"].(map[string]interface{})
|
|
288
|
+ userJSONBytes, _ := json.Marshal(userJSON)
|
|
289
|
+ var adminUser models.AdminUser
|
|
290
|
+ if err := json.Unmarshal(userJSONBytes, &adminUser); err != nil {
|
|
291
|
+ utils.ErrorLog("解析管理员失败:%v", err)
|
|
292
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
293
|
+ return
|
|
294
|
+ }
|
|
295
|
+
|
|
296
|
+ var org models.Org
|
|
297
|
+ if respJSON["data"].(map[string]interface{})["org"] != nil {
|
|
298
|
+ orgJSON := respJSON["data"].(map[string]interface{})["org"].(map[string]interface{})
|
|
299
|
+ orgJSONBytes, _ := json.Marshal(orgJSON)
|
|
300
|
+ if err := json.Unmarshal(orgJSONBytes, &org); err != nil {
|
|
301
|
+ utils.ErrorLog("解析机构失败:%v", err)
|
|
302
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
303
|
+ return
|
|
304
|
+ }
|
|
305
|
+ }
|
|
306
|
+
|
|
307
|
+ var app models.OrgApp
|
|
308
|
+
|
|
309
|
+ if respJSON["data"].(map[string]interface{})["app"] != nil {
|
|
310
|
+ appJSON := respJSON["data"].(map[string]interface{})["app"].(map[string]interface{})
|
|
311
|
+ appJSONBytes, _ := json.Marshal(appJSON)
|
|
312
|
+ if err := json.Unmarshal(appJSONBytes, &app); err != nil {
|
|
313
|
+ utils.ErrorLog("解析应用失败:%v", err)
|
|
314
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
315
|
+ return
|
|
316
|
+ }
|
|
317
|
+ }
|
|
318
|
+
|
|
319
|
+ var appRole models.App_Role
|
|
320
|
+
|
|
321
|
+ if respJSON["data"].(map[string]interface{})["app_role"] != nil {
|
|
322
|
+ appRoleJSON := respJSON["data"].(map[string]interface{})["app_role"].(map[string]interface{})
|
|
323
|
+ appRoleJSONBytes, _ := json.Marshal(appRoleJSON)
|
|
324
|
+ if err := json.Unmarshal(appRoleJSONBytes, &appRole); err != nil {
|
|
325
|
+ utils.ErrorLog("解析AppRole失败:%v", err)
|
|
326
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
327
|
+ return
|
|
328
|
+ }
|
|
329
|
+ }
|
|
330
|
+
|
|
331
|
+ var subscibe models.ServeSubscibe
|
|
332
|
+ if respJSON["data"].(map[string]interface{})["subscibe"] != nil {
|
|
333
|
+ subscibeJSON := respJSON["data"].(map[string]interface{})["subscibe"].(map[string]interface{})
|
|
334
|
+ subscibeJSONBytes, _ := json.Marshal(subscibeJSON)
|
|
335
|
+ if err := json.Unmarshal(subscibeJSONBytes, &subscibe); err != nil {
|
|
336
|
+ utils.ErrorLog("解析Subscibe失败:%v", err)
|
|
337
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
338
|
+ return
|
|
339
|
+ }
|
|
340
|
+
|
|
341
|
+ }
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+ templateInfo, _ := service.GetOrgInfoTemplate(org.Id)
|
|
345
|
+
|
|
346
|
+ mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
|
|
347
|
+ AdminUser: &adminUser,
|
|
348
|
+ Org: &org,
|
|
349
|
+ App: &app,
|
|
350
|
+ AppRole: &appRole,
|
|
351
|
+ Subscibe: &subscibe,
|
|
352
|
+ TemplateInfo: &templateInfo,
|
|
353
|
+ }
|
|
354
|
+
|
|
355
|
+ this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+ mobile := adminUser.Mobile + "-" + strconv.FormatInt(org.Id, 10) + "-" + strconv.FormatInt(appRole.Id, 10)
|
|
359
|
+ token := utils.GenerateLoginToken(mobile)
|
|
360
|
+ expiration, _ := beego.AppConfig.Int64("mobile_token_expiration_second")
|
|
361
|
+ this.Ctx.SetCookie("token_cookie", token, expiration, "/")
|
|
362
|
+
|
|
363
|
+ var configList interface{}
|
|
364
|
+ var FiledList []*models.FiledConfig
|
|
365
|
+
|
|
366
|
+ if org.Id > 0 {
|
|
367
|
+ configList, _ = service.GetConfigList(org.Id)
|
|
368
|
+ FiledList, _ = service.FindFiledByOrgId(org.Id)
|
|
369
|
+ }
|
|
370
|
+ if len(FiledList) == 0 {
|
|
371
|
+ var err error
|
|
372
|
+ if org.Id > 0 {
|
|
373
|
+ err = service.BatchInsertFiledConfig(org.Id)
|
|
374
|
+ if err == nil {
|
|
375
|
+ FiledList, _ = service.FindFiledByOrgId(org.Id)
|
|
376
|
+ } else {
|
|
377
|
+ utils.ErrorLog("字段批量插入失败:%v", err)
|
|
378
|
+ }
|
|
379
|
+ } else {
|
|
380
|
+ FiledList = make([]*models.FiledConfig, 0)
|
|
381
|
+ }
|
|
382
|
+ }
|
|
383
|
+
|
|
384
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
385
|
+ "admin": adminUser,
|
|
386
|
+ "user": appRole,
|
|
387
|
+ "org": org,
|
|
388
|
+ "template_info": map[string]interface{}{
|
|
389
|
+ "id": templateInfo.ID,
|
|
390
|
+ "org_id": templateInfo.OrgId,
|
|
391
|
+ "template_id": templateInfo.TemplateId,
|
|
392
|
+ },
|
|
393
|
+ "config_list": configList,
|
|
394
|
+ "filed_list": FiledList,
|
|
395
|
+ })
|
|
396
|
+ }
|
|
397
|
+
|
|
398
|
+ }
|
|
399
|
+
|
|
400
|
+}
|
|
401
|
+
|
|
402
|
+func InitAdviceTemplate(org *models.Org) {
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+ adviceInit := &models.AdviceInit{
|
|
406
|
+ UserOrgId: org.Id,
|
|
407
|
+ CreateTime: time.Now().Unix(),
|
|
408
|
+ UpdateTime: time.Now().Unix(),
|
|
409
|
+ Status: 1,
|
|
410
|
+ IsInit: 1,
|
|
411
|
+ }
|
|
412
|
+
|
|
413
|
+ adviceParentTemplate := LoadConfig("./advice_template.json").Parent_template
|
|
414
|
+ for _, item := range adviceParentTemplate {
|
|
415
|
+ parentTemplate := &models.DoctorAdviceParentTemplate{
|
|
416
|
+ OrgId: org.Id,
|
|
417
|
+ Name: item.Name,
|
|
418
|
+ Status: 1,
|
|
419
|
+ CreatedTime: time.Now().Unix(),
|
|
420
|
+ UpdatedTime: time.Now().Unix(),
|
|
421
|
+ AdviceType: item.AdviceType,
|
|
422
|
+ }
|
|
423
|
+
|
|
424
|
+ createErr := service.CreateDoctorParentTemplate(parentTemplate)
|
|
425
|
+ fmt.Println(parentTemplate.ID)
|
|
426
|
+ if createErr == nil {
|
|
427
|
+ for _, adviceTemplateItem := range item.DoctorAdviceTemplate {
|
|
428
|
+ adviceTeplate := &models.DoctorAdviceTemplate{
|
|
429
|
+ OrgId: org.Id,
|
|
430
|
+ AdviceName: adviceTemplateItem.AdviceName,
|
|
431
|
+ AdviceDesc: adviceTemplateItem.AdviceDesc,
|
|
432
|
+ SingleDose: adviceTemplateItem.SingleDose,
|
|
433
|
+ SingleDoseUnit: adviceTemplateItem.SingleDoseUnit,
|
|
434
|
+ PrescribingNumber: adviceTemplateItem.PrescribingNumber,
|
|
435
|
+ PrescribingNumberUnit: adviceTemplateItem.PrescribingNumberUnit,
|
|
436
|
+ DeliveryWay: adviceTemplateItem.DeliveryWay,
|
|
437
|
+ ExecutionFrequency: adviceTemplateItem.ExecutionFrequency,
|
|
438
|
+ AdviceDoctor: adviceTemplateItem.AdviceDoctor,
|
|
439
|
+ Status: 1,
|
|
440
|
+ CreatedTime: time.Now().Unix(),
|
|
441
|
+ UpdatedTime: time.Now().Unix(),
|
|
442
|
+ TemplateId: parentTemplate.ID,
|
|
443
|
+ DrugSpec: adviceTemplateItem.DrugSpec,
|
|
444
|
+ DrugSpecUnit: adviceTemplateItem.DrugSpecUnit,
|
|
445
|
+ ParentId: adviceTemplateItem.ParentId,
|
|
446
|
+ AdviceType: adviceTemplateItem.AdviceType,
|
|
447
|
+ DayCount: adviceTemplateItem.DayCount,
|
|
448
|
+ WeekDays: adviceTemplateItem.WeekDays,
|
|
449
|
+ FrequencyType: adviceTemplateItem.FrequencyType,
|
|
450
|
+ }
|
|
451
|
+ createErr := service.CreateDoctorTemplate(adviceTeplate)
|
|
452
|
+
|
|
453
|
+ if createErr == nil {
|
|
454
|
+ for _, childItem := range adviceTemplateItem.SubDoctorAdviceTemplate {
|
|
455
|
+ adviceTeplate := &models.DoctorAdviceTemplate{
|
|
456
|
+ OrgId: org.Id,
|
|
457
|
+ AdviceName: childItem.AdviceName,
|
|
458
|
+ AdviceDesc: childItem.AdviceDesc,
|
|
459
|
+ SingleDose: childItem.SingleDose,
|
|
460
|
+ SingleDoseUnit: childItem.SingleDoseUnit,
|
|
461
|
+ PrescribingNumber: childItem.PrescribingNumber,
|
|
462
|
+ PrescribingNumberUnit: childItem.PrescribingNumberUnit,
|
|
463
|
+ DeliveryWay: childItem.DeliveryWay,
|
|
464
|
+ ExecutionFrequency: childItem.ExecutionFrequency,
|
|
465
|
+ AdviceDoctor: childItem.AdviceDoctor,
|
|
466
|
+ Status: 1,
|
|
467
|
+ CreatedTime: time.Now().Unix(),
|
|
468
|
+ UpdatedTime: time.Now().Unix(),
|
|
469
|
+ TemplateId: parentTemplate.ID,
|
|
470
|
+ DrugSpec: childItem.DrugSpec,
|
|
471
|
+ DrugSpecUnit: childItem.DrugSpecUnit,
|
|
472
|
+ ParentId: adviceTeplate.ID,
|
|
473
|
+ AdviceType: childItem.AdviceType,
|
|
474
|
+ DayCount: childItem.DayCount,
|
|
475
|
+ WeekDays: childItem.WeekDays,
|
|
476
|
+ FrequencyType: childItem.FrequencyType,
|
|
477
|
+ }
|
|
478
|
+ service.CreateDoctorTemplate(adviceTeplate)
|
|
479
|
+ }
|
|
480
|
+ }
|
|
481
|
+ }
|
|
482
|
+ }
|
|
483
|
+ }
|
|
484
|
+ service.CreateAdviceInitConfig(adviceInit)
|
|
485
|
+
|
|
486
|
+}
|
|
487
|
+
|
|
488
|
+func InitSystemPrescrption(org *models.Org) {
|
|
489
|
+
|
|
490
|
+ prescriptions := LoadPrescriptionConfig("./system_dialysis_prescription.json").Prescription
|
|
491
|
+ for _, item := range prescriptions {
|
|
492
|
+ item.UserOrgId = org.Id
|
|
493
|
+ item.CreatedTime = time.Now().Unix()
|
|
494
|
+ item.UpdatedTime = time.Now().Unix()
|
|
495
|
+ service.CreateVMPrescription(item)
|
|
496
|
+ }
|
|
497
|
+
|
|
498
|
+}
|
|
499
|
+
|
|
500
|
+func InitPatientAndSchedule(org *models.Org) {
|
|
501
|
+ var ids []int64
|
222
|
502
|
|
|
503
|
+
|
223
|
504
|
|
224
|
|
- patients := LoadConfig("./patient.json").patients
|
|
505
|
+ patients := LoadPatientConfig("./patient.json").Patients
|
225
|
506
|
for _, item := range patients {
|
226
|
507
|
item.UserOrgId = org.Id
|
227
|
508
|
item.CreatedTime = time.Now().Unix()
|
228
|
509
|
item.UpdatedTime = time.Now().Unix()
|
229
|
510
|
item.Status = 1
|
|
511
|
+
|
230
|
512
|
service.CreateVMOrgPatient(item)
|
231
|
513
|
ids = append(ids, item.ID)
|
232
|
514
|
}
|
|
@@ -234,7 +516,7 @@ func (this *MobileRegistController) CreateOrg() {
|
234
|
516
|
|
235
|
517
|
vmGroup := &models.VMDeviceGroup{
|
236
|
518
|
OrgId: org.Id,
|
237
|
|
- Name: "测试分组1",
|
|
519
|
+ Name: "护理一组",
|
238
|
520
|
Status: 1,
|
239
|
521
|
Ctime: time.Now().Unix(),
|
240
|
522
|
Mtime: time.Now().Unix(),
|
|
@@ -245,7 +527,7 @@ func (this *MobileRegistController) CreateOrg() {
|
245
|
527
|
|
246
|
528
|
vmZone1 := &models.VMDeviceZone{
|
247
|
529
|
OrgId: org.Id,
|
248
|
|
- Name: "分区1",
|
|
530
|
+ Name: "A区",
|
249
|
531
|
Type: 1,
|
250
|
532
|
Status: 1,
|
251
|
533
|
Ctime: time.Now().Unix(),
|
|
@@ -255,7 +537,7 @@ func (this *MobileRegistController) CreateOrg() {
|
255
|
537
|
|
256
|
538
|
vmZone2 := &models.VMDeviceZone{
|
257
|
539
|
OrgId: org.Id,
|
258
|
|
- Name: "分区2",
|
|
540
|
+ Name: "B区",
|
259
|
541
|
Type: 2,
|
260
|
542
|
Status: 1,
|
261
|
543
|
Ctime: time.Now().Unix(),
|
|
@@ -263,10 +545,10 @@ func (this *MobileRegistController) CreateOrg() {
|
263
|
545
|
}
|
264
|
546
|
service.CreateVMZone(vmZone2)
|
265
|
547
|
|
266
|
|
-
|
|
548
|
+
|
267
|
549
|
vmDeviceNumber1 := &models.VMDeviceNumber{
|
268
|
550
|
OrgId: org.Id,
|
269
|
|
- Number: "1",
|
|
551
|
+ Number: "1号床",
|
270
|
552
|
GroupId: vmGroup.ID,
|
271
|
553
|
ZoneId: vmZone1.ID,
|
272
|
554
|
Status: 1,
|
|
@@ -277,7 +559,7 @@ func (this *MobileRegistController) CreateOrg() {
|
277
|
559
|
|
278
|
560
|
vmDeviceNumber2 := &models.VMDeviceNumber{
|
279
|
561
|
OrgId: org.Id,
|
280
|
|
- Number: "2",
|
|
562
|
+ Number: "2号床",
|
281
|
563
|
GroupId: vmGroup.ID,
|
282
|
564
|
ZoneId: vmZone2.ID,
|
283
|
565
|
Status: 1,
|
|
@@ -286,53 +568,111 @@ func (this *MobileRegistController) CreateOrg() {
|
286
|
568
|
}
|
287
|
569
|
service.CreateVMDeviceNumber(vmDeviceNumber2)
|
288
|
570
|
|
289
|
|
-
|
290
|
|
- stime, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
|
291
|
|
- for index, id := range ids {
|
292
|
|
- if index == 0 {
|
293
|
|
- sch := &models.VMSchedule{
|
294
|
|
- UserOrgId: org.Id,
|
295
|
|
- PartitionId: vmZone1.ID,
|
296
|
|
- BedId: vmDeviceNumber1.ID,
|
297
|
|
- PatientId: id,
|
298
|
|
- ScheduleDate: stime.Unix(),
|
299
|
|
- ScheduleType: 1,
|
300
|
|
- ScheduleWeek: int64(time.Now().Weekday()),
|
301
|
|
- ModeId: 1,
|
302
|
|
- Status: 1,
|
303
|
|
- CreatedTime: time.Now().Unix(),
|
304
|
|
- UpdatedTime: time.Now().Unix(),
|
|
571
|
+ var dates []int64
|
|
572
|
+
|
|
573
|
+ mondayDate := GetDateOfWeek(1)
|
|
574
|
+ tuesdayDate := GetDateOfWeek(2)
|
|
575
|
+ wednesdayDate := GetDateOfWeek(3)
|
|
576
|
+ thursdayDate := GetDateOfWeek(4)
|
|
577
|
+ fridayDate := GetDateOfWeek(5)
|
|
578
|
+ saturdayDate := GetDateOfWeek(6)
|
|
579
|
+ sundayDate := GetDateOfWeek(7)
|
|
580
|
+
|
|
581
|
+ dates = append(dates, mondayDate)
|
|
582
|
+ dates = append(dates, tuesdayDate)
|
|
583
|
+ dates = append(dates, wednesdayDate)
|
|
584
|
+ dates = append(dates, thursdayDate)
|
|
585
|
+ dates = append(dates, fridayDate)
|
|
586
|
+ dates = append(dates, saturdayDate)
|
|
587
|
+ dates = append(dates, sundayDate)
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+ for _, date := range dates {
|
|
592
|
+ for index, id := range ids {
|
|
593
|
+ if index == 0 {
|
|
594
|
+ sch := &models.VMSchedule{
|
|
595
|
+ UserOrgId: org.Id,
|
|
596
|
+ PartitionId: vmZone1.ID,
|
|
597
|
+ BedId: vmDeviceNumber1.ID,
|
|
598
|
+ PatientId: id,
|
|
599
|
+ ScheduleDate: date,
|
|
600
|
+ ScheduleType: 1,
|
|
601
|
+ ScheduleWeek: int64(time.Now().Weekday()),
|
|
602
|
+ ModeId: 1,
|
|
603
|
+ Status: 1,
|
|
604
|
+ CreatedTime: time.Now().Unix(),
|
|
605
|
+ UpdatedTime: time.Now().Unix(),
|
|
606
|
+ }
|
|
607
|
+ service.CreateVMSch(sch)
|
305
|
608
|
}
|
306
|
|
- service.CreateVMSch(sch)
|
307
|
|
- }
|
308
|
609
|
|
309
|
|
- if index == 1 {
|
310
|
|
-
|
311
|
|
- sch := &models.VMSchedule{
|
312
|
|
- UserOrgId: org.Id,
|
313
|
|
- PartitionId: vmZone2.ID,
|
314
|
|
- BedId: vmDeviceNumber2.ID,
|
315
|
|
- PatientId: id,
|
316
|
|
- ScheduleDate: stime.Unix(),
|
317
|
|
- ScheduleType: 1,
|
318
|
|
- ScheduleWeek: int64(time.Now().Weekday()),
|
319
|
|
- ModeId: 1,
|
320
|
|
- Status: 1,
|
321
|
|
- CreatedTime: time.Now().Unix(),
|
322
|
|
- UpdatedTime: time.Now().Unix(),
|
|
610
|
+ if index == 1 {
|
|
611
|
+
|
|
612
|
+ sch := &models.VMSchedule{
|
|
613
|
+ UserOrgId: org.Id,
|
|
614
|
+ PartitionId: vmZone2.ID,
|
|
615
|
+ BedId: vmDeviceNumber2.ID,
|
|
616
|
+ PatientId: id,
|
|
617
|
+ ScheduleDate: date,
|
|
618
|
+ ScheduleType: 2,
|
|
619
|
+ ScheduleWeek: int64(time.Now().Weekday()),
|
|
620
|
+ ModeId: 1,
|
|
621
|
+ Status: 1,
|
|
622
|
+ CreatedTime: time.Now().Unix(),
|
|
623
|
+ UpdatedTime: time.Now().Unix(),
|
|
624
|
+ }
|
|
625
|
+ service.CreateVMSch(sch)
|
323
|
626
|
}
|
324
|
|
- service.CreateVMSch(sch)
|
325
|
627
|
}
|
|
628
|
+
|
326
|
629
|
}
|
327
|
630
|
|
328
|
|
- if createErr != nil {
|
329
|
|
- utils.ErrorLog("mobile=%v的超级管理员创建机构失败:%v", adminUser.Mobile, createErr)
|
330
|
|
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
|
331
|
|
- this.ServeJSON()
|
332
|
|
- } else {
|
333
|
|
- this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{})
|
334
|
|
- this.ServeJSON()
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+ mode := &models.VMPatientScheduleTemplateMode{
|
|
634
|
+ OrgId: org.Id,
|
|
635
|
+ Mode: 1,
|
|
636
|
+ ExecuteTimes: 0,
|
|
637
|
+ Status: 1,
|
|
638
|
+ Ctime: time.Now().Unix(),
|
|
639
|
+ Mtime: time.Now().Unix(),
|
|
640
|
+ }
|
|
641
|
+ service.CreateVMSchMode(mode)
|
|
642
|
+
|
|
643
|
+ templaeIdOne := &models.VMPatientScheduleTemplateId{
|
|
644
|
+ OrgId: org.Id,
|
|
645
|
+ Status: 1,
|
|
646
|
+ Ctime: time.Now().Unix(),
|
|
647
|
+ Mtime: time.Now().Unix(),
|
|
648
|
+ }
|
|
649
|
+ service.CreateVMSchTemplateId(templaeIdOne)
|
|
650
|
+ templaeIdTwo := &models.VMPatientScheduleTemplateId{
|
|
651
|
+ OrgId: org.Id,
|
|
652
|
+ Status: 1,
|
|
653
|
+ Ctime: time.Now().Unix(),
|
|
654
|
+ Mtime: time.Now().Unix(),
|
|
655
|
+ }
|
|
656
|
+ service.CreateVMSchTemplateId(templaeIdTwo)
|
|
657
|
+
|
|
658
|
+ items := LoadSchTemplateConfig("./schedule_template.json").ScheduleTemplateItem
|
|
659
|
+ for _, item := range items {
|
|
660
|
+ if item.TimeType == 1 {
|
|
661
|
+ item.OrgId = org.Id
|
|
662
|
+ item.TemplateId = templaeIdOne.ID
|
|
663
|
+ item.DeviceNumberId = vmDeviceNumber1.ID
|
|
664
|
+ item.PatientId = ids[0]
|
|
665
|
+
|
|
666
|
+ } else if item.TimeType == 2 {
|
|
667
|
+ item.OrgId = org.Id
|
|
668
|
+ item.TemplateId = templaeIdOne.ID
|
|
669
|
+ item.DeviceNumberId = vmDeviceNumber2.ID
|
|
670
|
+ item.PatientId = ids[1]
|
|
671
|
+ }
|
|
672
|
+
|
|
673
|
+ service.CreateVMSchTemplate(item)
|
335
|
674
|
}
|
|
675
|
+
|
336
|
676
|
}
|
337
|
677
|
|
338
|
678
|
func (this *MobileRegistController) ModifyName() {
|
|
@@ -394,12 +734,80 @@ func (this *MobileRegistController) Login() {
|
394
|
734
|
|
395
|
735
|
}
|
396
|
736
|
|
397
|
|
-type Config struct {
|
398
|
|
- patients []*models.VMOrgPatients "json:patients"
|
|
737
|
+type PatientConfig struct {
|
|
738
|
+ Patients []*models.VMOrgPatients "json:patients"
|
399
|
739
|
}
|
400
|
740
|
|
401
|
|
-func LoadConfig(dataFile string) *Config {
|
402
|
|
- var config Config
|
|
741
|
+type SchTemplateConfig struct {
|
|
742
|
+ ScheduleTemplateItem []*models.VMPatientScheduleTemplateItem "json:item"
|
|
743
|
+}
|
|
744
|
+
|
|
745
|
+type PrescriptionConfig struct {
|
|
746
|
+ Prescription []*models.SystemPrescription "json:prescription"
|
|
747
|
+}
|
|
748
|
+
|
|
749
|
+func LoadPatientConfig(dataFile string) *PatientConfig {
|
|
750
|
+ var config PatientConfig
|
|
751
|
+ _, filename, _, _ := runtime.Caller(1)
|
|
752
|
+ datapath := path.Join(path.Dir(filename), dataFile)
|
|
753
|
+ config_file, err := os.Open(datapath)
|
|
754
|
+ if err != nil {
|
|
755
|
+ emit("Failed to open config file '%s': %s\n", datapath, err)
|
|
756
|
+ return &config
|
|
757
|
+ }
|
|
758
|
+
|
|
759
|
+ fi, _ := config_file.Stat()
|
|
760
|
+
|
|
761
|
+ buffer := make([]byte, fi.Size())
|
|
762
|
+ _, err = config_file.Read(buffer)
|
|
763
|
+
|
|
764
|
+ buffer, err = StripComments(buffer)
|
|
765
|
+ if err != nil {
|
|
766
|
+ emit("Failed to strip comments from json: %s\n", err)
|
|
767
|
+ return &config
|
|
768
|
+ }
|
|
769
|
+
|
|
770
|
+ buffer = []byte(os.ExpandEnv(string(buffer)))
|
|
771
|
+ err = json.Unmarshal(buffer, &config)
|
|
772
|
+ if err != nil {
|
|
773
|
+ emit("Failed unmarshalling json: %s\n", err)
|
|
774
|
+ return &config
|
|
775
|
+ }
|
|
776
|
+ return &config
|
|
777
|
+}
|
|
778
|
+
|
|
779
|
+func LoadSchTemplateConfig(dataFile string) *SchTemplateConfig {
|
|
780
|
+ var config SchTemplateConfig
|
|
781
|
+ _, filename, _, _ := runtime.Caller(1)
|
|
782
|
+ datapath := path.Join(path.Dir(filename), dataFile)
|
|
783
|
+ config_file, err := os.Open(datapath)
|
|
784
|
+ if err != nil {
|
|
785
|
+ emit("Failed to open config file '%s': %s\n", datapath, err)
|
|
786
|
+ return &config
|
|
787
|
+ }
|
|
788
|
+
|
|
789
|
+ fi, _ := config_file.Stat()
|
|
790
|
+
|
|
791
|
+ buffer := make([]byte, fi.Size())
|
|
792
|
+ _, err = config_file.Read(buffer)
|
|
793
|
+
|
|
794
|
+ buffer, err = StripComments(buffer)
|
|
795
|
+ if err != nil {
|
|
796
|
+ emit("Failed to strip comments from json: %s\n", err)
|
|
797
|
+ return &config
|
|
798
|
+ }
|
|
799
|
+
|
|
800
|
+ buffer = []byte(os.ExpandEnv(string(buffer)))
|
|
801
|
+ err = json.Unmarshal(buffer, &config)
|
|
802
|
+ if err != nil {
|
|
803
|
+ emit("Failed unmarshalling json: %s\n", err)
|
|
804
|
+ return &config
|
|
805
|
+ }
|
|
806
|
+ return &config
|
|
807
|
+}
|
|
808
|
+
|
|
809
|
+func LoadPrescriptionConfig(dataFile string) *PrescriptionConfig {
|
|
810
|
+ var config PrescriptionConfig
|
403
|
811
|
_, filename, _, _ := runtime.Caller(1)
|
404
|
812
|
datapath := path.Join(path.Dir(filename), dataFile)
|
405
|
813
|
config_file, err := os.Open(datapath)
|
|
@@ -449,3 +857,89 @@ func StripComments(data []byte) ([]byte, error) {
|
449
|
857
|
|
450
|
858
|
return bytes.Join(filtered, []byte("\n")), nil
|
451
|
859
|
}
|
|
860
|
+
|
|
861
|
+func GetDateOfWeek(week_type int) (weekMonday int64) {
|
|
862
|
+ thisTime := time.Now()
|
|
863
|
+ weekDay := int(thisTime.Weekday())
|
|
864
|
+ if weekDay == 0 {
|
|
865
|
+ weekDay = 7
|
|
866
|
+ }
|
|
867
|
+ weekEnd := 7 - weekDay
|
|
868
|
+ weekStart := weekEnd - 6
|
|
869
|
+ weekTitle := make([]string, 0)
|
|
870
|
+ days := make([]string, 0)
|
|
871
|
+ for index := weekStart; index <= weekEnd; index++ {
|
|
872
|
+ theDay := thisTime.AddDate(0, 0, index)
|
|
873
|
+ indexYear, indexMonthTime, indexDay := theDay.Date()
|
|
874
|
+ indexMonth := int(indexMonthTime)
|
|
875
|
+ indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
|
|
876
|
+ weekTitle = append(weekTitle, indexWeek)
|
|
877
|
+ days = append(days, theDay.Format("2006-01-02"))
|
|
878
|
+ }
|
|
879
|
+ var targetDayStr string
|
|
880
|
+ switch week_type {
|
|
881
|
+ case 1:
|
|
882
|
+ targetDayStr = days[0]
|
|
883
|
+ break
|
|
884
|
+ case 2:
|
|
885
|
+ targetDayStr = days[1]
|
|
886
|
+
|
|
887
|
+ break
|
|
888
|
+ case 3:
|
|
889
|
+ targetDayStr = days[2]
|
|
890
|
+
|
|
891
|
+ break
|
|
892
|
+ case 4:
|
|
893
|
+ targetDayStr = days[3]
|
|
894
|
+
|
|
895
|
+ break
|
|
896
|
+ case 5:
|
|
897
|
+ targetDayStr = days[4]
|
|
898
|
+
|
|
899
|
+ break
|
|
900
|
+ case 6:
|
|
901
|
+ targetDayStr = days[5]
|
|
902
|
+
|
|
903
|
+ break
|
|
904
|
+ case 7:
|
|
905
|
+ targetDayStr = days[6]
|
|
906
|
+
|
|
907
|
+ break
|
|
908
|
+ }
|
|
909
|
+ targetDay, _ := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
|
|
910
|
+ return targetDay.Unix()
|
|
911
|
+}
|
|
912
|
+
|
|
913
|
+type Config struct {
|
|
914
|
+ Parent_template []*models.VMDoctorAdviceParentTemplate "json:parent_template"
|
|
915
|
+}
|
|
916
|
+
|
|
917
|
+func LoadConfig(dataFile string) *Config {
|
|
918
|
+ var config Config
|
|
919
|
+ _, filename, _, _ := runtime.Caller(1)
|
|
920
|
+ datapath := path.Join(path.Dir(filename), dataFile)
|
|
921
|
+ config_file, err := os.Open(datapath)
|
|
922
|
+ if err != nil {
|
|
923
|
+ emit("Failed to open config file '%s': %s\n", datapath, err)
|
|
924
|
+ return &config
|
|
925
|
+ }
|
|
926
|
+
|
|
927
|
+ fi, _ := config_file.Stat()
|
|
928
|
+
|
|
929
|
+ buffer := make([]byte, fi.Size())
|
|
930
|
+ _, err = config_file.Read(buffer)
|
|
931
|
+
|
|
932
|
+ buffer, err = StripComments(buffer)
|
|
933
|
+ if err != nil {
|
|
934
|
+ emit("Failed to strip comments from json: %s\n", err)
|
|
935
|
+ return &config
|
|
936
|
+ }
|
|
937
|
+
|
|
938
|
+ buffer = []byte(os.ExpandEnv(string(buffer)))
|
|
939
|
+ err = json.Unmarshal(buffer, &config)
|
|
940
|
+ if err != nil {
|
|
941
|
+ emit("Failed unmarshalling json: %s\n", err)
|
|
942
|
+ return &config
|
|
943
|
+ }
|
|
944
|
+ return &config
|
|
945
|
+}
|