summaryrefslogtreecommitdiff
path: root/server/src/artefact.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/artefact.cc')
-rw-r--r--server/src/artefact.cc97
1 files changed, 69 insertions, 28 deletions
diff --git a/server/src/artefact.cc b/server/src/artefact.cc
index cc29b77..24114f9 100644
--- a/server/src/artefact.cc
+++ b/server/src/artefact.cc
@@ -35,7 +35,7 @@
Artefact::Artefact()
{
#ifndef WITHOUT_PENTOMINOS
- PRACRO_DEBUG(artefact, "Creating artefact connection %s : %d",
+ PRACRO_DEBUG(artefact, "Creating artefact connection %s : %d\n",
Conf::artefact_addr.c_str(), Conf::artefact_port);
#endif/*WITHOUT_PENTOMINOS*/
@@ -54,47 +54,88 @@ Artefact::~Artefact()
atf_close(atfh);
}
+static QueryResult node2result(atf_result_node_t *node, time_t timestamp)
+{
+ QueryResult rnode;
+ rnode.timestamp = timestamp;
+ rnode.source = "pentominos";
+
+ if(!node) return rnode;
+
+ struct _atf_result_node_t *child = node->child;
+ while(child) {
+ if(child->value == NULL) {
+ rnode.groups[child->name] = node2result(child, timestamp);
+ } else {
+ rnode.values[child->name] = child->value;
+ }
+ child = child->next;
+ }
+
+ return rnode;
+}
+
QueryResult Artefact::exec(Query &query,
std::string patientid,
std::string user)
{
- QueryParser parser;
+ atf_transaction_t* atft = NULL;
+ atf_reply_t *reply = NULL;
+ atf_result_t *result = NULL;
+ atf_result_node_t *root = NULL;
+ atf_status_t status;
+ time_t timestamp;
+ atf_id id;
+
+ QueryResult rroot;
+ rroot.timestamp = 0;
+ rroot.source = "pentominos";
+
+ if(query.attributes.find("class") == query.attributes.end()) {
+ PRACRO_ERR(artefact, "Missing 'class' attribute!\n");
+ goto aaarg;
+ }
- atf_transaction_t *trans = atf_new_transaction(conn, patientid.c_str());
- atf_querylist_t *qlist = atf_new_querylist(trans, user.c_str());
+ atft = atf_new_transaction(conn, patientid.c_str());
+ if(!atft) goto aaarg;
- atf_id id = atf_add_query(qlist,
- query.attributes["class"].c_str(),
- 0/*oldest*/, "xml"/*replyformat*/);
+ id = atf_add_query(atft, query.attributes["class"].c_str(),
+ FILTER_LATEST, USE_NONE, 0, 0);
+ if(!atft) goto aaarg;
- atf_reply_t *reply = atf_commit(trans, NULL, qlist);
+ reply = atf_commit(atft);
+ if(!reply) goto aaarg;
- atf_status_t status = atf_get_reply_status(reply, id);
+ if(atf_get_num_results(reply, id) != 1) goto aaarg;
- switch(status) {
- case ATF_STATUS_OK:
- {
- size_t bufsize = atf_get_reply_size(reply, id);
- char *buf = new char[bufsize];
-
- ssize_t size = atf_get_reply_data(reply, id, buf, size);
- parser.parse(buf, size);
-
- delete[] buf;
- }
- break;
+ result = atf_get_result(reply, id, 0);
+ if(!result) goto aaarg;
+
+ status = atf_get_result_status(result, NULL, 0);
+ if(status != ATF_STATUS_OK) goto aaarg;
+
+ timestamp = atf_get_result_timestamp(result);
+ rroot.timestamp = timestamp;
- case ATF_STATUS_ERROR:
- PRACRO_ERR(artefact, "Error in artefact query.\n");
- break;
+ root = atf_get_result_node(result);
+ if(!root) goto aaarg;
+
+ {
+ QueryResult qresult = node2result(root, timestamp);
+ rroot.groups[query.attributes["class"]] = qresult;
}
- atf_free_reply(reply);
+ goto cleanup;
+
+ aaarg:
+ PRACRO_ERR(artefact, "Artefact comm error (%d)!\n", atf_get_last_error(atfh));
- atf_free_querylist(qlist);
- atf_free_transaction(trans);
+ cleanup:
+ if(root) atf_free_result_node(root);
+ if(reply) atf_free_reply(reply);
+ if(atft) atf_free_transaction(atft);
- return parser.result;
+ return rroot;
}