2023-08-21 14:22:41 +08:00
|
|
|
#include "ReconClient.h"
|
|
|
|
|
#include "Request.h"
|
|
|
|
|
#include "json/cJSON.h"
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <malloc.h>
|
|
|
|
|
#include <string>
|
2024-04-25 14:14:01 +08:00
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
const char *CREATE_URL = "/Scan/Create/";
|
2024-05-27 09:27:21 +08:00
|
|
|
const char *STATE_URL = "/State/";
|
2024-04-25 14:14:01 +08:00
|
|
|
const char *QUERY_SCAN_URL = "/Scan/Query/";
|
|
|
|
|
const char *QUERY_VERSION_URL = "/Version/";
|
|
|
|
|
const char *QUERY_RECON_URL = "/Task/Query/";
|
|
|
|
|
const char *QUERY_TRANSFER_URL = "/Transfer/Query/";
|
|
|
|
|
const char *SET_PACS_URL = "/Transfer/Setting/";
|
2023-08-21 14:22:41 +08:00
|
|
|
}
|
|
|
|
|
|
2024-04-25 14:14:01 +08:00
|
|
|
ReconClient::ReconClient(std::string aCerPath, std::string aKeyPath)
|
|
|
|
|
{
|
|
|
|
|
Request::Init();
|
|
|
|
|
mHeaders["Content-Type"] = "application/json";
|
|
|
|
|
mRequest.setClientCertificate(aCerPath, aKeyPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReconClient::~ReconClient()
|
|
|
|
|
{
|
|
|
|
|
Request::Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReconClient::SetHost(const std::string &aHost)
|
|
|
|
|
{
|
|
|
|
|
mHost = aHost;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RequestResult ReconClient::CheckActive()
|
|
|
|
|
{
|
|
|
|
|
std::string content;
|
|
|
|
|
content.append("1");
|
2024-05-27 09:27:21 +08:00
|
|
|
auto resp = mRequest.post(mHost + STATE_URL, content, mHeaders);
|
2024-04-25 14:14:01 +08:00
|
|
|
if (resp.httpCode() == 200)
|
|
|
|
|
{
|
|
|
|
|
return RequestResult::Success();
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-08-21 14:22:41 +08:00
|
|
|
{
|
2024-04-25 14:14:01 +08:00
|
|
|
mErrorMessage = resp.getContent();
|
|
|
|
|
return RequestResult::Fail(mErrorMessage);
|
2023-08-21 14:22:41 +08:00
|
|
|
}
|
2024-04-25 14:14:01 +08:00
|
|
|
}
|
2023-08-21 14:22:41 +08:00
|
|
|
|
2024-04-25 14:14:01 +08:00
|
|
|
RequestResult ReconClient::Create(const Scan &aScan)
|
|
|
|
|
{
|
|
|
|
|
cJSON *obj = cJSON_CreateObject();
|
|
|
|
|
cJSON_AddStringToObject(obj, "ScanID", aScan.ScanID.c_str());
|
2024-05-27 09:27:21 +08:00
|
|
|
if (aScan.StudyUID.length()>0)
|
|
|
|
|
{
|
|
|
|
|
cJSON_AddStringToObject(obj, "StudyUID", aScan.StudyUID.c_str());
|
|
|
|
|
}
|
|
|
|
|
if (aScan.MPPSUID.length()>0)
|
|
|
|
|
{
|
|
|
|
|
cJSON_AddStringToObject(obj, "MPPSUID", aScan.MPPSUID.c_str());
|
|
|
|
|
}
|
2024-04-25 14:14:01 +08:00
|
|
|
cJSON_AddStringToObject(obj, "ReferencePath", aScan.ReferencePath.c_str());
|
|
|
|
|
if (!aScan.ReferencePath.empty())
|
|
|
|
|
{
|
|
|
|
|
cJSON_AddStringToObject(obj, "ReferenceID", aScan.ReferenceID.c_str());
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddNumberToObject(obj, "Type", aScan.Type);
|
|
|
|
|
char *str = cJSON_Print(obj);
|
|
|
|
|
cJSON_Delete(obj);
|
|
|
|
|
std::string content;
|
|
|
|
|
content.append(str);
|
|
|
|
|
free(str);
|
|
|
|
|
auto resp = mRequest.post(mHost + CREATE_URL, content, mHeaders);
|
|
|
|
|
if (resp.httpCode() == 201)
|
2023-08-21 14:22:41 +08:00
|
|
|
{
|
2024-04-25 14:14:01 +08:00
|
|
|
return RequestResult::Success();
|
2023-08-21 14:22:41 +08:00
|
|
|
}
|
2024-04-25 14:14:01 +08:00
|
|
|
else
|
2023-08-21 14:22:41 +08:00
|
|
|
{
|
2024-04-25 14:14:01 +08:00
|
|
|
mErrorMessage = resp.getContent();
|
|
|
|
|
return RequestResult::Fail(mErrorMessage);
|
2023-08-21 14:22:41 +08:00
|
|
|
}
|
2024-04-25 14:14:01 +08:00
|
|
|
}
|
2023-09-06 18:01:48 +08:00
|
|
|
|
2024-04-25 14:14:01 +08:00
|
|
|
RequestResult ReconClient::QueryScan(const std::string &aScanID, int &state)
|
|
|
|
|
{
|
|
|
|
|
cJSON *obj = cJSON_CreateObject();
|
|
|
|
|
cJSON_AddStringToObject(obj, "ScanID", aScanID.data());
|
|
|
|
|
char *str = cJSON_Print(obj);
|
|
|
|
|
cJSON_Delete(obj);
|
|
|
|
|
std::string content;
|
|
|
|
|
content.append(str);
|
|
|
|
|
free(str);
|
|
|
|
|
auto resp = mRequest.post(mHost + QUERY_SCAN_URL, content, mHeaders);
|
|
|
|
|
if (resp.httpCode() == 200)
|
|
|
|
|
{
|
|
|
|
|
cJSON *scans = cJSON_Parse(resp.getContent().data());
|
|
|
|
|
int size = cJSON_GetArraySize(scans);
|
|
|
|
|
if (size == 1)
|
|
|
|
|
{
|
|
|
|
|
cJSON *scaninf = cJSON_GetArrayItem(scans, 0);
|
|
|
|
|
if (scaninf != NULL)
|
|
|
|
|
{
|
|
|
|
|
cJSON *value = cJSON_GetObjectItem(scaninf, "State");
|
|
|
|
|
state = value->valueint;
|
|
|
|
|
cJSON_Delete(scans);
|
|
|
|
|
return RequestResult::Success();
|
|
|
|
|
}
|
2023-09-06 18:01:48 +08:00
|
|
|
}
|
2024-04-25 14:14:01 +08:00
|
|
|
mErrorMessage = "get null from server";
|
|
|
|
|
return RequestResult::Fail(mErrorMessage);
|
2023-09-06 18:01:48 +08:00
|
|
|
}
|
2024-04-25 14:14:01 +08:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mErrorMessage = resp.getContent();
|
|
|
|
|
return RequestResult::Fail(mErrorMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-06 18:01:48 +08:00
|
|
|
|
2024-04-25 14:14:01 +08:00
|
|
|
RequestResult ReconClient::QueryVersion()
|
|
|
|
|
{
|
|
|
|
|
std::string content;
|
|
|
|
|
content.append("1");
|
|
|
|
|
auto resp = mRequest.post(mHost + QUERY_VERSION_URL, content, mHeaders);
|
|
|
|
|
if (resp.httpCode() == 200)
|
|
|
|
|
{
|
|
|
|
|
std::string version = resp.getContent();
|
|
|
|
|
return RequestResult::Success(version);
|
2023-09-07 17:29:02 +08:00
|
|
|
}
|
2024-04-25 14:14:01 +08:00
|
|
|
else
|
2023-08-22 10:47:19 +08:00
|
|
|
{
|
2024-04-25 14:14:01 +08:00
|
|
|
mErrorMessage = resp.getContent();
|
|
|
|
|
return RequestResult::Fail(mErrorMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RequestResult ReconClient::SetPACSSetting(const PACSSetting &aSetting)
|
|
|
|
|
{
|
|
|
|
|
cJSON *obj = cJSON_CreateObject();
|
|
|
|
|
if (!aSetting.AETitle.empty())
|
|
|
|
|
{
|
|
|
|
|
cJSON_AddStringToObject(obj, "AETitle", aSetting.AETitle.c_str());
|
|
|
|
|
}
|
|
|
|
|
if (!aSetting.ServerIP.empty())
|
|
|
|
|
{
|
|
|
|
|
cJSON_AddStringToObject(obj, "IP", aSetting.ServerIP.c_str());
|
|
|
|
|
}
|
|
|
|
|
if (!aSetting.ServerAETitle.empty())
|
|
|
|
|
{
|
|
|
|
|
cJSON_AddStringToObject(obj, "ServerAETitle", aSetting.ServerAETitle.c_str());
|
|
|
|
|
}
|
|
|
|
|
if (aSetting.Port > 0)
|
|
|
|
|
{
|
|
|
|
|
cJSON_AddNumberToObject(obj, "Port", aSetting.Port);
|
|
|
|
|
}
|
|
|
|
|
char *str = cJSON_Print(obj);
|
|
|
|
|
cJSON_Delete(obj);
|
|
|
|
|
std::string content;
|
|
|
|
|
content.append(str);
|
|
|
|
|
free(str);
|
|
|
|
|
auto resp = mRequest.post(mHost + SET_PACS_URL, content, mHeaders);
|
|
|
|
|
if (resp.httpCode() == 200)
|
|
|
|
|
{
|
|
|
|
|
return RequestResult::Success();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mErrorMessage = resp.getContent();
|
|
|
|
|
return RequestResult::Fail(mErrorMessage);
|
2023-08-21 14:22:41 +08:00
|
|
|
}
|
|
|
|
|
}
|