|
@ -66,8 +66,6 @@ public class MongodbStorage implements IDataStorage {
|
|
|
public boolean save(IDataTransformer dataTransformer) {
|
|
|
DataSetTransformer dataSetTransformer = (DataSetTransformer) dataTransformer;
|
|
|
ObjectNode jsonObject = dataSetTransformer.getJsonObject();
|
|
|
StorageMode storagePattern = SysConfig.getInstance().getStoragePattern();//模式类型
|
|
|
|
|
|
|
|
|
if (jsonObject != null) {
|
|
|
String dataSetCode = jsonObject.get(getKey()).asText();
|
|
@ -86,24 +84,15 @@ public class MongodbStorage implements IDataStorage {
|
|
|
updateOptions.upsert(true);
|
|
|
collection.replaceOne(filter, Document.parse(jsonObject.toString()), updateOptions);
|
|
|
|
|
|
|
|
|
String url = createUrl(dataSetCode, patientId, eventNo);
|
|
|
Date expiryDate = DateUtil.setDateTime(new Date(), getExpireDays().intValue());
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
|
|
|
String date = sdf.format(expiryDate);
|
|
|
|
|
|
if (storagePattern == StorageMode.DISTRIBUTE) {
|
|
|
Document updateDoc = new Document();
|
|
|
updateDoc.put("resource.url", url);
|
|
|
updateDoc.put("resource.expiry_date", null);
|
|
|
collection.updateOne(filter, new Document("$set", updateDoc));
|
|
|
} else {
|
|
|
Date expiryDate = DateUtil.setDateTime(new Date(), getExpireDays().intValue());
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
|
|
|
String date = sdf.format(expiryDate);
|
|
|
|
|
|
Document updateDoc = new Document(CREATE_AT, new Date());
|
|
|
updateDoc.put("resource.url", url);
|
|
|
updateDoc.put("resource.expiry_date", date);
|
|
|
collection.updateMany(filter, new Document("$set", updateDoc));
|
|
|
}
|
|
|
Document updateDoc = new Document(CREATE_AT, new Date());
|
|
|
updateDoc.put("resource.url", url);
|
|
|
updateDoc.put("resource.expiry_date", date);
|
|
|
collection.updateMany(filter, new Document("$set", updateDoc));
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
//DebugLogger.fatal("保存病人档案信息至MongoDB异常:", e);
|
|
@ -125,8 +114,6 @@ public class MongodbStorage implements IDataStorage {
|
|
|
public boolean toFile(Patient patient) {
|
|
|
boolean result = true;
|
|
|
PatientCDAIndex patientCDAIndex = new PatientCDAIndex(patient);
|
|
|
StorageMode storagePattern = SysConfig.getInstance().getStoragePattern();
|
|
|
|
|
|
Document datasetDoc = new Document();
|
|
|
Document resultDoc = new Document();
|
|
|
try {
|
|
@ -152,19 +139,14 @@ public class MongodbStorage implements IDataStorage {
|
|
|
}
|
|
|
}
|
|
|
Map<String, String> resource = (Map<String, String>) doc.get("resource");
|
|
|
if (storagePattern == StorageMode.DISTRIBUTE) {
|
|
|
//分布式 dataset 数据调阅URL生成
|
|
|
datasetDoc.put(name, resource.get("url"));
|
|
|
resultDoc.put("expiry_date", "");
|
|
|
} else {
|
|
|
datasetDoc.put(name, "");
|
|
|
resultDoc.put("expiry_date", resource.get("expiry_date"));
|
|
|
boolean writeFile = FileUtil.writeFile(filePath, doc.toJson(), "UTF-8");
|
|
|
if (!writeFile) {
|
|
|
//DebugLogger.fatal("存储临时文件失败:" + cursor.next().toJson());
|
|
|
result = false;
|
|
|
}
|
|
|
datasetDoc.put(name, "");
|
|
|
resultDoc.put("expiry_date", resource.get("expiry_date"));
|
|
|
boolean writeFile = FileUtil.writeFile(filePath, doc.toJson(), "UTF-8");
|
|
|
if (!writeFile) {
|
|
|
//DebugLogger.fatal("存储临时文件失败:" + cursor.next().toJson());
|
|
|
result = false;
|
|
|
}
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
//DebugLogger.fatal("存储临时文件失败.", e);
|
|
|
result = false;
|
|
@ -176,17 +158,17 @@ public class MongodbStorage implements IDataStorage {
|
|
|
}
|
|
|
|
|
|
//摘要信息生成
|
|
|
Document indexData = genPatientIndexData(patient);
|
|
|
if (indexData != null) {
|
|
|
resultDoc.put("dataset", datasetDoc);
|
|
|
resultDoc.put("sumary", indexData);
|
|
|
String indexPath = patientCDAIndex.createDataSetIndex("index", PatientCDAIndex.FileType.JSON);
|
|
|
boolean writeFile = FileUtil.writeFile(indexPath, resultDoc.toJson(), "UTF-8");
|
|
|
if (!writeFile) {
|
|
|
//DebugLogger.fatal("存储索引临时文件失败:" + resultDoc.toJson());
|
|
|
result = false;
|
|
|
}
|
|
|
}
|
|
|
// Document indexData = genPatientIndexData(patient);
|
|
|
// if (indexData != null) {
|
|
|
// resultDoc.put("dataset", datasetDoc);
|
|
|
// resultDoc.put("sumary", indexData);
|
|
|
// String indexPath = patientCDAIndex.createDataSetIndex("index", PatientCDAIndex.FileType.JSON);
|
|
|
// boolean writeFile = FileUtil.writeFile(indexPath, resultDoc.toJson(), "UTF-8");
|
|
|
// if (!writeFile) {
|
|
|
// //DebugLogger.fatal("存储索引临时文件失败:" + resultDoc.toJson());
|
|
|
// result = false;
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
//DebugLogger.fatal("", e);
|