База для ручки PostUserMedicationsExecutor.h

This commit is contained in:
2026-01-10 13:32:44 +03:00
parent a4d5384fd3
commit 8eb44b6e45
8 changed files with 119 additions and 48 deletions
+4 -1
View File
@@ -59,7 +59,10 @@ add_executable(App ./src/main.cpp
src/DAO/IMedicationsDAO.h
src/DAO/MySQLMedicationsDAO.h
src/DAO/MySQLMedicationsDAO.cpp
src/dtos/treatment_scheme_dto.h
src/dtos/user_treatment_scheme_dto.h
src/DAO/IUserTreatmentSchemesDAO.h
src/DAO/MySQLUserTreatmentSchemesDAO.cpp
src/DAO/MySQLUserTreatmentSchemesDAO.h
)
target_link_libraries(App PRIVATE Boost::boost
+3 -23
View File
@@ -193,27 +193,7 @@ null
"dream_level": 6,
"anxiety_level": 7,
"comment": "Накрыл психоз. Выпил одну таблетку аминазина"
"treatment_scheme": {
"uuid": "bf6d1555-39e9-4d73-8928-4763627f4dd5",
"treatment_name": "Bipolar I Scheme",
"instructions": "Контроль лития в крови раз в 2 месяца. Анализ крови через вену."
"medications": [
{
"uuid": "9bf2dfa9-3add-413c-9a0e-ff605088f1d5",
name: "Haloperidol",
dose: 10
unit: "mg",
"is_urgent": false
},
{
"uuid": "8af2dfa9-3add-413c-9a0e-ff605088f1d5",
"name": "Litii Carbonate",
"dose": 1800,
"unit": "mg",
"is_urgent": false
}
]
}
"treatment_scheme_uuid": bf6d1555-39e9-4d73-8928-4763627f4dd5
}
]
}
@@ -225,11 +205,11 @@ null
##### Response - 200 - OK
```
{
"treatment_schemes": [
"user_treatment_schemes": [
{
"uuid": "248313cb-a75e-4331-8379-d3f2fc36b68d"
"treatment_name": "Bipolar I Scheme Urgent",
"instructions": "Схема для бытрого и жесткого купирования психозов. Аминазин пить каждый день.",
"instructions": "Схема для быстрого и жесткого купирования психозов. Аминазин пить каждый день.",
"medications": [
{
"uuid": "eda5a5f7-167a-44b9-900d-c5c6acfc249b",
+10 -10
View File
@@ -1,11 +1,11 @@
-- Заполнение пользователями
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('ab555fcb-b9ee-45f4-9de8-8f16daa5d03c', 'login1', '56EED90A26203A6E');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('56b7c993-392f-41f8-adb1-9766842dc5fd', 'login2', '56EED90A26203A6E');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('a243b5f2-e265-4c25-82a9-dde4cc70643f', 'login3', '56EED90A26203A6E');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('51351bb1-7563-479d-a8e9-201d0ff934c2', 'login4', '56EED90A26203A6E');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b6', 'login5', '56EED90A26203A6E');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b7', 'login6', '56EED90A26203A6E');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b8', 'login7', '56EED90A26203A6E');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b9', 'login8', '56EED90A26203A6E');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b0', 'login9', '56EED90A26203A6E');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b1', 'login10', '56EED90A26203A6E');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('ab555fcb-b9ee-45f4-9de8-8f16daa5d03c', 'login1', '649111DF29DD8B55');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('56b7c993-392f-41f8-adb1-9766842dc5fd', 'login2', '649111DF29DD8B55');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('a243b5f2-e265-4c25-82a9-dde4cc70643f', 'login3', '649111DF29DD8B55');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('51351bb1-7563-479d-a8e9-201d0ff934c2', 'login4', '649111DF29DD8B55');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b6', 'login5', '649111DF29DD8B55');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b7', 'login6', '649111DF29DD8B55');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b8', 'login7', '649111DF29DD8B55');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b9', 'login8', '649111DF29DD8B55');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b0', 'login9', '649111DF29DD8B55');
INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES ('c792bbe6-2bf2-4fe0-a781-ba96bfeaa3b1', 'login10', '649111DF29DD8B55');
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include <vector>
#include <string>
#include "./../dtos/user_treatment_scheme_dto.h"
namespace uad
{
class IUserTreatmentSchemeDAO {
public:
virtual std::vector<user_treatment_scheme_dto> FindByUserLogin(const std::string& login) = 0;
virtual ~IUserTreatmentSchemeDAO() = default;
};
}
+66
View File
@@ -0,0 +1,66 @@
#include <mysqlx/xdevapi.h>
#include <unordered_map>
#include "MySQLUserTreatmentSchemesDAO.h"
namespace uad
{
MySQLUserTreatmentSchemesDAO::MySQLUserTreatmentSchemesDAO(mysqlx::Session& session)
: session_(session)
{
}
std::vector<user_treatment_scheme_dto> MySQLUserTreatmentSchemesDAO::FindByUserLogin(
const std::string& login)
{
const std::string query = R"(
SELECT
uts.uuid,
uts.treatment_name,
uts.instructions,
ts.medication_uuid
FROM up_and_down.users u
JOIN up_and_down.user_treatment_schemes uts
ON uts.user_uuid = u.uuid
LEFT JOIN up_and_down.treatment_schemes ts
ON ts.user_treatment_schemes_uuid = uts.uuid
WHERE u.login = ?
ORDER BY uts.uuid
)";
mysqlx::SqlStatement stmt = session_.sql(query);
stmt.bind(login);
mysqlx::SqlResult result = stmt.execute();
std::unordered_map<std::string, user_treatment_scheme_dto> scheme_map;
for (const mysqlx::Row& row : result) {
const std::string scheme_uuid = row[0].get<std::string>();
if (scheme_map.find(scheme_uuid) == scheme_map.end()) {
user_treatment_scheme_dto dto;
dto.uuid = scheme_uuid;
dto.treatment_name = row[1].isNull() ? "" : row[1].get<std::string>();
dto.instructions = row[2].isNull() ? "" : row[2].get<std::string>();
scheme_map.emplace(scheme_uuid, std::move(dto));
}
if (!row[3].isNull()) {
scheme_map[scheme_uuid]
.medication_uuids
.push_back(row[3].get<std::string>());
}
}
std::vector<user_treatment_scheme_dto> schemes;
schemes.reserve(scheme_map.size());
for (auto& [_, dto] : scheme_map) {
schemes.push_back(std::move(dto));
}
return schemes;
}
} // uad
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include "IUserTreatmentSchemesDAO.h"
#include <mysqlx/xdevapi.h>
namespace uad
{
class MySQLUserTreatmentSchemesDAO : public IUserTreatmentSchemeDAO
{
mysqlx::Session& session_;
public:
explicit MySQLUserTreatmentSchemesDAO(mysqlx::Session& session);
std::vector<user_treatment_scheme_dto> FindByUserLogin(const std::string& login) override;
};
} // uad
-11
View File
@@ -1,11 +0,0 @@
#pragma once
#include "medication_dto.h"
namespace uad
{
struct treatment_scheme_dto {
std::string scheme_uuid;
medication_dto medication;
};
}
+5 -3
View File
@@ -1,6 +1,7 @@
#pragma once
#include "treatment_scheme_dto.h"
#include <string>
#include <vector>
namespace uad
{
@@ -8,7 +9,8 @@ struct user_treatment_scheme_dto {
std::string uuid;
std::string user_uuid;
std::string treatment_name;
std::optional<std::string> instructions;
std::vector<treatment_scheme_dto> medications;
std::string instructions;
std::vector<std::string> medication_uuids;
};
}