Scan Json create and save.

This commit is contained in:
Krad
2022-05-11 15:44:43 +08:00
parent 1abd387617
commit f7540385a4
5 changed files with 89 additions and 8 deletions

View File

@@ -8,7 +8,8 @@
#define APP_VALUES()\
ADD_APP_VALUE(InProcessing)\
ADD_APP_VALUE(LastOperationTime)\
ADD_APP_VALUE(LastOperation)
ADD_APP_VALUE(LastOperation)\
ADD_APP_VALUE(EmptyScanFlag)\
#include <QApplication>
#include <QVariant>

View File

@@ -10,6 +10,7 @@
#include <QDateTime>
#include <qdebug.h>
#include "appvals/AppGlobalValues.h"
#include "json/ScanJson.h"
#define TRIGGER_EVENT EventCenter::Default()->triggerEvent
#define THROW_ERROR(errormsg)\
@@ -31,7 +32,6 @@ const char* getStatusString(int status)
return "";
}
std::string getJsonFromPatInf(QObject* obj)
{
return ((QString*)obj)->toStdString();
@@ -229,6 +229,22 @@ void DeviceManager::timerEvent(QTimerEvent* event) {
QString s("%1 %2");
s = s.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd HH:mm:ss")).arg("Scan finished");
TRIGGER_EVENT(GUIEvents::GlobalBannerMessage, nullptr, (QObject*)&s);
QString outputPath = GetDeviceInfo(DeviceInfo::DEV_OUTPATH);
outputPath = outputPath.replace("\\","/");
if (outputPath.endsWith('/')) outputPath = outputPath.remove(outputPath.length()-1,1);
QStringList list = outputPath.split('/');
if (list.length()){
if (AppGlobalValues::EmptyScanFlag().toBool()){
ScanJson::Current()->setEmptyScanID(list.last().toStdString().c_str());
}else{
ScanJson::Current()->setScanID(list.last().toStdString().c_str());
}
ScanJson::Current()->save();
}
else{
QString msg("Scan Output Path error!");
THROW_ERROR(msg);
}
}
//一般不会出现其他情况
else {
@@ -267,6 +283,7 @@ void DeviceManager::processScan(const char* json, bool empty) {
AppGlobalValues::setInProcessing(true);
TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, (QObject*)&msg);
qDebug() << "SetScanInfo>>>>>>>>>>>>>>>>>>>>";
AppGlobalValues::setEmptyScanFlag(empty);
int ret = SetScanInfo(json, empty ? 1 : 0);
if (ret) {
qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo failed";
@@ -293,6 +310,9 @@ void DeviceManager::processScan(const char* json, bool empty) {
}
void DeviceManager::close() {
#ifdef _WIN32
StopDevice();
#endif
previewDataCaller->terminate();
delete previewDataCaller;
}

View File

@@ -2,17 +2,13 @@
#include "ui_patientinformationform.h"
#include "json/cJSON.h"
#include "event/EventCenter.h"
#include "json/ScanJson.h"
PatientInformationForm::PatientInformationForm(QWidget* parent) :
QWidget(parent),
ui(new Ui::PatientInformationForm)
{
ui->setupUi(this);
//ui->lbl_ID->setText(tr(""));
//ui->lbl_Date->setText(tr(""));
//ui->lbl_Name->setText(tr(""));
//ui->lbl_Sex->setText(tr(""));
//ui->lbl_Acc->setText(tr(""));
connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() {
ui->retranslateUi(this);
@@ -63,6 +59,6 @@ const char* PatientInformationForm::getCurrentPatientJsonString(bool empty) {
cJSON_AddItemToObject(root, "InstitutionAddress", cJSON_CreateString("HZ"));
delete jsonstr;
jsonstr = cJSON_Print(root);
cJSON_Delete(root);
ScanJson::Current()->store(root);
return jsonstr;
}

20
src/json/ScanJson.cpp Normal file
View File

@@ -0,0 +1,20 @@
//
// Created by Krad on 2022/5/11.
//
#include "ScanJson.h"
#include <QFile>
#include <QDir>
#include <QCoreApplication>
void ScanJson::save() {
if (!root) return;
QFile f(QString("%1/%2.json").arg(QCoreApplication::applicationDirPath(),scanID.c_str()));
f.open(QFileDevice::ReadWrite);
cJSON_AddItemToObject(root, "EmptyScanID", cJSON_CreateString(emptyScanID.c_str()));
cJSON_AddItemToObject(root, "ScanID", cJSON_CreateString(scanID.c_str()));
char* content = cJSON_Print(root);
f.write(content);
f.flush();
f.close();
free(content);
}

44
src/json/ScanJson.h Normal file
View File

@@ -0,0 +1,44 @@
//
// Created by Krad on 2022/5/11.
//
#ifndef GUI_SCANJSON_H
#define GUI_SCANJSON_H
#include <string>
#include "cJSON.h"
class ScanJson {
public:
~ScanJson(){
if(root)cJSON_Delete(root);
}
void store(cJSON* json){
if(root){
cJSON_Delete(root);
root = nullptr;
}
root = json;
}
void setScanID(const char * id){
scanID.clear();
scanID.append(id);
}
void setEmptyScanID(const char * id){
emptyScanID.clear();
emptyScanID.append(id);
setScanID(id);
}
void save();
static ScanJson* Current(){
static ScanJson instance;
return &instance;
}
private:
std::string emptyScanID;
std::string scanID;
cJSON* root = nullptr;
};
#endif //GUI_SCANJSON_H