#pragma once #include "DeviceComplexJsonCommand.h" #include "SetExaminationInfoCommand.h" #include "ExaminationInfo.h" #include "UsbDeviceManager.h" #include "ElectrodesInfoCreator.h" #include "ComplexCommandCreateMultidata.h" namespace Incart::DeviceWebApi { class SetExaminationInfoJsonCommand final : public DeviceComplexJsonCommand { private: Usb::ByteCommandQueue* const m_commandQueue; Usb::UsbDeviceCommandSet* const m_usbDeviceCommands; public: SetExaminationInfoJsonCommand(std::shared_ptr description, Usb::UsbDeviceManager* const usbDeviceManager) : DeviceComplexJsonCommand(description) , m_commandQueue(usbDeviceManager->getCommandQueue()) , m_usbDeviceCommands(usbDeviceManager->getCommandSet()) { } SetExaminationInfoJsonCommand(Usb::UsbDeviceManager* const usbDeviceManager) : SetExaminationInfoJsonCommand(createCommandDescription(), usbDeviceManager) { } public: static std::shared_ptr createCommandDescription() { return std::make_shared("SetExaminationInfo", std::make_shared(std::vector>{ std::make_shared("PatientId", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("Name", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("Surname", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("Patronymic", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("BirthdayDate", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("Sex", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("StartTime", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("LeadType", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("FileName", Net::WebApi::EJsonCommandUnitType::String), std::make_shared("CableInfo", std::vector>{ std::make_shared("Type", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("Number", Net::WebApi::EJsonCommandUnitType::Int), std::make_shared("SetupCounter", Net::WebApi::EJsonCommandUnitType::Int) }) }), std::make_shared() ); } std::shared_ptr execute(std::shared_ptr launchedCommandInfo_) override { std::shared_ptr launchedCommandInfo = std::dynamic_pointer_cast(launchedCommandInfo_); uid = launchedCommandInfo->uid; if (launchedCommandInfo->data.isNull()) { std::cout << __PRETTY_FUNCTION__ << " json object interpretation error" << std::endl; return DeviceWebApi::JsonCommandStatusCreator::create(Usb::DeviceCommand::EStatus::BAD_DATA); } QVariantMap jsonMap = launchedCommandInfo->data.toMap(); DeviceComplexCommands::ExaminationInfo examinationInfo; examinationInfo.patientId = jsonMap["PatientId"].toString().toStdString(); examinationInfo.name = jsonMap["Name"].toString().toStdString(); examinationInfo.surname = jsonMap["Surname"].toString().toStdString(); examinationInfo.patronymic = jsonMap["Patronymic"].toString().toStdString(); examinationInfo.birthdayDate = Common::DateObject::fromString(jsonMap["BirthdayDate"].toString().toStdString()); examinationInfo.sex = DeviceComplexCommands::PatientSex{jsonMap["Sex"].toString().toStdString() }; examinationInfo.startTime = Common::DateTimeObject::fromString(jsonMap["StartTime"].toString().toStdString()); uint8_t leadType = static_cast(jsonMap["LeadType"].toInt()); examinationInfo.electrodes = DeviceComplexCommands::ElectrodesInfoCreator::create(leadType); examinationInfo.fileName = jsonMap["FileName"].toString().toStdString(); QVariantMap cableInfoJson = jsonMap["CableInfo"].toMap(); examinationInfo.cableInfo.CableType = static_cast(cableInfoJson["Type"].toUInt()); examinationInfo.cableInfo.CableNumber = static_cast(cableInfoJson["Number"].toUInt()); examinationInfo.cableInfo.SetupCounter = static_cast(cableInfoJson["SetupCounter"].toUInt()); std::shared_ptr commandData = std::make_shared>(m_commandQueue->generateUid(), examinationInfo); std::shared_ptr command = std::dynamic_pointer_cast(m_usbDeviceCommands->createComplexCommand(launchedCommandInfo->name, commandData)); m_executedCommands[command.get()] = command; connect(command.get(), &DeviceComplexCommands::SetExaminationInfoCommand::answerIsReady, this, &SetExaminationInfoJsonCommand::handleAnswerIsReady); return executeCommand(command); } private slots: void handleAnswerIsReady(Usb::ComplexCommand* command, std::shared_ptr status) { removeExecutedCommand(command); emit answerIsReady(this, QJsonDocument(), DeviceWebApi::JsonCommandStatusCreator::create(status)); } }; } // namespace Incart::DeviceWebApi