|
@@ -1271,6 +1271,16 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1271
|
1271
|
return
|
1272
|
1272
|
} else if origin == 2 {
|
1273
|
1273
|
|
|
1274
|
+ // 开始主事务
|
|
1275
|
+ db := service.XTWriteDB()
|
|
1276
|
+ tx := db.Begin()
|
|
1277
|
+
|
|
1278
|
+ // 在函数结束时处理事务回滚
|
|
1279
|
+ defer func() {
|
|
1280
|
+ if r := recover(); r != nil {
|
|
1281
|
+ tx.Rollback()
|
|
1282
|
+ }
|
|
1283
|
+ }()
|
1274
|
1284
|
adminInfo := c.GetMobileAdminUserInfo()
|
1275
|
1285
|
creater := c.GetMobileAdminUserInfo().AdminUser.Id
|
1276
|
1286
|
var ids []string
|
|
@@ -1337,7 +1347,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1337
|
1347
|
|
1338
|
1348
|
}
|
1339
|
1349
|
}
|
1340
|
|
- err = service.SaveHisDoctorAdvice(item)
|
|
1350
|
+
|
|
1351
|
+ //err = service.SaveHisDoctorAdvice(item)
|
|
1352
|
+
|
|
1353
|
+ service.SaveHisDoctorAdviceOne(item, tx)
|
1341
|
1354
|
|
1342
|
1355
|
//记录日志
|
1343
|
1356
|
byterequest, _ := json.Marshal(item)
|
|
@@ -1397,14 +1410,14 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1397
|
1410
|
if drugStockConfig.IsOpen == 1 {
|
1398
|
1411
|
for _, item := range advices {
|
1399
|
1412
|
//查询改药品信息
|
1400
|
|
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
|
|
1413
|
+ medical, _ := service.GetBaseDrugMedicalOne(item.DrugId, tx)
|
1401
|
1414
|
|
1402
|
1415
|
//判断单位是否合格
|
1403
|
1416
|
if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
|
1404
|
1417
|
//查询该药品是否有出库记录
|
1405
|
|
- flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
|
|
1418
|
+ flowMap, _ := service.GetDrugFLowByAdviceByIdOne(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate, tx)
|
1406
|
1419
|
if len(flowMap) == 0 {
|
1407
|
|
- errs := service.UpdateHisAdviceById(item.ID)
|
|
1420
|
+ errs := service.UpdateHisAdviceByIdOne(item.ID, tx)
|
1408
|
1421
|
if errs != nil {
|
1409
|
1422
|
drugError := models.XtDrugError{
|
1410
|
1423
|
UserOrgId: adminInfo.Org.Id,
|
|
@@ -1422,7 +1435,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1422
|
1435
|
service.CreateDrugError(drugError)
|
1423
|
1436
|
}
|
1424
|
1437
|
}
|
1425
|
|
- advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
|
|
1438
|
+ advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
|
|
1439
|
+ tx.Commit()
|
1426
|
1440
|
c.ServeSuccessJSON(map[string]interface{}{
|
1427
|
1441
|
"msg": "7",
|
1428
|
1442
|
"advice": advice,
|
|
@@ -1432,8 +1446,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1432
|
1446
|
}
|
1433
|
1447
|
|
1434
|
1448
|
//查询这个患者这个患者这个药已经出库的所有数量
|
1435
|
|
- advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
|
1436
|
|
- drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
|
|
1449
|
+ advicelist, _ := service.GetAllHisDoctorAdviceByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
|
|
1450
|
+ drugoutlist, _ := service.GetAllDrugFlowByIdOne(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId, tx)
|
1437
|
1451
|
var total_count int64
|
1438
|
1452
|
var drug_count int64
|
1439
|
1453
|
for _, it := range advicelist {
|
|
@@ -1460,8 +1474,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1460
|
1474
|
}
|
1461
|
1475
|
|
1462
|
1476
|
if total_count == drug_count {
|
1463
|
|
-
|
1464
|
|
- advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
|
|
1477
|
+ advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
|
|
1478
|
+ tx.Commit()
|
1465
|
1479
|
c.ServeSuccessJSON(map[string]interface{}{
|
1466
|
1480
|
"msg": "1",
|
1467
|
1481
|
"advice": advice,
|
|
@@ -1470,7 +1484,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1470
|
1484
|
return
|
1471
|
1485
|
}
|
1472
|
1486
|
|
1473
|
|
- advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
|
|
1487
|
+ advice, _ := service.FindHisDoctorAdviceByIdTwo(adminInfo.Org.Id, item.ID, tx)
|
1474
|
1488
|
|
1475
|
1489
|
var total int64
|
1476
|
1490
|
var prescribing_number_total int64
|
|
@@ -1480,7 +1494,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1480
|
1494
|
if config.IsOpen != 1 {
|
1481
|
1495
|
//查询该药品是否有库存
|
1482
|
1496
|
houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
|
1483
|
|
- list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
|
|
1497
|
+ list, _ := service.GetDrugTotalCountTwoTwety(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut, tx)
|
1484
|
1498
|
|
1485
|
1499
|
//判断单位是否相等
|
1486
|
1500
|
if medical.MaxUnit == advice.PrescribingNumberUnit {
|
|
@@ -1540,6 +1554,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1540
|
1554
|
PrescribingNumberUnit: advice.PrescribingNumberUnit,
|
1541
|
1555
|
}
|
1542
|
1556
|
service.CreateDrugError(drugError)
|
|
1557
|
+ tx.Commit()
|
1543
|
1558
|
c.ServeSuccessJSON(map[string]interface{}{
|
1544
|
1559
|
"msg": "3",
|
1545
|
1560
|
"advice": advice,
|
|
@@ -1562,6 +1577,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1562
|
1577
|
PrescribingNumberUnit: advice.PrescribingNumberUnit,
|
1563
|
1578
|
}
|
1564
|
1579
|
service.CreateDrugError(drugError)
|
|
1580
|
+ tx.Commit()
|
1565
|
1581
|
c.ServeSuccessJSON(map[string]interface{}{
|
1566
|
1582
|
"msg": "2",
|
1567
|
1583
|
"advice": advice,
|
|
@@ -1571,6 +1587,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1571
|
1587
|
}
|
1572
|
1588
|
}
|
1573
|
1589
|
|
|
1590
|
+ fmt.Println("hhahhahahahhhhhha", prescribing_number_total)
|
|
1591
|
+ fmt.Println("total0000000000000", total)
|
|
1592
|
+ fmt.Println("medical22222222222222", medical.IsUse)
|
|
1593
|
+ fmt.Println("config.isp", config.IsOpen)
|
1574
|
1594
|
if prescribing_number_total <= total {
|
1575
|
1595
|
|
1576
|
1596
|
pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
|
|
@@ -1579,13 +1599,15 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1579
|
1599
|
|
1580
|
1600
|
if config.IsOpen != 1 {
|
1581
|
1601
|
if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
|
1582
|
|
- service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
|
|
1602
|
+
|
|
1603
|
+ //service.NewHisDrugsDelivery(adminInfo.Org.Id, creater, &advice, tx)
|
|
1604
|
+ //service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
|
1583
|
1605
|
|
1584
|
1606
|
if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
|
1585
|
1607
|
//查询该药品是否有出库记录
|
1586
|
|
- flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
|
|
1608
|
+ flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
|
1587
|
1609
|
if len(flowMap) == 0 {
|
1588
|
|
- errs := service.UpdateHisAdviceById(advice.ID)
|
|
1610
|
+ errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
|
1589
|
1611
|
if errs != nil {
|
1590
|
1612
|
drugError := models.XtDrugError{
|
1591
|
1613
|
UserOrgId: adminInfo.Org.Id,
|
|
@@ -1602,6 +1624,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1602
|
1624
|
}
|
1603
|
1625
|
service.CreateDrugError(drugError)
|
1604
|
1626
|
}
|
|
1627
|
+ tx.Commit()
|
1605
|
1628
|
c.ServeSuccessJSON(map[string]interface{}{
|
1606
|
1629
|
"msg": "6",
|
1607
|
1630
|
"advice": advice,
|
|
@@ -1613,14 +1636,15 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1613
|
1636
|
}
|
1614
|
1637
|
if pharmacyConfig.IsOpen != 1 {
|
1615
|
1638
|
|
1616
|
|
- service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
|
|
1639
|
+ //service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
|
|
1640
|
+ service.NewHisDrugsDelivery(adminInfo.Org.Id, creater, &advice, tx)
|
1617
|
1641
|
if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
|
1618
|
1642
|
//查询该药品是否有出库记录
|
1619
|
|
- flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
|
|
1643
|
+ flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
|
1620
|
1644
|
|
1621
|
1645
|
if len(flowMap) == 0 {
|
1622
|
1646
|
|
1623
|
|
- errs := service.UpdateHisAdviceById(advice.ID)
|
|
1647
|
+ errs := service.UpdateHisAdviceByIdOne(advice.ID, tx)
|
1624
|
1648
|
if errs != nil {
|
1625
|
1649
|
drugError := models.XtDrugError{
|
1626
|
1650
|
UserOrgId: adminInfo.Org.Id,
|
|
@@ -1637,18 +1661,20 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1637
|
1661
|
}
|
1638
|
1662
|
service.CreateDrugError(drugError)
|
1639
|
1663
|
}
|
|
1664
|
+ tx.Commit()
|
1640
|
1665
|
c.ServeSuccessJSON(map[string]interface{}{
|
1641
|
1666
|
"msg": "6",
|
1642
|
1667
|
"advice": advice,
|
1643
|
1668
|
"ids": ids,
|
1644
|
1669
|
})
|
|
1670
|
+
|
1645
|
1671
|
return
|
1646
|
1672
|
}
|
1647
|
1673
|
}
|
1648
|
1674
|
}
|
1649
|
1675
|
|
1650
|
1676
|
//更新字典里面的库存
|
1651
|
|
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
|
|
1677
|
+ stockInfo, _ := service.GetNewDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
|
1652
|
1678
|
var sum_count int64
|
1653
|
1679
|
for _, its := range stockInfo {
|
1654
|
1680
|
if its.MaxUnit == medical.MaxUnit {
|
|
@@ -1656,9 +1682,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1656
|
1682
|
}
|
1657
|
1683
|
sum_count += its.StockMaxNumber + its.StockMinNumber
|
1658
|
1684
|
}
|
1659
|
|
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
|
|
1685
|
+ service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
|
1660
|
1686
|
//剩余库存
|
1661
|
|
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
|
|
1687
|
+ service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count, tx)
|
|
1688
|
+
|
1662
|
1689
|
}
|
1663
|
1690
|
|
1664
|
1691
|
}
|
|
@@ -1687,8 +1714,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
1687
|
1714
|
|
1688
|
1715
|
}
|
1689
|
1716
|
}
|
|
1717
|
+ tx.Commit()
|
1690
|
1718
|
for _, item := range advices {
|
1691
|
1719
|
advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
|
|
1720
|
+
|
1692
|
1721
|
c.ServeSuccessJSON(map[string]interface{}{
|
1693
|
1722
|
"msg": "1",
|
1694
|
1723
|
"advice": advice,
|