You are on page 1of 6

Labwork6

Biomedical informatics
University of Ljubljana, Faculty of Electrical
Engineering

Autor:
dr. Tomaž Vrtovec Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies Registration number: 70081273
Academic year: 2018/2019
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019

LabWork6: Electronic Health Record


The main purpose of this lab is to understand how EHR works and to see the importance of the XML.

Question 1

This first question asks to list the advantages and disadvantages of having data stored in the form of
an XML record.
ADVANTAGES
Readability: XML is text- based and it is therefore human readable. What’s more, data represented
by XML is usually somewhat understandable to the reader without reference to any other file or
definition.
Universality: XML supports the Unicode Standard, so text from any character set can be used.
Moreover, the text and elements can be specified in different character sets. This means that for
instance, the element wrappers could be in Japanese with the data in these elements in Cyrillic.
Binary representation: XML can store binary data. This data must be converted to text. This can be
done using algorithms such as Base64.
Data storage: XML will store any document or data that can be represented as a tree structure. XML
permits multiple instances of elements within a parent element.
Browser Display: XML can be displayed on browsers using a XML Stylesheet. Without this stylesheet a
browser will usually display an XML file as a list/tree.
DISADVANTAGES
Inefficient: XML wasn’t originally defined as a database storage platform. It was designed to
accommodate the exchange of data between nodes of dissimilar systems. It is therefore relatively
inefficient. XML tags (which make it readable to humans) require additional storage and bandwidth.
Inefficient Binary Storage: Storage of binary data (image data for example) is also inefficent. Since
storage is frequently done using Bawe64 encoding, four text bytes are required to store three bytes
of binary data, taking up more storage.
Encoded Image: An additional program is needed to display encoded image data represented in XML.
The encoded binary image data appears as a stream of unintelligible character data. To display it, it
nmust then be decoded and reassembled into an image.
XML Stylesheet: Even though XML can be used to transmit and store documents for visual display,
display is not its primary purpose. To use it for anything beyond basic display of the data XML
Stylesheet is needed.
Tree Structure Problems: Not all files are well-represened with tree structres.

1
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019

Question 2

This second question asks to write an iterative function and a recursive function to calculate the
factorial of a given natural number. Both functions are showed in the upcoming lines.
There is not much to say about the functions written. Both functions have a first if condition in
common. In fact, by definition 0!=1 and that cannot be calculated neither iteratively nor recursively,
it has to be directly programmed. After this initial condition, the iterative function uses a loop to
calculate the factorial and the recursive function calls itself to make the calculation. It is obvious that
both function give the same outputs.

function oValue=factI(iValue)
oValue=iValue;
if iValue==0 % 0!=1
oValue=1;
else
for i=1:(iValue-1)
oValue=oValue*(iValue-i);
end
end
end

function oValue=factR(iValue)
oValue=iValue;
if iValue==0 % 0!=1
oValue=1;
else
oValue=iValue*factR(iValue-1);
end
end

2
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019

Question 3

This last question asks to write the functions xml2struct_attr and struct2xml_attr by modifying
functions xml2struct and struc2xml so that they will enable reading and writing of the attribute type
within each tag.

Firstly, the function xml2struct_attr will be explained. This function is composed of several
subfunctions such as deleteString, numberOrString and xml2struct. This last function is almost
identical to the one written in the lab, with the exception of some little changes. The codes of the
subfunctions programmed are also shown below.

xml2struct_attr is a function that has just one input (iXml) and a Matab structure as the output. This
function aims to convert the given iXml to an iXml with the identical structure of the one used in the
lab. Once this is achieved, the function written in the lab xml2struct will be called and the output will
be created. In other words, the strategy to follow is for example:

<id type=’’number’’> --> <id>

This is achieved with the help of the function deleteString. This function needs the text that has to be
removed as input and gives a ’clean’ text as output.

After this, the function written in the lab is called and we finally achieve the Matlab structure we
were looking for.
function oStruct = xml2struct_attr(iXml)
iNumber=' type="number"';
iString=' type="string"';
iXml=deleteString(iXml,iNumber,iString);
oStruct=xml2struct(iXml,struct,[]);
end

This function starts creating two arrays that keep the position of type=’’number’’ or type=’’string’’
found in iXml. Afterwards, if the index of the loop is in a position were type=’’number’’ or
type=’’string’’ are found, the iXml gets rewritten removing the attribute. Finally, it must be
highlighted that every time an attribute is removed, the iXml changes its length. It is therefore
necessary to look for the positions of the attributes in every single loop.
function oXml=deleteString(iXml,iNumber,iString)
for i=1:length(iXml)
inumber=strfind(iXml,iNumber);
istring=strfind(iXml,iString);
if inumber~[]
if i==inumber(1)
for k=i:(length(iXml)-length(iNumber))
iXml(k)=iXml(k+length(iNumber));
end

3
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019
end
end
if istring~[]
if i==istring(1)
for k=i:(length(iXml)-length(iString))
iXml(k)=iXml(k+length(iString));
end
end
end
end
oXml=iXml;
end

The aim of this function is to define whether ’xml ’is a string or a integer. The output of this function
is a string if xml is a string and a integer if the xml is a number. With a loop every single character of
xml is evaluated. Since we know that in the ASCII code the characters ’0-9 ’occupy the positions 48-
57, we can conclude that if every single character of xml fits in that zone, xml is a integer. If there is
any character different to ’0-9’ xml will then be a string.
function xml=numberOrString(xml)
aux=0;
for k=1:length(xml)
if (unicode2native(xml(k),'US-ASCII')<=57) &( unicode2native
(xml(k),'US-ASCII')>=48)
aux=aux+1;
end
end
if aux==length(xml)
xml=str2num(xml);
else
xml=xml;
end
end

Finally, the change madein the function xml2struct written in class must be taken into account. The
unique change made is that the following line has been added before the command
eval(['oStruct.', structTag, '=''', xml, ''';']);
xml=numberOrString(xml);

4
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019

Now, the function strct2xml will be discussed. This function is almost identical to the one written in
the lab. The changes made are: the text written after aux=numberOrString(iStruct.(f{i}));
In short, xml is evaluated and if it is a string type=’’string’’ is written and if it is a number
type=’’number’’ is written.
function oXml=strct2xml(iStruct,iXml,iOffset)
oXml=iXml;
nl=char(10);
f= fieldnames(iStruct);
for i=1:length(f)
isstruct(iStruct.(f{i}))
if isstruct(iStruct.(f{i}))
oXml=[oXml,iOffset,'<',f{i},'>',nl]
oXml=struct2xml_attr(iStruct.(f{i}),oXml,[iOffset,' '])
oXml=[oXml,iOffset,'</',f{i},'>',nl]
else
aux=numberOrString(iStruct.(f{i}));
if ischar(aux)
oXml=[oXml,iOffset,'<',f{i},' type="string">',iStruct.
(f{i}),'</',f{i},'>',nl];
else
oXml=[oXml,iOffset,'<',f{i},' type="number">',iStruct.
(f{i}),'</',f{i},'>',nl];
end
end
end

You might also like