summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2009-07-24 13:59:36 +0000
committerdeva <deva>2009-07-24 13:59:36 +0000
commit408c7c5b36e1058a76741a22876593ee8c042dd4 (patch)
tree2fa4fb2a1586a0019349f3da569cbb1fc86c3dc5
parentc0392425fbc024084da9c626fa47814a34eba3e7 (diff)
Introduced a new template tag called 'header' to replace the macro-tag-with-header-attribute construct.
-rw-r--r--client/macro.cc12
-rw-r--r--client/mainwindow.cc6
-rw-r--r--server/src/server.cc9
-rw-r--r--server/src/template.h1
-rw-r--r--server/src/templateparser.cc95
-rw-r--r--server/xml/templates/amd_behandling.xml2
-rw-r--r--server/xml/templates/amd_forunders.xml10
-rw-r--r--server/xml/templates/amd_kontrolunders.xml10
8 files changed, 67 insertions, 78 deletions
diff --git a/client/macro.cc b/client/macro.cc
index bd7393f..2777cf5 100644
--- a/client/macro.cc
+++ b/client/macro.cc
@@ -45,8 +45,8 @@ void Macro::update(QDomNode &n)
QDomElement xml_elem = node.toElement();
- if(xml_elem.tagName() != "macro") return;
- if(xml_elem.hasAttribute("header")) return;
+ if(xml_elem.tagName() != "macro" && xml_elem.tagName() != "header") return;
+ // if(xml_elem.hasAttribute("header")) return;
name = xml_elem.attribute("name");
@@ -57,7 +57,7 @@ void Macro::init(QBoxLayout *layout, Macros &macros, bool initialising, NetCom &
{
QDomElement xml_elem = node.toElement();
- if(xml_elem.tagName() != "macro") return;
+ if(xml_elem.tagName() != "macro" && xml_elem.tagName() != "header") return;
isstatic = xml_elem.attribute("static", "false") == "true";
iscompact = xml_elem.attribute("compact", "false") == "true";
@@ -67,14 +67,16 @@ void Macro::init(QBoxLayout *layout, Macros &macros, bool initialising, NetCom &
requires = xml_elem.attribute("requires").split(",");
}
- if(xml_elem.hasAttribute("header")) {
+ // if(xml_elem.hasAttribute("header")) {
+ if(xml_elem.tagName() == "header") {
// Macro is a special headline macro.
// Simply create a headline, and ignore the rest.
// Only add header on initial contruction.
if(initialising == true) {
QLabel *header = new QLabel();
- header->setText(xml_elem.attribute("header"));
+ // header->setText(xml_elem.attribute("header"));
+ header->setText(xml_elem.attribute("caption"));
QFont headerfont = header->font();
headerfont.setBold(true);
headerfont.setPointSize(headerfont.pointSize() + 2);
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index 91d87a7..14ed60b 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -125,9 +125,12 @@ void MainWindow::update()
QDomNodeList macronodes = coursenode.childNodes();
for(int j = 0; j < macronodes.count(); j++) {
+
QDomNode macronode = macronodes.at(j);
QDomElement macroelement = macronode.toElement();
+ // printf("%s\n", macroelement.tagName().toStdString().c_str());
+
QString macroname = macroelement.attribute("name");
bool found = false;
@@ -137,7 +140,8 @@ void MainWindow::update()
i++;
}
- if(found == false || macroelement.hasAttribute("header")) {
+ // if(found == false || macroelement.hasAttribute("header")) {
+ if(found == false || macroelement.tagName() == "header") {
QString num;
num.sprintf("%04d", j);
Macro macro(macronode);
diff --git a/server/src/server.cc b/server/src/server.cc
index 884284a..8bfd827 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -148,17 +148,14 @@ static std::string handleTransaction(Transaction *transaction,
while(mi2 != templ->course.macros.end()) {
Macro &macro = (*mi2);
- // FIXME: This is to be made in some other way in a later version.
- if(macro.attributes.find("header") != macro.attributes.end()) {
- // Macro is a special headline macro
- // Simply output a headline, and ignore the rest of it.
- answer += " <macro header=\"" + macro.attributes["header"] + "\"></macro>\n";
+ if(macro.isHeader) {
+ answer += " <header caption=\"" + macro.attributes["caption"] + "\"/>\n";
mi2++;
continue;
}
bool completed = db->checkMacro(transaction->cpr, macro.attributes["name"]);
-
+
answer += " <macro completed=";
if(completed) answer += "\"true\"";
else answer += "\"false\"";
diff --git a/server/src/template.h b/server/src/template.h
index f39baac..ac5900f 100644
--- a/server/src/template.h
+++ b/server/src/template.h
@@ -65,6 +65,7 @@ public:
Widget window;
std::map< std::string, std::string > attributes;
Resume resume;
+ bool isHeader;
};
class Course {
diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc
index 8db6bbf..49cc29d 100644
--- a/server/src/templateparser.cc
+++ b/server/src/templateparser.cc
@@ -47,28 +47,14 @@
void TemplateParser::error(const char* fmt, ...)
{
- // TODO: Throw exception here.
-
va_list argp;
- int s = 256;
- char *p = new char[s];
- /* See printf(3) for details on the loop how to get the right buffersize. */
- while(1) {
- va_start(argp, fmt);
- int n = vsnprintf(p, s, fmt, argp);
- va_end(argp);
- if(n > -1 && n < s)
- break;
- if(n > -1) /* glibc 2.1 */
- s = n+1; /* precisely what is needed */
- else /* glibc 2.0 */
- s *= 2; /* twice the old size */
- delete[] p;
- p = new char[s];
- }
+ char *p;
+ va_start(argp, fmt);
+ vasprintf(&p, fmt, argp);
+ va_end(argp);
PRACRO_ERR_LOG(macro, "Error in TemplateParser: %s\n", p);
- delete[] p;
- throw Exception("Error in TemplateParser");
+ throw Exception(std::string("Error in TemplateParser: ") + p);
+ free(p);
}
TemplateParser::TemplateParser(std::string course)
@@ -77,11 +63,7 @@ TemplateParser::TemplateParser(std::string course)
t = new Template();
current_macro = NULL;
-#ifndef TEST_TEMPLATEPARSER
file = Conf::xml_basedir + "/templates/" + course + ".xml";
-#else
- file = "../xml/templates/" + course + ".xml";
-#endif/*TEST_TEMPLATEPARSER*/
PRACRO_DEBUG(macro, "Using template file: %s\n", file.c_str());
@@ -114,7 +96,7 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri
}
// Create macro and enable parsing of queries, maps and window
- if(name == "macro") {
+ if(name == "macro" || name == "header") {
if(state != COURSE) error("macro found outside course.");
state = MACRO;
@@ -122,6 +104,7 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri
Macro m;
m.attributes = attributes;
+ m.isHeader = name == "header";
t->course.macros.push_back(m);
current_macro = &(t->course.macros.back());
@@ -134,7 +117,7 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri
void TemplateParser::endTag(std::string name)
{
if(name == "course") state = UNDEFINED;
- if(name == "macro") {
+ if(name == "macro" || name == "header") {
current_macro = NULL;
state = COURSE;
}
@@ -182,41 +165,43 @@ void print_attributes(std::string prefix,
int main()
{
+ Conf::xml_basedir = "../xml/";
+
try {
- TemplateParser parser("example");
- parser.parse();
+ TemplateParser parser("example");
+ parser.parse();
- Template *t = parser.getTemplate();
+ Template *t = parser.getTemplate();
- printf("[Template]:\n");
- print_attributes("\t-", t->attributes);
+ printf("[Template]:\n");
+ print_attributes("\t-", t->attributes);
- printf("\t[Course]:\n");
- print_attributes("\t\t-", t->course.attributes);
+ printf("\t[Course]:\n");
+ print_attributes("\t\t-", t->course.attributes);
- printf("\t\t[Macros]:\n");
- std::vector< Macro >::iterator i = t->course.macros.begin();
-
- while(i != t->course.macros.end()) {
- printf("\t\t\t[Macro]:\n");
- print_attributes("\t\t\t\t-", (*i).attributes);
-
- std::vector< Query >::iterator qi = (*i).queries.begin();
- while(qi != (*i).queries.end()) {
- printf("\t\t\t\t[Query]:\n");
- print_attributes("\t\t\t\t\t-", (*qi).attributes);
- qi++;
+ printf("\t\t[Macros]:\n");
+ std::vector< Macro >::iterator i = t->course.macros.begin();
+
+ while(i != t->course.macros.end()) {
+ printf("\t\t\t[Macro]:\n");
+ print_attributes("\t\t\t\t-", (*i).attributes);
+
+ std::vector< Query >::iterator qi = (*i).queries.begin();
+ while(qi != (*i).queries.end()) {
+ printf("\t\t\t\t[Query]:\n");
+ print_attributes("\t\t\t\t\t-", (*qi).attributes);
+ qi++;
+ }
+
+ std::vector< Map >::iterator mi = (*i).maps.begin();
+ while(mi != (*i).maps.end()) {
+ printf("\t\t\t\t[Map]:\n");
+ print_attributes("\t\t\t\t\t-", (*mi).attributes);
+ mi++;
+ }
+
+ i++;
}
-
- std::vector< Map >::iterator mi = (*i).maps.begin();
- while(mi != (*i).maps.end()) {
- printf("\t\t\t\t[Map]:\n");
- print_attributes("\t\t\t\t\t-", (*mi).attributes);
- mi++;
- }
-
- i++;
- }
} catch(Exception &e) {
printf("ERROR: %s\n", e.what());
return 1;
diff --git a/server/xml/templates/amd_behandling.xml b/server/xml/templates/amd_behandling.xml
index 016a6f2..7581864 100644
--- a/server/xml/templates/amd_behandling.xml
+++ b/server/xml/templates/amd_behandling.xml
@@ -3,7 +3,7 @@
resume="Behandling af AMD med Lucentis">
<macro name="header" static="true"/>
- <macro header="Behandling"/>
+ <header caption="Behandling"/>
<macro name="amdinjektionindikation"/>
<macro name="5steps"/>
<macro name="amdprocedure"/>
diff --git a/server/xml/templates/amd_forunders.xml b/server/xml/templates/amd_forunders.xml
index 1245b99..9201e3f 100644
--- a/server/xml/templates/amd_forunders.xml
+++ b/server/xml/templates/amd_forunders.xml
@@ -3,7 +3,7 @@
<macro name="header" static="true"/>
<macro name="referral"/>
- <macro header="Anamnese"/>
+ <header caption="Anamnese"/>
<macro name="cave" requires="referral"/>
<macro name="medicine" requires="referral" compact="true"/>
<macro name="previouscommon" requires="referral"/>
@@ -11,7 +11,7 @@
<macro name="preveyediseases" requires="referral"/>
<macro name="current" requires="referral"/>
- <macro header="Objektiv undersøgelse"/>
+ <header caption="Objektiv undersøgelse"/>
<macro name="visus" requires="referral"/>
<macro name="lensmeter" requires="referral"/>
<macro name="autoref" requires="referral"/>
@@ -22,15 +22,15 @@
<macro name="90Dlens" requires="referral"/>
<macro name="amdpreopconclusion" requires="referral"/>
- <macro header="Øjendrypning"/>
+ <header caption="Øjendrypning"/>
<macro name="ocgtt" requires="referral"/>
- <macro header="Fluorescens angiografi"/>
+ <header caption="Fluorescens angiografi"/>
<macro name="fluoresceininj" requires="referral"/>
<macro name="fluoresceinphases" requires="referral"/>
<macro name="fluoresceinconclusion" requires="referral"/>
- <macro header="Samlet konklusion"/>
+ <header caption="Samlet konklusion"/>
<macro name="amdinformation" requires="referral"/>
<macro name="amdindication" requires="referral"/>
<macro name="amdconsent" requires="referral" compact="true"/>
diff --git a/server/xml/templates/amd_kontrolunders.xml b/server/xml/templates/amd_kontrolunders.xml
index 5d81b0a..2606743 100644
--- a/server/xml/templates/amd_kontrolunders.xml
+++ b/server/xml/templates/amd_kontrolunders.xml
@@ -3,13 +3,13 @@
resume="Kontrolundersøgelse i AMD forløb">
<macro name="header" static="true"/>
- <macro header="Anamnese"/>
+ <header caption="Anamnese"/>
<macro name="cave"/>
<macro name="medicine" compact="true"/>
<macro name="subjeval"/>
<macro name="current"/>
- <macro header="Objektiv undersøgelse"/>
+ <header caption="Objektiv undersøgelse"/>
<macro name="visus"/>
<macro name="lensmeter"/>
<macro name="autoref"/>
@@ -21,14 +21,14 @@
<macro name="amdpreopconclusion"/>
<macro name="fundus"/>
- <macro header="Øjendrypning"/>
+ <header caption="Øjendrypning"/>
<macro name="ocgtt"/>
- <macro header="Fluorescens angiografi"/>
+ <header caption="Fluorescens angiografi"/>
<macro name="fluoresceinphases"/>
<macro name="fluoresceinconclusion"/>
- <macro header="Samlet konklusion"/>
+ <header caption="Samlet konklusion"/>
<macro name="amdinformation"/>
<macro name="amdtreatmentindication"/>
<macro name="amdconsent" compact="true"/>