199 lines
6.8 KiB
C++
199 lines
6.8 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* CHECK_URL = "/v/";
|
|
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/";
|
|
}
|
|
namespace Recon {
|
|
|
|
ReconClient::ReconClient(std::string aCerPath, std::string aKeyPath)
|
|
{
|
|
Req::Request::Init();
|
|
mHeaders["Content-Type"] = "application/json";
|
|
mRequest.setClientCertificate(aCerPath,aKeyPath);
|
|
}
|
|
|
|
ReconClient::~ReconClient()
|
|
{
|
|
Req::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+CHECK_URL,content,mHeaders);
|
|
if (resp.httpCode() == 200){
|
|
return RequestResult::Success();
|
|
}
|
|
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());
|
|
cJSON_AddStringToObject(obj, "PatientID", aScan.PatientID.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.httpCode() == 201){
|
|
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.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();
|
|
}
|
|
}
|
|
mErrorMessage ="get null from server";
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
else{
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
}
|
|
|
|
RequestResult ReconClient::QueryReconID(const std::string& aScanID, std::string& aReconID)
|
|
{
|
|
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_RECON_URL,content,mHeaders);
|
|
if (resp.httpCode() == 204){
|
|
return RequestResult::Success();
|
|
}
|
|
else if (resp.httpCode() == 200){
|
|
aReconID = resp.getContent();
|
|
return RequestResult::Success(aReconID);
|
|
}
|
|
else{
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::Fail(mErrorMessage);
|
|
|
|
}
|
|
}
|
|
|
|
RequestResult ReconClient::QueryReconTask(const std::string& aReconID, TaskQueryResult& aTask)
|
|
{
|
|
cJSON * obj = cJSON_CreateObject();
|
|
cJSON_AddStringToObject(obj, "ReconID", aReconID.data());
|
|
char* str = cJSON_Print(obj);
|
|
cJSON_Delete(obj);
|
|
std::string content;
|
|
content.append(str);
|
|
free(str);
|
|
auto resp = mRequest.post(mHost+QUERY_RECON_URL,content,mHeaders);
|
|
if (resp.httpCode() == 200){
|
|
cJSON * task = cJSON_Parse(resp.getContent().data());
|
|
aTask.ReconID = cJSON_GetObjectItem(task, "ReconID")->valuestring;
|
|
aTask.ScanID= cJSON_GetObjectItem(task, "ScanID")->valuestring;
|
|
aTask.Start = cJSON_GetObjectItem(task, "Start")->valueint!=0;
|
|
aTask.SeqID = cJSON_GetObjectItem(task, "SeqID")->valueint;
|
|
cJSON_Delete(task);
|
|
return RequestResult::Success();
|
|
}
|
|
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.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.httpCode() == 200){
|
|
return RequestResult::Success();
|
|
}
|
|
else{
|
|
mErrorMessage = resp.getContent();
|
|
return RequestResult::Fail(mErrorMessage);
|
|
}
|
|
}
|
|
|
|
}
|