Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxPatientStorage.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxPatientStorage.h"
14 #include "cxXMLNodeWrapper.h"
15 
16 namespace cx
17 {
18 
19 PatientStorage::PatientStorage(SessionStorageServicePtr sessionStorageService, QString baseNodeName, bool delayedLoad) :
20  mBaseNodeName(baseNodeName)
21 {
22  if(delayedLoad)
23  connect(sessionStorageService.get(), &SessionStorageService::isLoadingSecond, this, &PatientStorage::duringLoadPatientSlot);
24  connect(sessionStorageService.get(), &SessionStorageService::isLoading, this, &PatientStorage::duringLoadPatientSlot);
25  connect(sessionStorageService.get(), &SessionStorageService::isSaving, this, &PatientStorage::duringSavePatientSlot);
26 }
27 
28 void PatientStorage::storeVariable(QString nodeName, boost::function<QString ()> getValueFunction, boost::function<void (QString)> setValueFunction)
29 {
30  mGetFunctions[nodeName] = getValueFunction;
31  mSetFunctions[nodeName] = setValueFunction;
32 }
33 
34 
35 void PatientStorage::duringSavePatientSlot(QDomElement& node)
36 {
37  XMLNodeAdder root(node);
38  QDomElement baseNode = root.descend(mBaseNodeName).node().toElement();
39  this->addXml(baseNode);
40 }
41 
42 void PatientStorage::duringLoadPatientSlot(QDomElement& node)
43 {
44  XMLNodeParser root(node);
45  QDomElement baseNode = root.descend(mBaseNodeName).node().toElement();
46  if (!baseNode.isNull())
47  this->parseXml(baseNode);
48 }
49 
50 void PatientStorage::addXml(QDomNode& parentNode)
51 {
52  QDomDocument doc = parentNode.ownerDocument();
53 
54  std::map<QString, boost::function<QString()> >::iterator iter;
55  for(iter = mGetFunctions.begin(); iter != mGetFunctions.end(); ++iter)
56  {
57  QDomElement newDataNode = doc.createElement(iter->first);
58  newDataNode.appendChild(doc.createTextNode(iter->second()));
59  parentNode.appendChild(newDataNode);
60  }
61 }
62 
63 void PatientStorage::parseXml(QDomNode& dataNode)
64 {
65  std::map<QString, boost::function<void(QString value)> >::iterator iter;
66  for(iter = mSetFunctions.begin(); iter != mSetFunctions.end(); ++iter)
67  {
68  QString nodeValue = dataNode.namedItem(iter->first).toElement().text();
69  iter->second(nodeValue);
70  }
71 }
72 
73 } //cx
void isLoading(QDomElement &root)
emitted while loading a session. Xml storage is available, getRootFolder() is set to loaded value...
XMLNodeAdder descend(QString path)
void isLoadingSecond(QDomElement &root)
Emitted after the isLoading signal, to allow for structures that must be loaded after core structures...
PatientStorage(SessionStorageServicePtr sessionStorageService, QString baseNodeName, bool delayedLoad=false)
void storeVariable(QString nodeName, boost::function< QString()> getValueFunction, boost::function< void(QString)> setValueFunction)
storeVariable Store a variable in the patient file
XMLNodeParser descend(QString path)
void isSaving(QDomElement &root)
xml storage is available
boost::shared_ptr< class SessionStorageService > SessionStorageServicePtr
Namespace for all CustusX production code.