323 lines
9.9 KiB
C++
323 lines
9.9 KiB
C++
#include "ReconClient.h"
|
|
#include "Request.h"
|
|
#include "json/cJSON.h"
|
|
#include <cstddef>
|
|
#include <malloc.h>
|
|
#include <string>
|
|
namespace
|
|
{
|
|
const char *CREATE_URL = "/Scan/Create/";
|
|
const char *STATE_URL = "/State/";
|
|
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/";
|
|
const char *SET_MPPS_URL = "/Transfer/MSetting/";
|
|
const char *GET_PACS_URL = "/Transfer/Setting/";
|
|
const char *ECHO_URL = "/Transfer/Echo/";
|
|
}
|
|
|
|
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");
|
|
auto resp = mRequest.post(mHost + STATE_URL, content, mHeaders);
|
|
if (resp.isResponsed() == false){
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::ConnectFail(mErrorMessage);
|
|
}
|
|
if (resp.httpCode() == 200)
|
|
{
|
|
return RequestResult::Success(resp.getContent());
|
|
}
|
|
else
|
|
{
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
}
|
|
|
|
RequestResult ReconClient::Create(const Scan &aScan)
|
|
{
|
|
cJSON *obj = cJSON_CreateObject();
|
|
cJSON_AddStringToObject(obj, "ScanID", aScan.ScanID.c_str());
|
|
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());
|
|
}
|
|
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.isResponsed() == false){
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::ConnectFail(mErrorMessage);
|
|
}
|
|
if (resp.httpCode() == 200)
|
|
{
|
|
return RequestResult::Success();
|
|
}
|
|
else
|
|
{
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
}
|
|
|
|
RequestResult ReconClient::Echo(const std::string& aIP, int aPort, const std::string& aAETitle)
|
|
{
|
|
cJSON *obj = cJSON_CreateObject();
|
|
cJSON_AddStringToObject(obj, "IP", aIP.data());
|
|
cJSON_AddStringToObject(obj, "AETitle", aAETitle.data());
|
|
cJSON_AddNumberToObject(obj, "Port", aPort);
|
|
char *str = cJSON_Print(obj);
|
|
cJSON_Delete(obj);
|
|
std::string content;
|
|
content.append(str);
|
|
free(str);
|
|
auto resp = mRequest.post(mHost + ECHO_URL, content, mHeaders);
|
|
if (resp.isResponsed() == false){
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::ConnectFail(mErrorMessage);
|
|
}
|
|
if (resp.httpCode() == 200)
|
|
{
|
|
|
|
return RequestResult::Success();
|
|
}
|
|
else
|
|
{
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
}
|
|
|
|
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.isResponsed() == false){
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::ConnectFail(mErrorMessage);
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
if (scans)cJSON_Delete(scans);
|
|
mErrorMessage = "get null from server";
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
else
|
|
{
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
}
|
|
|
|
RequestResult ReconClient::QueryVersion()
|
|
{
|
|
std::string content;
|
|
content.append("1");
|
|
auto resp = mRequest.post(mHost + QUERY_VERSION_URL, content, mHeaders);
|
|
if (resp.isResponsed() == false){
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::ConnectFail(mErrorMessage);
|
|
}
|
|
if (resp.httpCode() == 200)
|
|
{
|
|
std::string version = resp.getContent();
|
|
return RequestResult::Success(version);
|
|
}
|
|
else
|
|
{
|
|
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.isResponsed() == false){
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::ConnectFail(mErrorMessage);
|
|
}
|
|
if (resp.httpCode() == 200)
|
|
{
|
|
return RequestResult::Success();
|
|
}
|
|
else
|
|
{
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
}
|
|
|
|
RequestResult ReconClient::GetPACSSetting(std::vector<PACSSetting> &aSettings)
|
|
{
|
|
std::string content;
|
|
content.append("1");
|
|
auto resp = mRequest.post(mHost + GET_PACS_URL, content, mHeaders);
|
|
if (resp.isResponsed() == false){
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::ConnectFail(mErrorMessage);
|
|
}
|
|
if (resp.httpCode() == 200)
|
|
{
|
|
cJSON *setting = cJSON_Parse(resp.getContent().data());
|
|
cJSON* storagePoints = cJSON_GetObjectItem(setting,"StoragePoints");
|
|
if (storagePoints == NULL ){
|
|
mErrorMessage = "Can't get storagePoints from server";
|
|
cJSON_Delete(setting);
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
int storagePointsCount = cJSON_GetArraySize(storagePoints);
|
|
if (storagePointsCount == 0){
|
|
mErrorMessage = "Get null storagePoints from server";
|
|
cJSON_Delete(setting);
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
cJSON* AETitleObj = cJSON_GetObjectItem(setting,"AETitle");
|
|
if (AETitleObj == NULL)
|
|
{
|
|
mErrorMessage = "Can't get AETitle from server";
|
|
cJSON_Delete(setting);
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
std::string aetitle = AETitleObj->valuestring;
|
|
for (size_t i = 0; i < storagePointsCount; i++)
|
|
{
|
|
cJSON* storagePoint = cJSON_GetArrayItem(storagePoints,i);
|
|
if (storagePoint == NULL) continue;
|
|
cJSON* ServerAETitle = cJSON_GetObjectItem(storagePoint,"ServerAETitle");
|
|
if (ServerAETitle == NULL) continue;
|
|
cJSON* ServerIP = cJSON_GetObjectItem(storagePoint,"ServerIP");
|
|
if (ServerIP == NULL) continue;
|
|
cJSON* Port = cJSON_GetObjectItem(storagePoint,"Port");
|
|
if (Port == NULL) continue;
|
|
cJSON* StorageCommitment = cJSON_GetObjectItem(storagePoint,"StorageCommitment");
|
|
if (StorageCommitment == NULL) continue;
|
|
PACSSetting readedSetting;
|
|
readedSetting.AETitle = aetitle;
|
|
readedSetting.ServerAETitle = ServerAETitle->valuestring;
|
|
readedSetting.ServerIP = ServerIP->valuestring;
|
|
readedSetting.Port = Port->valueint;
|
|
readedSetting.StorageCommitment = StorageCommitment->valueint == 1;
|
|
aSettings.push_back(readedSetting);
|
|
}
|
|
return RequestResult::Success();
|
|
}
|
|
else
|
|
{
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
}
|
|
|
|
RequestResult ReconClient::SetMPPSSetting(const MPPSSetting &aSetting)
|
|
{
|
|
cJSON *obj = cJSON_CreateObject();
|
|
if (!aSetting.ServerAETitle.empty())
|
|
{
|
|
cJSON_AddStringToObject(obj, "ServerAETitle", aSetting.ServerAETitle.c_str());
|
|
}
|
|
if (!aSetting.IP.empty())
|
|
{
|
|
cJSON_AddStringToObject(obj, "IP", aSetting.IP.c_str());
|
|
}
|
|
cJSON_AddNumberToObject(obj, "On", aSetting.On);
|
|
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_MPPS_URL, content, mHeaders);
|
|
if (resp.isResponsed() == false){
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::ConnectFail(mErrorMessage);
|
|
}
|
|
if (resp.httpCode() == 200)
|
|
{
|
|
return RequestResult::Success();
|
|
}
|
|
else
|
|
{
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
}
|