All pastes #942222 Raw Edit

Zeug

public c v1 · immutable
·published 2008-03-14 10:52 UTC
rendered paste body
Index: export_xml.c===================================================================--- export_xml.c	(Revision 475)+++ export_xml.c	(Arbeitskopie)@@ -30,33 +30,29 @@ #include "medvip.h" #include <libxml/parser.h> #include <iconv.h>-#include <string.h>-#include "check.h"+#include "string.h" static iconv_t utfconv; #ifdef _WIN32 extern int errno; #endif-#define XSD_NAMESPACE "xs"- #define BUF_SIZE 0x10000 /**  * @brief Internal _xmlNewChild functions which is handling to utf-8 conversion  */-static inline xmlNodePtr _xmlNewChild (xmlNodePtr parent, xmlNsPtr ns, const char *name, const char* content)+static inline xmlNodePtr _xmlNewChild (xmlNodePtr parent, xmlNsPtr ns, char *name, const char* content) { 	xmlNodePtr node; 	char outputBuffer[BUF_SIZE] = ""; 	char *outStr = outputBuffer;+	char *inStr = name; 	assert(name); 	if (content) { 		xmlChar *utf8content = xmlCharStrdup(content); 		xmlChar *utf8name = xmlCharStrdup(name);-		char *inStr = strdup(name);-		char *freeMe = inStr; /* theoretically iconv could change the inStr pointer location */ 		if (!xmlCheckUTF8((unsigned char *)utf8name)) { 			size_t length = strlen(name);@@ -91,30 +87,10 @@ 		node = xmlNewChild(parent, ns, utf8name, utf8content); 		free(utf8content); 		free(utf8name);-		free(freeMe); 	} else { 		xmlChar *utf8name = xmlCharStrdup(name);-		char *inStr = strdup(name);-		char *freeMe = inStr; /* theoretically iconv could change the inStr pointer location */--		if (!xmlCheckUTF8((unsigned char *)utf8name)) {-			size_t length = strlen(name);-			size_t outLength = sizeof(outputBuffer) - 1;-			size_t retcode = iconv(utfconv, &inStr, &length, &outStr, &outLength);-			if (retcode == (size_t) -1) {-				DPrintf(LEVEL_IMPORTANT, "Could not convert - no valid utf8 for name: %s\n", (char *)utf8name);-			} else {-				free(utf8name);-				utf8name = xmlCharStrdup(outputBuffer);-				if (!xmlCheckUTF8((unsigned char *)utf8name)) {-					DPrintf(LEVEL_IMPORTANT, "No valid utf8 after convert for name: %s\n", (char *)utf8name);-				}-			}-		}- 		node = xmlNewChild(parent, ns, utf8name, NULL); 		free(utf8name);-		free(freeMe); 	} 	return node; }@@ -122,14 +98,13 @@ /**  * @brief Internal xmlSetProp functions which is handling to utf-8 conversion  */-static inline void _xmlSetProp (xmlNodePtr node, const char* name, const char *content)+static inline void _xmlSetProp (xmlNodePtr node, char* name, const char *content) { 	xmlChar *utf8name; 	xmlChar *utf8content; 	char outputBuffer[BUF_SIZE] = ""; 	char *outStr = outputBuffer;-	char *inStr = strdup(name);-	char *freeMe = inStr; /* theoretically iconv could change the inStr pointer location */+	char *inStr = name; 	assert(name); 	assert(content);@@ -167,20 +142,18 @@ 	xmlSetProp(node, utf8name, utf8content); 	free(utf8content); 	free(utf8name);-	free(freeMe); } /**  * @brief Internal xmlSetNsProp functions which is handling to utf-8 conversion  */-static inline void _xmlSetNsProp (xmlNodePtr node, xmlNsPtr ns, const char* name, const char *content)+static inline void _xmlSetNsProp (xmlNodePtr node, xmlNsPtr ns, char* name, const char *content) { 	xmlChar *utf8name; 	xmlChar *utf8content; 	char outputBuffer[BUF_SIZE] = ""; 	char *outStr = outputBuffer;-	char *inStr = strdup(name);-	char *freeMe = inStr; /* theoretically iconv could change the inStr pointer location */+	char *inStr = name; 	assert(name); 	assert(content);@@ -200,7 +173,6 @@ 			} 		} 	}-	utf8content = xmlCharStrdup(content); 	if (!xmlCheckUTF8((unsigned char *)utf8content)) { 		size_t length = strlen(name); 		size_t outLength = sizeof(outputBuffer) - 1;@@ -219,7 +191,6 @@ 	xmlSetNsProp(node, ns, utf8name, utf8content); 	free(utf8content); 	free(utf8name);-	free(freeMe); } void Askallo_Export_XML (const char *filepath)@@ -248,6 +219,7 @@ 	const char *fileName; 	char buf[256]; 	int start, end;+	const char **tBuf; 	const char *token; 	if (!importerConfig.patientInit) {@@ -281,7 +253,7 @@ 	/* create xsd structure for later adding of elements */ 	schema = xmlNewDoc(BAD_CAST "1.0"); 	schemaNode = xmlNewNode(NULL, BAD_CAST "schema");-	xsdNs = xmlNewNs(schemaNode, BAD_CAST "http://www.w3.org/2001/XMLSchema", BAD_CAST XSD_NAMESPACE);+	xsdNs = xmlNewNs(schemaNode, BAD_CAST "http://www.w3.org/2001/XMLSchema", BAD_CAST "xsd"); 	xmlSetNs(schemaNode, xsdNs); 	xmlDocSetRootElement(schema, schemaNode); 	/* create own data types */@@ -289,17 +261,16 @@ 	tmpNode = _xmlNewChild(schemaNode, xsdNs, "simpleType", NULL); 	_xmlSetProp(tmpNode, "name", "sex"); 	tmpNode = _xmlNewChild(tmpNode, xsdNs, "restriction", NULL);-	_xmlSetProp(tmpNode, "base", XSD_NAMESPACE":integer");+	_xmlSetProp(tmpNode, "base", "xsd:integer"); 	tmpNode = _xmlNewChild(tmpNode, xsdNs, "minInclusive", NULL); 	_xmlSetProp(tmpNode, "value", "0"); 	tmpNode = _xmlNewChild(tmpNode->parent, xsdNs, "maxInclusive", NULL); 	_xmlSetProp(tmpNode, "value", "2"); 	/* create age type */-	/* FIXME: Wouldn't be a type derived from xs:duration better? */ 	tmpNode = _xmlNewChild(schemaNode, xsdNs, "simpleType", NULL); 	_xmlSetProp(tmpNode, "name", "age"); 	tmpNode = _xmlNewChild(tmpNode, xsdNs, "restriction", NULL);-	_xmlSetProp(tmpNode, "base", XSD_NAMESPACE":integer");+	_xmlSetProp(tmpNode, "base", "xsd:integer"); 	tmpNode = _xmlNewChild(tmpNode, xsdNs, "minInclusive", NULL); 	_xmlSetProp(tmpNode, "value", "0"); 	tmpNode = _xmlNewChild(tmpNode->parent, xsdNs, "maxInclusive", NULL);@@ -308,7 +279,7 @@ 	tmpNode = _xmlNewChild(schemaNode, xsdNs, "simpleType", NULL); 	_xmlSetProp(tmpNode, "name", "kvNumber"); 	tmpNode = _xmlNewChild(tmpNode, xsdNs, "restriction", NULL);-	_xmlSetProp(tmpNode, "base", XSD_NAMESPACE":integer");+	_xmlSetProp(tmpNode, "base", "xsd:integer"); 	tmpNode = _xmlNewChild(tmpNode, xsdNs, "totalDigits", NULL); 	_xmlSetProp(tmpNode, "value", "8"); 	/* create questionSet type */@@ -317,7 +288,7 @@ 	tmpNode = _xmlNewChild(tmpNode, xsdNs, "sequence", NULL); 	tmpNode = _xmlNewChild(tmpNode, xsdNs, "element", NULL); 	_xmlSetProp(tmpNode, "name", "question");-/*	_xmlSetProp(tmpNode, "type", XSD_NAMESPACE":string");*/+/*	_xmlSetProp(tmpNode, "type", "xsd:string");*/ 	_xmlSetProp(tmpNode, "minOccurs", "0"); 	_xmlSetProp(tmpNode, "maxOccurs", "1"); 	tmpNode = _xmlNewChild(tmpNode->parent, xsdNs, "element", NULL);@@ -331,10 +302,10 @@ 	tmpNode = _xmlNewChild(tmpNode, xsdNs, "complexType", NULL); 	tmpNode = _xmlNewChild(tmpNode, xsdNs, "attribute", NULL); 	_xmlSetProp(tmpNode, "name", "ref");-	_xmlSetProp(tmpNode, "type", XSD_NAMESPACE":IDREF");+	_xmlSetProp(tmpNode, "type", "xsd:IDREF"); 	tmpNode = _xmlNewChild(tmpNode->parent->parent->parent->parent, xsdNs, "attribute", NULL); 	_xmlSetProp(tmpNode, "name", "id");-	_xmlSetProp(tmpNode, "type", XSD_NAMESPACE":ID");+	_xmlSetProp(tmpNode, "type", "xsd:ID"); 	/* askallo-element */ 	tmpNode = _xmlNewChild(schemaNode, xsdNs, "element", NULL); 	_xmlSetProp(tmpNode, "name", "askallo");@@ -365,10 +336,10 @@ 	patientTypeSubParentNode = _xmlNewChild(patientTypeNode, xsdNs, "all", NULL); 	tmpNode = _xmlNewChild(patientTypeNode, xsdNs, "attribute", NULL); 	_xmlSetProp(tmpNode, "name", "internalPatID");-	_xmlSetProp(tmpNode, "type", XSD_NAMESPACE":string");+	_xmlSetProp(tmpNode, "type", "xsd:string"); 	tmpNode = _xmlNewChild(patientTypeNode, xsdNs, "attribute", NULL); 	_xmlSetProp(tmpNode, "name", "kvNumber");-	_xmlSetProp(tmpNode, "type", XSD_NAMESPACE":integer");+	_xmlSetProp(tmpNode, "type", "xsd:integer"); 	/* stammdaten-ref */ 	tmpNode = _xmlNewChild(patientTypeSubParentNode, xsdNs, "element", NULL); 	_xmlSetProp(tmpNode, "ref", "stammdaten");@@ -409,15 +380,14 @@ 		if (vp->string && !vp->merge) 			/* if the string is merged, only exported the first field (that is not marked as merged) */ 			if (!vp->merge && vp->sqlTable) {-				if (!strcmp(vp->sqlTable, MEDVIP_PROJECT_D_IMPORT_PATIENT_TEMP_TABLE)) {+				const char* xsdType;+				const char* xsdMinOccurs;+				if (!strcmp(vp->sqlTable,MEDVIP_PROJECT_D_IMPORT_PATIENT_TEMP_TABLE)) { 					tmpNode = stammdatenTypeSubParentNode;-				} else if (!strcmp(vp->sqlTable, MEDVIP_PROJECT_D_IMPORT_SURVEY_BASE_ASSESSMENT_TEMP_TABLE)) {+				} else if (!strcmp(vp->sqlTable,MEDVIP_PROJECT_D_IMPORT_SURVEY_BASE_ASSESSMENT_TEMP_TABLE)) { 					tmpNode = baseAssessmentTypeSubParentNode;-				} else if (!strcmp(vp->sqlTable, MEDVIP_PROJECT_D_IMPORT_SURVEY_FOLLOW_UP_TEMP_TABLE)) {+				} else if (!strcmp(vp->sqlTable,MEDVIP_PROJECT_D_IMPORT_SURVEY_FOLLOW_UP_TEMP_TABLE)) { 					tmpNode = followUpTypeSubParentNode;-				} else {-					DPrintf(LEVEL_IMPORTANT, "Invalid sqlTable given: '%s'\n", vp->sqlTable);-					continue; 				} 				/* create xsd-definition for the node */ 				tmpNode = _xmlNewChild(tmpNode, xsdNs, "element", NULL);@@ -435,14 +405,6 @@ 		const patient_t *patient = patientArray[i]; 		if (!patient) 			continue;--		/* check whether this patient is blacklisted */-		if (importerConfig.blackListPath && *importerConfig.blackListPath)-			if (Check_PatIDIsInBlackList(va("%i", patient->kvNumber), patient->internalPatID) == 1) {-				DPrintf(LEVEL_IMPORTANT, "Skip entry: '%i' - patid: '%s' (blacklisted)\n", patient->kvNumber, patient->internalPatID);-				continue;-			}- 		PrintProgress(i, patientArraySize); 		patientNode = _xmlNewChild(askalloNode, NULL, "patient", NULL); 		_xmlSetProp(patientNode, "internalPatID", patient->internalPatID);@@ -466,20 +428,17 @@ 						parentNode = baseAssessmentNode; 					} else if (!strcmp(vp->sqlTable,MEDVIP_PROJECT_D_IMPORT_SURVEY_FOLLOW_UP_TEMP_TABLE)) { 						parentNode = followUpNode;-					} else {-						DPrintf(LEVEL_IMPORTANT, "Invalid sqlTable given: '%s' - skip exporting of '%s'\n", vp->sqlTable, str);-						continue; 					}-					switch (vp->type) {+					switch(vp->type) { 					case V_INT:-						xsType = XSD_NAMESPACE":integer";+						xsType = "xs:integer"; 						break; 					case V_DATE: 					case V_DATETIME_WITHOUT_SECONDS: 					case V_DATETIME_SHORT: 					case V_DATETIME_ISO: 					case V_DATETIME:-						xsType = XSD_NAMESPACE":dateTime";+						xsType = "xs:dateTime"; 						break; 					case V_SEX: 						xsType = "sex";@@ -491,45 +450,29 @@ 						xsType = "kvNumber"; 						break; 					case V_INTERNAL_PAT_ID:-					case V_STRING: 					default:-						xsType = XSD_NAMESPACE":string";+					case V_STRING:+						xsType = "xs:string"; 						break; 					}--					/* append new child to corresponding parent node */+						/* append new child to corresponding parent node */ 					tmpNode = _xmlNewChild(parentNode, NULL, vp->string, NULL);--					if (vp->description[0] != '\0')+					if(vp->description[0] != '\0') 						_xmlNewChild(tmpNode, NULL, "question", vp->description);- 					tmpNode = _xmlNewChild(tmpNode, NULL, "answer", str); 					_xmlSetNsProp(tmpNode, xsiNs, "type", xsType);- 					tmpNode = tmpNode->parent; 					_xmlSetProp(tmpNode, "id", va("id%i-%s-%s-%s", patient->kvNumber, patient->internalPatID, (const char*) parentNode->name, vp->string));--					if (vp->triggers[0] != '\0') {-						/* we may not directly modify vp->triggers - so we make a copy here - also don't use a va here!! */-						char *triggersBuffer = strdup(vp->triggers);-						/* the first token in the triggers string is the value that is needed in the parent to trigger this entity-						 * a '*' means, that every value except a 0 will trigger it */-						token = strtok(triggersBuffer, " ");-						if (*token == '*') {-							/* @todo only add the id if there is a value != 0 or empty */-						} else {-							/* @todo only add the id if the value in the xml node is == token */-						}-						token = strtok(NULL, " ");+					if(vp->triggers[0] != '\0') {+						token = strtok(va("%s", vp->triggers), " "); 						do {-							const char *propStr = va("id%i-%s-%s-%s", patient->kvNumber, patient->internalPatID, (const char*) parentNode->name, token);+							const char refKey[256]; 							tmpNode = _xmlNewChild(tmpNode, NULL, "trigger", NULL);-							_xmlSetProp(tmpNode, "ref", propStr);+							sprintf(refKey, "id%i-%s-%s-%s", patient->kvNumber, patient->internalPatID, (const char*) parentNode->name, va("%s", token));+							_xmlSetProp(tmpNode, "ref", refKey); 							tmpNode = tmpNode->parent; 							token = strtok(0, " ");-							DPrintf(LEVEL_EXTRA, "add trigger '%s' (vp->string: '%s')\n", propStr, vp->string);-						} while (token);-						free(triggersBuffer);+						} while(token); 					} 				/* FIXME: activate this check as soon as the values are correct */ 				}@@ -559,3 +502,4 @@ 	iconv_close(utfconv); }+