Top Banner
RFID Patient Tagging and Database System April 2004 Department of Electronic Engineering RFID PATIENT TAGGING AND DATABASE SYSTEM FINAL YEAR PROJECT REPORT Student: Martin O’Halloran Supervisor: Martin Glavin
99

RFID PATIENT TAGGING AND DATABASE SYSTEM

Nov 01, 2014

Download

Documents

sonnni

RFID PATIENT TAGGING AND DATABASE SYSTEM
RFID PATIENT TAGGING AND DATABASE SYSTEMRFID PATIENT TAGGING AND DATABASE SYSTEMRFID PATIENT TAGGING AND DATABASE SYSTEM
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Department of Electronic Engineering

RFID PATIENT TAGGING AND

DATABASE SYSTEM

FINAL YEAR PROJECT REPORT

Student:

Martin O’Halloran

Supervisor: Martin Glavin

Date: April 2004

Page 2: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

ACKNOWLEDGEMENTS

I would like to thank the department technicians, Aodh Dalton, Myles Meehan and

Martin Burke for their assistance throughout this project.

I would also like to thank my supervisor, Martin Glavin, for giving me the help and

insight I needed, and for giving me the liberty to develop this project.

Finally, I would like to express my gratitude to Connaught Electronics Ltd for their

continued assistance and support throughout this project.

Page 3: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

ABSTRACT

This paper proposes the use of a Radio Frequency Identification (RFID) tagging

system, coupled with a web-based database, to facilitate the centralisation of patient

records within the hospital environment. RFID carries data in suitable transponders,

generally known as tags and receives data by an RFID reader at a suitable time and

place to satisfy particular application needs. This paper proposes a system for the

identification of hospital patients using RFID. The tag holds a unique patient

identifier, which is used to retrieve the patient details from a web-based database. The

merging of RFID technologies and the advances in web-based database systems

provides standardised and centralised hospital records, with a strong emphasis on data

security.

This project merges many different technologies including the following:

RFID

Wi-Fi (Wireless Fidelity)

Linux

HTML (HyperText Mark-up Language)

PHP (PHP Hypertext Pre-processor)

SQL (Structured Query Language)

This document will first introduce these technologies, before showing how they have

been implemented in this project.

Page 4: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

ACKNOWLEDGEMENTS.......................................................................................................................2

ABSTRACT..............................................................................................................................................3

1. INTRODUCTION..........................................................................................................................8

1.1 INTRODUCTION.............................................................................................................................8

1.2 OVERVIEW OF THE SYSTEM.....................................................................................................8

1.3 PROBLEMS TO BE CONSIDERED..............................................................................................9

2. RESEARCH..................................................................................................................................10

2.1 INTRODUCTION...........................................................................................................................10

2.1 INFORMATION RECORDED BY DOCTORS..........................................................................10

Patient History...............................................................................................................................10Examinations..................................................................................................................................11Special Investigations.....................................................................................................................11

2.2 INFORMATION RECORDED BY NURSES..............................................................................11

General Observations....................................................................................................................11Neurological Observations............................................................................................................11

3. RFID....................................................................................................................................................13

3.1 INTRODUCTION TO RFID.................................................................................................13

3.2 TYPES OF RFID SYSTEMS..........................................................................................................13

3.2.1 Radio Frequency...................................................................................................................13Low Frequency RFID.................................................................................................................................14Medium Frequency RFID..........................................................................................................................14High Frequency RFID................................................................................................................................14

3.2.2 Modulation............................................................................................................................15Electromagnetic coupling...........................................................................................................................15Propagating Electromagnetic Waves.........................................................................................................16

3.2.3 Types of RFID Tag................................................................................................................16Active Tags................................................................................................................................................16Passive Tags...............................................................................................................................................17

3.3 RFID TAG STRUCTURE..............................................................................................................17

3.4 RFID READER STRUCTURE......................................................................................................18

3.5 RFID COMMUNICATION............................................................................................................19

4. TECHNOLOGIES EMPLOYED IN THE SYSTEM...............................................................21

4.1 LINUX......................................................................................................................................21

4.2 APACHE...........................................................................................................................................22

4.3 PHP...................................................................................................................................................24

4.4 VISUAL BASIC.......................................................................................................................25

4.4.1 INTRODUCTION........................................................................................................................25

4.4.2 ADVANTAGES OFFERED BY VISUAL BASIC....................................................................25

5. SERVER-SIDE SETUP AND INSTALLATION...........................................................................26

5.1 INTRODUCTION...........................................................................................................................26

5.2 INSTALLATION OF LINUX........................................................................................................26

5.2.1 Initial Installation Process....................................................................................................265.2.1 Post-Installation Configuration............................................................................................27

5.3 APACHE INSTALLATION AND CONFIGURATION.............................................................27

5.3.1 Installation............................................................................................................................27

Page 5: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

5.3.2 Apache Configuration...........................................................................................................275.3.2 Apache Testing......................................................................................................................28

5.4 MYSQL INSTALLATION.............................................................................................................28

5.4.1 MySQL Installation...............................................................................................................285.4.2 MySQL Testing......................................................................................................................29

5.5 PHP INSTALLATION AND CONFIGURATION......................................................................30

5.5.1 Introduction...........................................................................................................................305.5.2 Installation............................................................................................................................305.5.3 Configuration........................................................................................................................305.5.4 Testing...................................................................................................................................31

6. VISUAL BASIC CLIENT APPLICATION....................................................................................32

6.1 INTRODUCTION...........................................................................................................................32

6.2 COMMUNICATION WITH THE RFID READER....................................................................32

6.2.1 Introduction...........................................................................................................................326.2.2 RFID reader serial protocol definition.................................................................................32

6.2.2.1 Request packet format....................................................................................................................326.2.2.2 Response packet format.................................................................................................................336.2.2.3 Request commands.........................................................................................................................346.2.2.4 Request Command Flags................................................................................................................346.2.2.5 Response Command Flags.............................................................................................................35

6.2.3 MSComm communication control.........................................................................................356.2.3.1 Initial MSComm setup...................................................................................................................356.2.3.2 Reading the RFID tag number.......................................................................................................35

6.3 CLIENT LOGIN SYSTEM............................................................................................................41

6.4 USER-TYPE SPECIFIC CONTROLS..........................................................................................43

6.5 UPDATING PATIENT INFORMATION.....................................................................................44

6.6 VIEWING PATIENT INFORMATION.......................................................................................46

7. PHP AND MYSQL DATABASE DEVELOPMENT...............................................................48

7.1 INTRODUCTION...........................................................................................................................48

7.2 MYSQL DATABASE SETUP........................................................................................................49

7.2.1 Information to be stored........................................................................................................497.2.2 Information to be stored........................................................................................................497.2.3 Organising the information...................................................................................................517.2.4 Establishing the relationship between the data tables..........................................................527.2.5 Building the database............................................................................................................53

7.3 PHP...................................................................................................................................................55

7.3.1 Application of PHP...............................................................................................................557.3.2.1 User login verification....................................................................................................................567.3.2.2 Uploading Patient Personal Information........................................................................................577.3.2.3 Uploading Patient Medical Details................................................................................................597.3.2.4 Uploading the doctor’s diagnosis...................................................................................................637.3.2.5 Uploading Multimedia information...............................................................................................657.3.2.6 Retrieving patient personal information.........................................................................................667.3.2.7 Display Medical Details.................................................................................................................677.3.2.8 Retrieval and display of nurses’ observations................................................................................677.3.2.9 Retrieving and displaying Multimedia data...................................................................................697.3.2.10 Displaying Past medical records..................................................................................................70

Page 6: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

1. INTRODUCTION

1.1 Introduction

In general, patient medical records in hospital are currently paper based. They are

often compiled in an ad-hoc manner, with recorded details varying between doctors.

This project details a solution that attempts to homogenise hospital records by

merging RFID and web-based database technologies. The solution standardises the

recorded data, and provides a database that can be accessed by authorised personnel.

Current systems [1] offer solutions whereby the patient data is held on the RFID tag,

which restricts the amount of patient data that can be stored, due to limited memory

on the tag. This paper proposes a solution that will resolve this issue. The RFID tag

will only store a unique Personal Identification Number (PIN), which identifies the

patient’s records within the web-based database.

1.2 OVERVIEW OF THE SYSTEM

The systems structure is as follows: Each patient’s records are associated with a

unique identifier. This identifier is stored on a transponder attached to the patient’s

wrist. Doctors, nurses and administration personnel are allowed access the database

using a PDA (Personal Digital Assistant) or tablet PC enabled with a wireless network

card, as shown in figure 1.1. The RFID tag is read, and the identifier is passed over

the wireless network to the centralised server. The server searches the database and

dynamically generates a web page containing the relevant patient information.

Medical personnel are then be authorised to view and update the patient details. The

information contained in the database comprises text and multimedia data. The

structure of the system can be described as client-server architecture. The client

consists of the PDA while the server includes the web server and database, as shown

in figure 1.1. The client code handles communication with the RFID reader and also

Page 7: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

handles the viewing of patient records. The server software deals with the storage and

retrieval of patient information.

Figure 1: Overview of the system

1.3 PROBLEMS TO BE CONSIDERED

The client software has to fulfil the following functionality:

It must interface with the RFID reader read the RFID tag. It must be able to communicate with the Web-server. It must incorporate a web-browser for the viewing and updating of patient

information.

The server software must incorporate the following functionality:

It must be secure. It must store all the patient information in an efficient manner. It must allow the patient information to be easily viewed and updated

through the generation of dynamic web pages.

Page 8: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

2. RESEARCH

2.1 Introduction

The main objective of any database is to accurately reflect the information it models.

That is to say, the database should hold information that is both relevant and useful.

With this is mind, the next step involved establishing what patient information was

maintained by medical personnel in hospitals. The findings of the research are

outlined below.

2.1 Information recorded by doctors

After several meeting with hospital interns, the following is a list of the general

patient details recorded by doctors:

Patient History Presenting Compliant: Symptoms that the patient is complaining of and the

duration of these symptoms (brief 2-3 lines only)

History of Presenting Complaint: Further questioning of the presenting

complaint e.g. when did the symptoms first present themselves

Family History: illnesses of family members.

Social History: Information such as does the patient smoke, units of alcohol

consumed per day, does the patient live alone, etc

Past Medical History: Present or previous medical history.

Past surgical history

Any Allergies

Current Medication

Review of Systems: quick questioning of all the other organ systems

Examinations Patient respiratory examination.

Page 9: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Inspection: Check the chest for scars, over-expansion, muscle wasting,

etc.

Palpation test

Percussion test

Special Investigations Blood test

Blood culture

ECG

X-rays

2.2 INFORMATION RECORDED BY NURSESThe following outlines the information recorded by nursing staff on a daily basis

(nurses’ observations):

General ObservationsThe following are the standard patient observations as recorded by nurses daily:

Pulse

Oxygen intake (if any)

Risk of pressure sores (Waterlow scale)

Fluid Intake

Fluid Output

Blood sugar level (if the patient is diabetic)

Neurological ObservationsIf the patient has had a head injury, or a stroke, or a similar injury, then the following

neurological observations should be taken:

Blood pressure

Pulse

Respirations

Temperature

Glasgow coma scale reading

Page 10: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

3. RFID

3.1 INTRODUCTION TO RFID

Radio Frequency Identification (RFID) systems were originally developed in the

1960’s for automatic data capture based on radio frequency transmissions to identify

rail carriages, personnel, and animals. Radio Frequency Identification (RFID) used

electromagnetic energy as a medium for communication. The two basic components,

a reader and a transponder, are connected to a host computer that controls the reader.

The transponder consists of a single unit containing a radio receiver and transmitter.

When the transponder receives a signal from the unit reader, it responds by

transmitting its unique identification code and any other data that is requested in the

form of a serial data stream. . The object of any RFID system is to carry data in

suitable transponders, generally known as tags, and to retrieve data at a suitable time

and place to satisfy particular application needs. Data within a tag may provide

identification for an item in manufacture, goods in transit, object location information,

the identity of a vehicle, or animal identification. In addition to tags, the system

requires a means of reading or interrogating the tags, and some means of

communicating the data to a host computer.

3.2 TYPES OF RFID SYSTEMS

RFID systems can be classified according to the radio frequency used, the type of

modulation used to communicate and the type of tag used in the system.

3.2.1 Radio FrequencyThe radio frequency is defined as the frequency of the sine wave generated by the

reader to send a request to the tag. Carrier wave frequency is of primary importance in

determining data transfer rates. In practical terms the rate of data transfer is influenced

primarily by the frequency of the carrier wave used to carry the data between the tag

and its reader. Generally speaking the higher the frequency the higher the data transfer

Page 11: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

that can be achieved. Three frequency ranges are generally pre-defined in RFID

systems as low, intermediate (medium) and high as shown in Table 3.1.

Frequency Range Frequency

Low 100-500 kHz

Intermediate 10-15 MHz

High 2.4-5.8 GHz

Table 3.1 : RFID frequency bands

Low Frequency RFIDThe advantage of low frequency RFID is that unlike high frequency RFID systems,

they do not require a line of sight between the transponder and the reader antenna.

They have an operating range of between 1 and 3 metres. They can use low power

levels, therefore making them more acceptable for licensing. The transponders are

quite inexpensive, and the low frequency allows for reads through non-metallics.

Medium Frequency RFIDMedium frequency RFID (typically 13.56 MHz) is used in Emergency Action

Notification (EAS) systems and ISM (Industrial, Scientific and Medical) applications.

They have a medium read range, medium data transfer rate, but are less able to permit

solids. While the medium frequency RFID systems are more orientation sensitive than

the low frequency system, they still do not require a line of sight between the reader

and the transponder.

High Frequency RFIDHigh frequency RFID (typically >900 MHz) is less acceptable internationally due to

licensing issues. These systems are available with operating ranges of 30 metres or

more. However, to obtain these ranges, high power levels are required. The ability of

these transponders to read through solids is very limited, and it is generally accepted

that a line of sight is required between the transponder and the reader unit. The

Page 12: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

advantage of the high frequency RFID systems is that they have very high data

transfer rates afforded to them by the very high carrier frequency.

3.2.2 ModulationTransfer of data between tags and a reader is wireless. Two modulation methods

distinguish and categorise RFID systems; one based upon close proximity

electromagnetic or inductive coupling, as shown in figure 2, and one based upon

propagating electromagnetic waves, as shown in figure 3. Coupling is via ‘antenna’

structures that form an integral feature in both tags and readers.

Electromagnetic couplingElectromagnetic couplings systems are systems in which a magnetic field is used as a

means of transferring data or power. Electromagnetic coupling techniques are

generally applied to RFID systems operating in the low to medium frequency bands,

with relatively short reading distances. Inductive coupling is basically a means of

conveying radio frequency energy via an oscillatory high frequency magnetic field.

The reader antenna loop and the tag coil windings establish a loosely connected

“space transformer” resulting in power transfer across short bidirectional reading

distances. Maximum power transfer between the reader antenna coil and the tag coil

occurs when the two coupled coils are placed or aligned in the same plane.

Page 13: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Figure 2: Electromagnetic coupling

Propagating Electromagnetic Waves

Figure 3.2: Propagating Electromagnetic waves

3.2.3 Types of RFID Tag

Page 14: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Tags are classified by the manner in which they derive their operating power, even

though the power levels required are invariably very small (micro to milli-watts).

Tags are either passive or active, the designation being determined entirely by the

manner in which the device derives its power.

Active Tags

An internal battery powers active tags. The use of a battery means that a sealed active

transponder has a finite lifetime. However, a suitable cell coupled to suitable low

power circuitry can ensure functionality for as long as ten or more years, depending

upon the operating temperatures, read/write cycles and usage. Active tags usually

send data back to the reader with power generated from the tag. The trade-off is

greater size and greater cost compared with passive tags.

Passive Tags

Passive tags operate without an internal battery, deriving the power to operate from

the magnetic field generated by the reader. Passive tags have shorter read ranges than

active tags and require a higher-powered reader. Passive tags are also constrained in

their capacity to store data and the ability to perform well in electromagnetically noisy

environments due to the fact that they don’t have a local power supply and are more

vulnerable to noise. However, passive tags offer advantages in terms of cost and life

span. They generally have much longer lifetime and are lower in price than active

transponders. Passive tags use modulated backscatter to communicate with the RFID

reader.

Page 15: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

3.3 RFID tag structure

The function of the tag is to respond to a request for the data it carries. Figure 4 shows

the basic structure of the RFID transponder, with its analogue front-end, coupled with

its back-end digital circuitry. The transponder memory may comprise Read-Only

Memory (ROM), Random Access Memory (RAM) and non-volatile programmable

memory for data storage depending upon the type and complexity of the device. The

non-volatile programmable memory is typically Electrically Erasable Programmable

Read Only Memory (EEPROM). It is used to store the transponder data and must be

non-volatile to ensure that the data is retained when the device is in its quiescent or

power-saving "sleep" state

Figure 4: Basic Structure of an RFID transponder

3.4 RFID reader structure

RFID readers are usually a microcontroller-based unit with a wound output coil, peak

detector hardware, comparators, and firmware to control the unit. The overall function

of an RFID reader is to provide the means of communicating with the tags and

facilitating data transfer. Functions performed by the reader may include quite

sophisticated signal conditioning, parity error checking and correction. Once the

Page 16: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

signal from a transponder has been correctly received and decoded, algorithms may

be applied to decide whether the signal is a repeat transmission, and may then instruct

the transponder to cease transmitting. This is known as the "Command Response

Protocol" and is used to circumvent the problem of reading multiple tags in a short

space of time. Using interrogators in this way is sometimes referred to as "Hands

Down Polling". An alternative, more secure, but slower tag polling technique is called

"Hands Up Polling" which involves the interrogator looking for tags with specific

identities, and interrogating them in turn. This is contention management, and a

variety of techniques have been developed to improve the process of batch reading. A

further approach may use multiple readers, multiplexed into one interrogator, but with

attendant increases in costs

3.5 rfid communication Active tags actually send data back to the reader with radio power derived from the

tags internally battery. Passive tags on the other hand, use modulated backscatter

(MBS) to respond to the reader’s request. Backscatter is a method of "reflecting" the

carrier wave and putting a signal into that reflection. Backscatter is achieved by

modulating the radar-cross section of the tag antenna. The tag modifies the reflected

wave by altering the tag feed-point impedance. This amplitude modulated reflected

wave hence communicates the data back to the reader as shown in figure 3.3.

Page 17: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Figure 3.3 RFID Communication through backscattering

Page 18: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

4. TECHNOLOGIES EMPLOYED IN THE SYSTEM

4.1 Linux

Linux is one of the most important operating systems worldwide due to its large

support base. UNIX was originally developed as a multi-tasking mainframe computer

operating system in the 1970s. Linux is a freely distributable version of UNIX

developed primarily by Linus Torvalds at the University of Helsinki in Finland. Linux

is a complete multitasking, multi-user operating system. The Linux kernel is known as

a monolithic kernel as opposed to a micro-kernel, in that all the device drivers are part

of the kernel. The Linux kernel is developed to use the special protected-mode

features of the Intel 80x86 processors. Linux also supports networking through two

primary networking protocols TCP (Transmission Control Protocol) and UUCP

(Unix-To-Unix Copy Protocol). Most TCP networks use Ethernet as the physical

network transport. Linux supports many popular Ethernet cards and interfaces for

personal computers. Linux has many advantages as a Web server- it runs for long

periods of without needing rebooting, and apache, the most popular Web server, runs

much better on Linux than on the Windows operating system. Apache is

automatically installed when you install most Linux distributions. Most distributions

of Linux now come with support for MySQL (my Structured Query Language) and

PHP (PHP: Hypertext Pre-processor) included. MySQL is a fast, easy to use

Relational Database Management System (RDBMS) very popular with Web

developers. PHP is a scripting language designed specifically for use on the Web.

Page 19: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

4.2 apache

Apache server is one of the most popular Web service applications. Apache is a

powerful, flexible, HTTP/1.1 compliant web server. It is highly configurable and

extensible with third-party modules. Users can further customise Apache by writing

modules using the Apache module. Apache implements the following features:

Database Management (DBM) databases for authentication that allows the

user to set up password-protected pages with large numbers of authorized

users, without bogging down the server.

Customized responses to errors and problems which allows you to set up files,

or even CGI scripts, which are returned by the server in response to errors and

problems

Unlimited flexible URL rewriting and aliasing meaning Apache has no fixed

limit on the numbers of Aliases and Redirects which may be declared in the

config files. In addition, a powerful rewriting engine can be used to solve most

URL manipulation problems.

Virtual Hosts which are often referred to as multi-homed servers. This allows

the server to distinguish between requests made to different IP addresses or

names (mapped to the same machine). Apache also offers dynamically

configurable mass-virtual hosting.

Apache can be configured to generate reliable piped logs, such as an error log.

In addition, on most UNIX architectures, Apache can send log files to a pipe,

allowing for log rotation, hit filtering, real-time splitting of multiple vhosts

into separate logs, and asynchronous DNS (Domain Naming Service)

resolving on the fly.

Page 20: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

4.3 MYSQL

Structured Query Language (SQL) is the de-facto standard programming language for

creating, updating and retrieving information that is stored in relational database

management system. A relational database is a database divided into logical units

called tables, where tables are related to one another within the database. A relational

database allows large complex data to be broken down into logical, smaller, more

manageable units. Tables are related to each other through a common key (data value)

in a relational database. SQL is a formal programming language. Speed was he

developer’s main focus when SQL was being developed.

MySQL is a fast easy to use RDMS. MySQL is easier to install and use than its

commercial competitors and the fact that MySQL is open source is strongly in its

favour. MySQL is available via the General Public License (GPU). MySQL consists

of a MySQL server, several utility programs that assist the administration of the

MySQL databases. MySQL’s main advantages include the following:

It is pre-packaged with most Linux distributions

.

It’s quite easy to use: you can interact with a MySQL database using a few

simple statements from the SQL language.

It’s very fast: MySQL’s developers’ main goal was speed; consequently the

software was designed from the beginning with speed in mind.

It’s free via the GNU General Public License.

Page 21: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

4.3 php

PHP is a scripting language designed specifically for use on the Web. PHP is a server-

side scripting language which was developed for dynamic Web sites and applications.

It is an embedded scripting language, which means that PHP code is embedded in

HTML code. PHP scripts can parse data submitted by HTML forms, communicate

with databases, and make complex calculations on the fly. PHP is very fast because

the freely available source code is compiled into the Apache Web server. A PHP

script is executed as part of the Web server process and requires no forking, often a

criticism of Common Gateway Interface (CGI) scripts. PHP interacts with the

database by invoking SQL commands, and displays the results in dynamically

generated Web pages. PHP provides the application part and MYSQL provides the

database part of a Web database application. PHP is used to move data into and out of

the MYSQL database. PHP is also suitable for more complicated tasks such as parsing

and verifying data that the user has entered into an HTML form. PHP’s advantages

include the following:

It’s free via the GNU General Public License (GPL).

It’s fast due to the fact that it’s embedded into the HTML code.

It’s designed to support databases including functionality designed to interact

with specific databases. It negates the need for the user to need to know the

technical details required to communicate with a database.

It’s quite easy to use in that it only contains elements of a programming

language needed to interact with a database and to generate dynamic web-

pages.

Page 22: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

4.4 VISUAL BASIC

4.4.1 Introduction

Visual Basic is currently one of the most widely used visual programming languages

used to develop stand-alone windows applications. Visual Basic allows for the rapid

development of custom designed applications modelled on the full range of window

features. Visual Basic provides for the building of very easy to use and intuitive user

interfaces. Using Visual Basic you can create quality user-interfaces by positioning

re-useable components directly into forms. Functionality is then added by linking

code to these components.

4.4.2 Advantages offered by Visual Basic

Visual Basic has many advantages that make it amenable for use in this project. The

advantages include the following:

Visual Basic as a programming language is relatively simple. Its structure is

quite straightforward.

The Visual Basic Integrated Development Environment (IDE) allows for

Rapid Application Development (RAD). It ideal for the development of

Graphical User Interfaces (GUI).

The online MSDM libraries provide a comprehensive interactive and context-

sensitive online help system.

Visual Basic is a component Integration language. It allows for the integration

of the Microsoft Component Object Model (COM). COM components can be

therefore embedded into your application’s user interface.

Page 23: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

5. Server-side setup and installation

5.1 Introduction

This chapter outlines the procedure involved in setting up a Linux web server. It

describes the general steps involved in the Linux installation, and the various modules

that need to be added.

5.2 Installation of Linux

5.2.1 Initial Installation ProcessThere are many companies offering different distributions of Linux. The Linux

distribution chosen fro this project was Red Hat Linux The installation of Red Hat

Linux is quite straightforward. Linux can be installed conveniently from a CD-ROM.

Red Hat Linux offers various installation configurations depending on the application

for which the machine is being used. The configuration chosen was “Server” as the

machine was to be used as a web-server. The installation options were chosen as

follows:

Hard-disk partitioning: Automatic Partitioning

Security options: High

Package Groups: GNOME and KDE (graphical desktops)

Account Configuration: Root password was entered and created new user:

king, password: fake_password

X configuration video card and monitor: Automatic

5.2.1 Post-Installation ConfigurationBefore working with Red Hat’s distribution of Linux, it is necessary to configure your

search path. This is to allow for the fact that Red Hat’s distribution of Linux does not

include the current directory. For example you compile a program called testProgram,

and you type testProgram, the shell returns an error saying the program could not be

Page 24: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

found. Without configuring the search path it becomes necessary to explicitly specify

the current directory i.e. to execute the program you need to type

. /testProgram

This can be easily fixed by editing the shell profile file

/root/.bash profile

and appending ‘.’ to the end of the line which sets PATH. You must log out before

this shell change takes effect.

5.3 Apache Installation and Configuration

5.3.1 InstallationThe installation of Apache is quite straight-forward. If Linux was installed with the

“server” configuration, Apache will be already installed. If Apache is not installed

automatically, it is necessary to download the Apache source code and compile the

code on your machine.

5.3.2 Apache ConfigurationApache can be configured almost entirely using the configuration file httpd.conf. This

file can be located in the /etc/httpd/conf directory. The contents of the configuration

file include the following settings

The ServerRoot setting indicates the top of the directory tree under which the server's

configuration, error, and log files are kept.

SERVERROOT "/ETC/HTTPD"

The Listen setting allows you to bind Apache to specific IP addresses and/or ports, in

addition to the default. In this case Apache is bound to the standard httpd port 80:

LISTEN 80

Extra modules have to be loaded using the “LoadModule” command, so the modules

functionality can be used. The PHP module is loaded below:

LOADMODULE PHP4_MODULE LIBEXEC/LIBPHP4.SO

Page 25: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

The document root setting specifies out of which directory you will server your

documents i.e. the directory in which your HTML (Hyper-Text Mark-up Language)

and PHP files are stored:

DOCUMENTROOT "/VAR/WWW/HTML"

ErrorLog is the location of the directory that will contain the error logs:

ERRORLOG LOGS/ERROR_LOG

The LogLevel setting controls the number of error messages sent to the error log:

LOGLEVEL DEBUG

5.3.2 Apache TestingIn order to test Apache, you must first start apache. To start apache type:

/ETC/RC.D/INIT.D/HTTPD START

To test if Apache is running properly type

MOZILLA HTTP://LOACLHOST If Apache is working properly you will be presented with an Apache test page.

5.4 MYSQL Installation

5.4.1 MySQL InstallationA MySQL Red Hat Package (RPM) can be used to install the RDBMS on a Linux

machine. The RPM for MySQL is usually located on the Red Hat installation disks.

The MySQL RPM is installed as follows:

Change to the directory to where you want MySQL to be installed. Save the

RPM into this directory. The directory should hold two files, similar to the

following:

MYSQL -4.23.45.-1.I386.RPM AND MYSQL-CLIENT-4.23.45-1.I186.RPM.

Install the RPM by typing the following:

Page 26: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

RPM –I MYSQL - 4.23.45.-1.I386.RPM MYSQL-CLIENT-4.23.45-1.I186.RPM.

These commands install the RPM packages. It creates the data directory as follows:

VAR/LIB/MYSQL

and sets the MySQL account and group name that you need. It starts the MySQL

server. Finally it edits the

/ETC/RC.D/INIT.D

file so that the MySQL server starts automatically at boot time.

5.4.2 MySQL TestingTo test MySQL type the following:

BIN/MYSQLADMIN –VERSION

This command should return the MySQL version number, provided MySQL is

functioning properly.

5.5 PHP installation and configuration

5.5.1 IntroductionThere are two methods of installing PHP. You can install it as a standalone interpreter

or as a module in Apache, depending on its intended application. In this case PHP is

used to interact with a database and create dynamic web pages, so it should be

installed as an Apache module. Before installing PHP, you must ensure the mod_so

apache module is installed, by typing the following command:

HTTPD -L

If mod_so is installed the following message will be displayed:

COMPILED IN MODULES:

Page 27: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

CORE.CPREFORK.CHTTP_CORE.CMOD_SO.C

5.5.2 InstallationThe following steps describe the installation process:

Download the PHP source code from PHP website

Save it to the appropriate directory

Unpack the tarball (similar to a zip file) file

Change to the new directory that was created.

Type the following command to configure PHP:

CONFIGURE –WITH-MYSQL –WITH-APX –ENABLE-TRANS-ID Type the following command:

MAKE

Type the following command:

MAKE INSTALL

5.5.3 ConfigurationIn order for Apache to recognise the PHP files, change have to me made to the

httpd.conf file. You must tell Apache what file types might contain PHP code. You

can do this by adding the following entry into the httpd.conf file:

ADDTYPE APPLICATION/X-HTTPD-PHP. PHP This tells Apache to expect PHP code in files with a .html or .php file extension

You must also tell apache to load the PHP module on start up.

LOADMODULE PHP4_MODULE LIBEXEC/LIBPHP4.SO.

5.5.4 TestingTo test PHP the following PHP file (test.php) was created:

</php

echo “PHP is working correctly”;

?>

Next save this file on the server. Point the browser at the test.php. PHP is

working properly if the “PHP is working correctly” string is displayed in the

browser window.

Page 28: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

6. VISUAL BASIC CLIENT APPLICATION

6.1 INTRODUCTIONThe client application has two main functions. It must interface with the RFID reader

and it must display the dynamically generated web pages sent from the server.

6.2 COMMUNICATION WITH THE RFID READER

6.2.1 IntroductionThe RFID reader used in this project is the Texas Instrument’s S6350 midrange

reader. This reader operates at a frequency of 13.56 MHz. The S6350 is designed to

operate in a host based reader system. It receives a command from the host and it

handles all the RF and digital functionality required in communicating with the RFID

tag. The communication between the host and the reader is over a serial cable (RS-

232). The host always initiates the communication between the host and the reader.

6.2.2 RFID reader serial protocol definitionThe RFID reader module communicates at the RS-232 level. Its baud rate can be set

to 9600, 19200, 38400 or 57600 baud. It uses 1 start bit, 8 data bits and no parity.

There are two types of packets, request and responses. A request packet is a command

sent from the host to the reader module. A response is the resulting answer sent from

the reader to the host. Every request has a corresponding response. The format of the

request packet is shown below.

6.2.2.1 Request packet format

Figure 6.1: Format of request packet1. Start of Frame: This one byte indicates the start of the frame. It should contain

the value 01hex

Page 29: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

2. Length: These two bytes describes the total length (in bytes) of the frame,

including the SOF byte.

3. Node Address: 2 bytes used for upward compatibility, always set to 0000hex

4. Command Flag: Significance of this byte depends on the contents of the

Command byte. The command byte combined with the command flag dictate

the action to be taken by the reader.

5. Command: This byte value, combined with the command flag dictates the

action to be taken by the reader.

6. Data: The size of the data bytes depends on the command because it contains

the parameters of the command.

7. BCC: These two bytes contain LRC check bits. These check bits are used to

validate the request when it arrives at the reader.

6.2.2.2 Response packet format

Figure 6.2: Format of response packet

1. Start of Frame: This one byte indicates the start of the frame. It should

contain the value 01hex

2. Length: These two bytes describes the total length (in bytes) of the frame,

including the SOF byte.

3. Node Address: 2 bytes used for upward compatibility, always set to

0000hex

4. Command Flag: Significance of this byte depends on the contents of the

Command byte. The command byte combined with the command flag

dictate the action to be taken by the reader.

5. Command: This byte value, combined with the command flag dictates the

action to be taken by the reader.

6. Data: The size of the data bytes depends on the command because it

contains the parameters of the command. Its length is between 0 and 23

bytes long.

Page 30: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

7. BCC: These two bytes contain LRC check bits. These check bits are used

to validate the request when it arrives at the reader.

6.2.2.3 Request commands The command is one byte in length. There are five possible commands, which are

described below:

Read Block (02hex): This command reads one block of data. If the address flag is not

set, then the data bytes just contain the block number to be read. If the address flag is

set, the address is read from the data section, as well as the block number.

Write Block (03 hex): This command writes one block of data. If the address flag is

not set then the data section just contains the block number and the data to be written.

If the address flag is set then the data section contains the address of the tag, the block

number and the data to be written.

Lock Block (04 hex): This command locks a single block of data. If the address flag is

not set, then the data section contains the block number to be locked. If the address

flag is set then the data section contains the address of the tag and the block number to

be locked.

Read Transponder Details (05 hex): This command reads the transponder details,

such as the transponder ID and the version number. If the address flag is not set, then

data section is clear. If the address flag is set then the data section contains the tag

address.

Special Read Block Command (0F hex): For this command the flag is not used. The

data section contains a single byte. This byte describes which blocks should be read.

If none of the bits in the data byte are set then the reader returns the SID of the tag.

6.2.2.4 Request Command FlagsThe command flags, coupled with the command, dictate what action the reader should

take.

Bits (0-3 and 5-7): These bits are reserved for future use, and should all be set to 0 by

default.

Bit 4: This is the address flag. If this bit is set, then the action is only performed on

the tag whose address matches that specified in the data section of the packet.

Page 31: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

6.2.2.5 Response Command FlagsThe command flags in the response packet are used solely for error checking.

Bits (0-3 and 5-7): These bits are reserved for future use and should not be set. These

bits should all be set to 0.

Bit 4: This is the error flag. If the flag is set then the request command contained

errors. The data section of the response packet contains the error code.

6.2.3 MSComm communication controlThe Visual Basic MSComm control provides an interface, through which one can

establish a connection to a serial port. The Visual Basic communication control

provides an API which allows the user to set and monitor properties and events of the

communications control. The API provides a high level of abstraction from the bit

level serial communication, making serial communication quite easy.

6.2.3.1 Initial MSComm setupThe first step in adding serial communication to the application is to add the

MSComm component to the application form. After adding the component it is

necessary to set the properties of the control:

'Initilise comm controlIf (MSComm1.PortOpen = False) Then 'if comm port isn't already open MSComm1.CommPort = 1 ' Port 1 is Comm1 MSComm1.Settings = "57600,N,8,1" 'baud rate = 57600, parity none,8 data bits, 1 stop bit MSComm1.PortOpen = True 'open the comm portEnd If

The MSComm setting sets the baud rate to 57600, the parity to none, the data bits to 8

and the stop bits to 1. It sets the COM port to 1 and opens the port for communication.

6.2.3.2 Reading the RFID tag numberBefore the Reader will read the tag and return the tag number, t must receive a read

request from the host. The read command must follow the request packet format

outline above:

Page 32: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

The process of creating and sending the command is as follows:

1. This command read block 1 of the RFID in non-addressable mode. The BCC

bits have to be calculated before the packet can be sent to the RFID reader.

The checkLRC function calculates the LRC bits and they are appended to the

original command string:

Call CheckLRC(sCmdString, sLRC) ’call function to calculate the check bits sTemp = sCmdString & sLRC 'reassemble string to be sent, by adding the LRCsCmdString = "" 'reset the command string

2. The checkLRC function is outlined below:

Public Sub CheckLRC(sCmdString, sLRC) ‘Declare the variables Dim LRC As Long Dim i As Integer Dim ByteVal As String Dim HNibble As Byte Dim LNibble As Byte Dim MSByte As String Dim LSByte As String Dim sTemp As String ' Start value LRC = &H0& 'The first step is to convert the string to decimal For i = 1 To Len(sCmdString) Step 2

' Step thru characters ' If the value is between A and F, i.e. between 10 and 16

If Mid$(sCmdString, i, 1) >= "A" And Mid$(sCmdString, i, 1) <= "F" Then

'get the first character, find its ansi code, 'minus 55 to get its decimal equivalent, and multiply by 16 'because its the upper nibble of the byte

HNibble = (Asc(Mid$(sCmdString, i, 1)) - 55) * 16 Else

'Otherwise if the value is between 0 and 9 'find its ANSI code, minus 48 to get its decimal equivalent 'and multiply by 16 because its the upper nibble of the byte

Page 33: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

HNibble = (Asc(Mid$(sCmdString, i, 1)) - 48) * 16 End If 'Get the next value ' If the value is between A and F, i.e. between 10 and 16

If Mid$(sCmdString, i + 1, 1) >= "A" And Mid$(sCmdString, i + 1, 1) <= "F" Then 'get the first character, find its ansi code,

'minus 55 to get its decimal equivalent

LNibble = (Asc(Mid$(sCmdString, i + 1, 1)) - 55) Else 'Otherwise if the value is between 0 and 9 'find its ANSI code, minus 48 to get its decimal equivalent

LNibble = (Asc(Mid$(sCmdString, i + 1, 1)) - 48)

End If 'Byteval holds the sum of the two nibbles (byteval is a decimal) ByteVal = (HNibble + LNibble) 'Perform XOR operation LRC = LRC Xor ByteVal Next i 'some string manipulation 'convert the LRC to hex sTemp = Hex(LRC) 'if the hex representation is only 1 hex character 'add a preceding "0" to the string and assign the new string to LSByte If Len(sTemp) = 1 Then

LSByte = "0" & sTemp

Else

'otherwise stemp to LSByte directly LSByte = sTemp

End If 'Assign MSByte as the 1's compliment of the LRC MSByte = Hex(LRC Xor &HFF) 'add a proceding "0" to the MSbyte string, if necessary If Len(MSByte) = 1 Then MSByte = "0" & MSByte End If 'append and assign the LSByte and MSByte to the sLRC sLRC = LSByte & MSByte

End Sub

3. The new command string is then converted to binary:

Page 34: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

‘take two characters at a timeFor i = 1 To Len(sTemp) Step 2

‘if character is between A and F‘convert to ANSI, minus 55 to get decimal,‘ then multiply by 16 because if the upper nibble

If Mid$(sTemp, i, 1) >= "A" And Mid$(sTemp, i, 1) <= "F" Then HNibble = (Asc(Mid$(sTemp, i, 1)) - 55) * 16 ‘if character is between 0 and 9‘convert to ANSI, minus 48 to get decimal,‘ then multiply by 16 because if the upper nibble

Else HNibble = (Asc(Mid$(sTemp, i, 1)) - 48) * 16 End If

‘if character is between A and F‘convert to ANSI, minus 55 to get decimal,

If Mid$(sTemp, i + 1, 1) >= "A" And Mid$(sTemp, i + 1, 1) <= "F" Then LNibble = (Asc(Mid$(sTemp, i + 1, 1)) - 55) Else

‘if character is between 0 and 9‘convert to ANSI, minus 48 to get decimal,

LNibble = (Asc(Mid$(sTemp, i + 1, 1)) - 48)

End If‘reconstruct command string sCmdString = sCmdString & Chr$(HNibble + LNibble) Next i

4. Send the command string and start a timer to wait for a response

' Initialise TIMEOUT timerlstartTime = Timer ‘Clear the receive buffer MSComm1.InBufferCount = 0 ' Specify binary data input MSComm1.InputMode = comInputModeBinary ' Input first 6 characters MSComm1.InputLen = 6‘Send command string to the reader MSComm1.Output = sCmdString ' Loop until 6 characters are received or 1 second has elapsed Do Until MSComm1.InBufferCount >= 6 Or ltimeNow > lstartTime + 1 DoEvents ltimeNow = Timer

Loop

Page 35: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

5. Get the response and convert it back to hex :

' Get response

Buffer = MSComm1.Input

' Assign Variant to Byte array

Aarray = Buffer

‘nTemp will hold the number of elements in the array

nTemp = UBound(Aarray)

If nTemp > 2 Then

' Convert to Hex

For i = 0 To (nTemp)

sHexChars = Hex$(Aarray(i))

‘If the length is 1, add a proceding 1

If Len(sHexChars) = 1 Then

sResponse = sResponse + ("0" & sHexChars)

Else

‘otherwise just add the sHexChars directly

sResponse = sResponse + sHexChars

End If

Next i

6. Get the rest of the response:

'Set up MSComm to get rest (nLength - 6) of response.

MSComm1.InputLen = nLength - 6

Do Until MSComm1.InBufferCount >= (nLength - 6) Or ltimeNow > lstartTime + 1

‘Do nothing and get the current time used in the DO loop for comparison

DoEvents

ltimeNow = Timer

Loop

' Assign Input buffer to variant Buffer

Buffer = MSComm1.Input

' Assign Buffer to array

Aarray = Buffer

' Find length of array (bytes)

nTemp = UBound(Aarray)

' Convert to Hex string

For i = 0 To (nTemp)

Page 36: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

sHexChars = Hex$(Aarray(i))

If Len(sHexChars) = 1 Then

' Add extra "0" to single hex chars

sResponse = sResponse + ("0" & sHexChars)

Else

‘otherwise assign sResponse directly

sResponse = sResponse + sHexChars

End If

Next i

7. To verify the response is error free call the checkLRC function:

' Calculate LCR Check

Call CheckLRC(Left$(sResponse, Len(sResponse) - 4), sLRC)

‘If the LRC is not ok, assign an error to sTag

If (sLRC <> Right$(sResponse, 4)) Then

sTag = " Bad Checksum"

Else

‘Otherwise assign sResponse to stag (no errors)

sTag = sResponse

End If

8. If the tag has been read and no errors have occurred then the string will have a

length of 30. If this is the case, extract the tag number from the response string

and assign it to the Tagnum variable:

‘if the response packet is the correct length, it contains no errors

If (Len(sTag) = 30) Then

'sTag is the string representation of the response

‘extract the 8 digit RFID tag number from the response string

TagNum = Mid(sTag, 15, 8)

End if

The RFID tag number has now been read and stored and can be used to reference

patient records within the web-based database. If the reader was unable to read the

tag, an error message will be displayed and the user must try to read the tag again.

Page 37: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

6.3 CLIENT LOGIN SYSTEMThe login system on the server-side simply takes the username and password, queries

the database, and links to the appropriate page depending on the query result. If the

user’s a doctor, it links to doctor.php, a nurse to nurse.php, the administrator to

admin.php and an unauthorised user to incorrectlogin.html. The client application

must present a login GUI (Graphical User Interface) where the user can enter their

login details:

The Visual Basic code must take the user name and password, pass them to the server

for querying, and then wait for a response from the server. The process is as follows:

Build a URL with the user name and password and send it to the server:

‘Initialise variables

Dim loginString As String

‘Build login URL encoding the username and password into the URL

loginString = "http://excelsior/~king/login.php" + "?" + "u=" + UserName + "&" + "p=" +

Password

‘Navigate the web-browser to the URL specified to verify login

Form1.WebBrowser1.Navigate (loginString)

Wait for 1 second to allow the server to query the database and link to the appropriate

page:

‘Initialise Variables

Dim lstartTime As Long

Dim ltimeNow As Long

lstartTime = Timer

‘loop until 1 second has passed

Do Until (ltimeNow > lstartTime + 1)

DoEvents

ltimeNow = Timer

Loop

Page 38: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Next, the web browser location URL to see which page it has been forwarded to, then

set the user variables:

‘Examine the web browser URL, if the browser has forwarded to doctor.php the user is

‘a doctor, if the browser has forwarded onto nurse.php the user is a nurse, etc.

If (Form1.WebBrowser1.LocationURL = "http://excelsior/~king/doctor.php") Then

‘set the usertype variable

‘set the login flag to true

‘hide the login dialog

‘call the login function

usertype = "doctor"

LoginSucceeded = True

Me.Hide

Call Login

End If

If (Form1.WebBrowser1.LocationURL = "http://excelsior/~king/nurse.php") Then

‘set the usertype variable

‘set the login flag to true

‘hide the login dialog

‘call the login function

usertype = "nurse"

LoginSucceeded = True

Me.Hide

Call Login

End If

If (Form1.WebBrowser1.LocationURL = "http://excelsior/~king/admin.php") Then

‘set the usertype variable

‘set the login flag to true

‘hide the login dialog

‘call the login function

usertype = "admin"

LoginSucceeded = True

Me.Hide

Call Login

End If

‘if the username and password are incorrect

If (Form1.WebBrowser1.LocationURL = "http://excelsior/~king/incorrectLogin.html") Then

Page 39: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

‘Present a message box saying the login was unsuccessful

MsgBox "Invalid Password, try again!", , "Login"

‘display the login dialog once again

Password.SetFocus

SendKeys "{Home}+{End}"

End If

End Sub

6.4 USER-TYPE SPECIFIC CONTROLSThe system must grant different privileges to different users when updating patient

information. The doctor should be allowed to update a patient’s diagnosis and basic

medical records. A nurse should be allowed to view, but not update the diagnosis and

basic medical records. A nurse should have sufficient privileges which allow the nurse

to update a patient’s daily observations.

This is achieved as follows:

The Visual basic code only displays the controls that should be used by the specific

user-type:

‘if the usertype is “doctor”, set up the doctors GUI

If (frmLogin.usertype = "doctor") Then

cmdUpdatePatientInfo.Visible = True

cmdGetInfo.Visible = True

PatientTag = TagNum

cmdReadTag.Visible = False

cmdCloseStay.Visible = False

End If

‘if the usertype is “nurse”, set up the nurses’ GUI

If (frmLogin.usertype = "nurse") Then

cmdGetInfo.Visible = True

cmdUpdatePatientInfo.Visible = True

PatientTag = TagNum

cmdReadTag.Visible = False

cmdCloseStay.Visible = False

End If

Page 40: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

‘if the usertype is “admin”, set up the administrators GUI

If (frmLogin.usertype = "admin") Then

cmdUpdatePatientInfo.Visible = True

cmdGetInfo.Visible = True

PatientTag = TagNum

cmdReadTag.Visible = False

cmdCloseStay.Visible = True

End If

6.5 UPDATING PATIENT INFORMATIONTo update medical details, the user must click the update button. They are then

presented with an update frame containing the following buttons:

Personal Details

Medical Details

Multimedia Details

Diagnosis

Page 41: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Nurses’ Observations (This is the only section which can be updated by

nurses)

When the button is clicked the web-browser’s URL is set to the appropriate address,

and the RFID tag number is encoded to the URL:

The appropriate web pages are displayed within the web-browser:

Private Sub UpdateMedicalDetails_Click()

‘Create a string containing the appropriate URL and encode the tag number into the

‘URL

Dim UrlString As String

UrlString = "http://excelsior/~king/MedicalDetailsForm.php" + "?" + "number=" +

TagNum

WebBrowser1.Navigate (UrlString)

‘Call a function to refresh the web-page

Call refreshWeb

End Sub

Page 42: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

6.6 VIEWING PATIENT INFORMATIONTo view medical details, the user must click the Get Patient Details button. They are

then presented with an viewing frame containing the following buttons:

Personal Details

Medical Details

Multimedia Details

Diagnosis

Nurses’ Observations

When the button is clicked the web-browser’s URL is set to the appropriate address,

and the RFID tag number is encoded to the URL:

Private Sub getMedicalDetails_Click()

‘Create a string containing the appropriate URL and encode the tag number into the

‘URL

Dim UrlString As String

UrlString = "http://excelsior/~king/RetrieveMedicalInfo.php" + "?" + "number=" +

TagNum

WebBrowser1.Navigate (UrlString)

‘call a function to refresh the web page

Call refreshWeb

End Sub

Page 43: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Page 44: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

7. PHP AND MYSQL DATABASE DEVELOPMENT

7.1 Introduction

PHP and MySQL are a natural combination for web-based database applications.

MySQL provides the database component, while PHP accesses the database and

generates dynamic web pages to interact with the user. The system must allow the

medical personnel to store and retrieve medical information. The system must allow

the medical personnel to view previous medical information. This led to the idea of a

hospital “stay” which would encompass all medical information relating to a patient

stay in a hospital. A stay is defined as the period of time between their first admission

and their eventual discharge. The basic structure of the stay object is defined below:

Figure 7.1 Patient Stay Object

Page 45: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

7.2 MySQL database setup

7.2.1 Information to be storedAfter determining what exactly the database should hold in chapter 2, the next step is

to design the database that holds the information needed by the application. The

design of the database includes identifying the data that you need to store and

organising in a manageable format.

7.2.2 Information to be storedThis section outlines what data should be held in the database. For this section it is

important to review the research completed. Apart from the basic medical details, it is

clear that some personal details relating to the patient must be stored. Personal details

such as:

First name

Last name

Address

Date of Birth

Phone Number

Comprehensive Medical Details of the patient as recorded by the doctor should be

stored, such as:

Presenting compliant

History of presenting complaint

Previous Medical history

Previous Surgical History

Other illnesses or surgery

Current medication

Any other conditions

Family Medical History

How many cigarettes does the patient smoke daily, if any?

Patient’s ability to perform daily tasks

Is the patient living alone?

Page 46: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Does the patient have any allergies?

Results of systems review?

X-ray results

Other test Results

The nurses’ daily observations should also be stored:

Pulse

Is the patient receiving oxygen, and if so, how much?

Fluid intake

Fluid output

Blood Pressure

Temperature

Is the patient diabetic? If so record the patient’s blood sugar level

Glasgow coma scale values (for neurological observations)

Page 47: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

7.2.3 Organising the informationData contained in a MySQL database must be organised into tables, since MySQL is a

Relational Database Management System (RDBMS). The first table is the database

contains the patient personal information. It contains the patients’ name, address etc.

The primary key or unique identifier in this table in the RFID tag number (shaded):

Figure 7.2: Personal Information table

The Medical Details table contains all the information recorded by the doctor. The

primary key for this table is the RFID Tag number:

Figure 7.3: Medical Details Table

The Nurses’ daily observations are held in a bale called NursesInfo. The primary key

for this table is the stay_session variable:

Figure 7.4: Nurses' Information Table

Page 48: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

7.2.4 Establishing the relationship between the data tablesAll the tables in this database hold data that is related. The personal details, medical

details and nurses’ observations all relate to a patient. Therefore it is very important

that the relationship between the various tables is well established. That is to say,

given the patient’s tag number, one should be able to find all information within the

database relating to the patient. This process is clearly outlined in the diagram below:

Figure 7.5: Relationship between MySQL tables

The advantage of this structure is that given an RFID tag number, we can use it as a

key to search for the patient’s personal records. We can also retrieve multiple medical

details records: medical details from previous stays and the current stay. By extracting

the stay_session identifier from the medical details, we can then extract the nurses’

Page 49: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

observations relating to that stay from the database. Therefore all records can be

accessed through one unique identifier, the RFID tag number.

7.2.5 Building the databaseBefore using MySQL you must first, setup the database and the tables held within that

database. You can start MySQL by typing the following command:

Mysql – u root –p fake_password

To create a database the flowing command:

CREATE DATABASE PATIENT_RECORDSBefore you can create a table, you must first select the database to use:

USE PATIENT_RECORDS;The personal Information table is created as follows:

CREATE TABLE PERSONALDETAILS (LASTNAME VARCHAR (50) NOT NULL,FIRSTNAME VARCHAR(50) NOT NULL,DATEOFBIRTH VARCHAR(20) NOT NULL,ADDRESS VARCHAR(100) NOT NULL,PHONE VARCHAR(15) NOT NULL,PATIENTID VARCHAR(8) NOT NULL,PRIMARY KEY(PATIENTID) ); THE MEDICAL DETAILS TABLE WAS CREATED AS WITH THE FOLLOWING COMMAND:CREATE TABLE MEDICALINFO (PRESENTCOMPLAINT TEXT,PRESENTCOMPLAINTHIS TEXT,PREVMEDHIS TEXT LL,PREVSURHIS TEXT,OTHERILLSUR TEXT,CURRENTMED TEXT,CIGARETTES VARCHAR(20),DAILYTASKS TEXT,ALONE VARCHAR(5),ALLERGIES TEXT,SYSTEMSREVIEW TEXT, FMHISTORY TEXT NOT NULL,PICTUREURL VARCHAR(100),VIDEOURL VARCHAR(100),X-RAYURL VARCHAR(100), STAY_STATUS VARCHAR(8) NOT NULL,SESSION VARCHAR(10) NOT NULL,DATE VARCHAR(30) NOT NULL,ID VARCHAR(8) NOT NULL,PRIMARY KEY(ID) );

Page 50: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Apart from the medical information held in the database, there is also information to

ensure the database is relational. The unique identifier is the id. The id is the 8 digit

number held on the RFID patient tag. With this number, you can find the patient’s

personal and medical details. The stay_status variable indicates whether this record

belongs to a patient’s current stay in hospital. If the stay_status variable is true, then

these records belong to the patient’s current stay in hospital. If stay_status is false,

then these records belong to the patient’s previous stay in hospital. The date variable

holds the date when the patient’s stay began. The session variable is a unique session

identifier. A patient may have multiple “stays” in hospital associated with them. Each

stay has a unique 10 digit session number. Using this session number, we can find the

nurses’ observations associated withy that stay, as shown in the diagram below:

Figure 5.6 : Relational structure of the database

The nurse’s observations database is setup as follows:

CREATE TABLE NURSESINFO (

Page 51: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

PULSE VARCHAR(5),OXYGEN VARCHAR(5),OXYGENAMT VARCHAR(10),FLUIDIN VARCHAR(10),FLUIDOUT VARCHAR(10),BP VARCHAR(10),TEMPERATURE VARCHAR(10),DIABETIC VARHCAR(10),BLOODSL VARCHAR(10),EYEOPENING VARCHAR(10),VERBALRESPONSE VARCHAR(10),MOTORRESPONSE VARCHAR(10),TOTAL VARCHAR(10),STAY_SESSION VARCHAR(10) NOT NULL,DATE VARCHAR(20) NOT NULL,NURSE_SESSION VARCHAR(10),PRIMARY KEY(NURSE_SESSION));

Here the stay_session variable is used to find the nurses’ observations associated with

a particular stay. The nurses_session variable is used to differentiate between the

different nurses’ observation entries. The database is now established and ready to be

used

7.3 PHP

7.3.1 Application of PHPPHP is used to interact with the MySQL database and to generate dynamic web pages.

In this application, PHP has a variety of functions:

It manages user-login

It deals with the uploading of patient information.

It handles the querying of the database, and generates dynamic web pages to

display the results

In the following section, the use of PHP in the system will be shown, along with the

key algorithms used.

7.3.2.1 User login verificationIn order to verify the user the system has to compare the username and password with

the USERS table in the MySQL database. The username and password are sent to the

server encoded in to the URL as follows:

Page 52: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

http://excelsior/~king/login.php?u=OhalloranJim&p=fakePassword

1. PHP extracts the username and password from the URL as follows:

$user = $_GET['u'];

$pass = $_GET['p'];

2. Connect to and select the database:

//set database variables, like the name of the host, the user , the password and

//database name

$dbHost = 'localhost';

$dbUser = 'root';

$dbPass = 'pearmouse817';

$dbDatabase = 'PATIENTS_RECORDS';

//Connect to the database

$db = mysql_connect("$dbHost", "$dbUser"," $dbPass") or die ("DEBUG:Error

connecting to database.");

//select the correct database

mysql_select_db("PATIENT_RECORDS", $db) or die ("DEBUG:Couldn't select the

database.");

3. Query the database to see if the username and password are correct:

‘Query the database and store the results on $result

$result=mysql_query("SELECT * FROM USERS WHERE username='$user' AND

password='$pass'", $db);

//check that at least one row was returned

$rowCheck = mysql_num_rows($result);

4. If the user was found, establish what type of user it is, and go to the corresponding

PHP page:

//if their username and password match

if($rowCheck > 0){

//get the first row returned (there should only be one row returned anyway)

$row = mysql_fetch_array($result);

‘If the user is a nurse, go to nurse.php

if ($row['usertype']== 'nurse')

{

header( "Location: nurse.php" );

}

‘If the user is a doctor, go to doctor.php

else if( $row['usertype']== 'doctor')

{

header( "Location: doctor.php" );

Page 53: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

}

‘If the user is the administrator, go to admin.php

Else

{

header( "Location: admin.php" );

}

}

//Otherwise if there username and password are incorrect

Else

{

//redirect to incorrectLogin.php

header( "Location: incorrectLogin.html" );

}

The code will forward an unauthorised user to incorrectlogin.html .This code will

forward a user of type nurse to nurse.php, a doctor to doctor.php, an administrator to

admin.php. The client application can then decipher from the new URL what is the

user type, and so display the appropriate Graphical User interface (GUI).

7.3.2.2 Uploading Patient Personal InformationThe code for uploading the patient personal information is contained in two files, a

HTML file which contains a form where the user can input the data, and a PHP file

which parses the data and inserts it into the database,. The HTML code is as described

below:

Indicate the name of the PHP file that will handle the post:

<form method="post" action="PersonalDetailsUL.php">

Get the patient’s first name:

<b><font size="4">First Name</font></b> input type="Text" name="firstname"

value=" " size="20"></p>

Get the patient’s last name

<b><font size="4">Last Name:<input type="Text"

name="lastname" value=" " size="20"></p>

Get the patient’s address

<b><font size="4">Address: <input type="Text"

name="address" value=" " size="20"></p>

Page 54: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Get the patient’s phone number

<b><font size="4">Phone Number: <input type="Text" name="phone" value=" "

size="20"><br>

Get the patient’s date of birth

<font size="4">Date of Birth: </font>

<input type="Text" name="phone1" value=" " size="20"></p>

<p align="center"><br>

Submit the information to the PHP file for processing

<Input type="Submit" name="submit" value="Enter information" style="float: left">

The PHP code is as follows:

Start a PHP session (a session is a way of storing and retrieving variable values in

PHP)

<?php

session_start();

?>

Connect to the database (as described earlier)

Get the variables from the HTML page

//The request function retrieves the variables posted from the previous

$firstname = $_REQUEST['firstname'];

$lastname = $_REQUEST['lastname'];

$address = $_REQUEST['address'];

$phone = $_REQUEST['phone'];

Get the patient’s ID from the session variable

//retrieve the Patient Id number as stored earlier as a session variable

$id = $_SESSION["id"];

Check if a record of this patient already exists

//query the database with the ID number

$sql = "SELECT * FROM PersonalDetails WHERE id = $id";

$result=mysql_query($sql);

‘Assign returned record to $row variable

$row = mysql_fetch_array($result);

‘Get the ID of the returned record

$temp = $row['id'];

//if the two Ids don’t match, no medical details relating to the patient exist

Page 55: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

if($temp!=$id)

If no record exists, create a new record in the personal details table

{

//Create a new entry in the personal Details table

$sql = "INSERT INTO

PersonalDetails(firstname,lastname,id,address,phone)VALUES('$firstname','$lastname','$id','$

address','$phone')";

$result=mysql_query($sql);

}

Otherwise, update the existing record

//Otherwise, if a personal details entry already exist, simply update the existing records

else

{

$sql = "UPDATE PersonalDetails SET firstname= '$firstname', lastname = '$lastname',

address = '$address',phone = '$phone' WHERE id = '$id'";

$result=mysql_query($sql);

}

7.3.2.3 Uploading Patient Medical Details The process for uploading patient Medical details is quite similar to the uploading

personal details. Due to the amount of data to be uploaded, the form is spread across

two HTML pages. Notable excerpts from the first page are shown below:

The Patient ID is taken from the URL and stored as a session variable

<?php

//start a PHP session and store the patient tag number retrieved from the URL

session_start();

$_SESSION["id"]= $_GET['number'];

?>

The form links you onto the second upload page

<form method="post" action="MedicalDetailsForm2.php">

The form code is similar to the last example except since the amount of test is larger,

textareas are used instead

//Get the patient’s previous surgical history

Previous Surgical History: <textarea name="SurHistory" value=" " rows="2"

cols="36"></textarea></p>

Page 56: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

<p align="center"><font size="5"><br>

<input type="Submit" name="submit" value="Next Page"> </p>

In the second page the variables from the first page are retrieved and stored as session

variables

<?php

//start a PHP session

session_start();

//Retrieve the variables posted from the previous page

//and store them as session variables

$pc = $_REQUEST['present&complaint'];

$_SESSION["pc"]=$pc;

$pcH = $_REQUEST['p&cHistory'];

$_SESSION["pcH"]=$pcH;

$MedHis = $_REQUEST['MedHistory'];

$_SESSION["MedHis"]=$MedHis;

$SurHis = $_REQUEST['SurHistory'];

$_SESSION["SurHis"]=$SurHis;

$FMHistory = $_REQUEST['FMHistory'];

$_SESSION["FMHistory"]=$FMHistroy;

$Cigarettes = $_REQUEST['Cigarettes'];

$_SESSION["Cigarettes"]=$Cigarettes;

$dailyTasks = $_REQUEST['dailyTasks'];

$_SESSION["dailyTasks"]=$dailyTasks;

$alone = $_REQUEST['alone'];

$_SESSION["alone"]=$alone;

?>

This page presents the user with another HTML form, to allow the user to upload the

rest of the medical details. The PHP code for uploading the data must have the

following functionality:

Page 57: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

It must check to see if an “open stay” exists (i.e. if the current open record

exists for the patient)

If an open stay exists, it must update the existing record.

If an open stay doesn’t exist, it must create a new Medical details record, and

assign it a new session id number.

The code is as follows:

Connect to the database (as described earlier)

Get the session variables stored earlier:

//assign the session variables to local variables

$id = $_SESSION["id"];

$pc = $_SESSION["pc"];

$pcH = $_SESSION["pcH"];

$MedHis = $_SESSION["MedHis"];

$SurHis = $_SESSION["SurHis"];

$alone = $_SESSION["alone"];

$dailyTasks = $_SESSION["dailyTasks"];

$Cigarettes = $_SESSION["Cigarettes"];

$FMHistory = $_SESSION["FMHistory"];

Get the variables posted from the previous page and other required variables

//Retrieve the variables posted from the previous page ( the second HTML form)

$illsur = $_REQUEST['ill/sur'];

$meds = $_REQUEST['medication'];

$conditions = $_REQUEST['other Conditions'];

$Allergies = $_REQUEST['Allergies'];

$systemsReview = $_REQUEST['systemsReview'];

//Initialise other variables

$date = date("FY");

$stay_status = "true";

$updateFlag = "";

If an open session relation to this patient already exists update that record

//Find all medical records relating to this patient

$sql = "SELECT * FROM MedicalInfo WHERE id = $id";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

//loop thru returned "stays" until you find an open one

while($updateFlag!='true' AND $row = mysql_fetch_array($result))

{

//extract first row//

Page 58: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

extract($row);

//check to see if an open stay exists

if($row['id']=$id && $row['stay_status']!= 'false')

{

//found an open "stay" and update it

//build the SQL query

$sql = "UPDATE MedicalInfo SET presentcomplaint= '$pc', presentcomplaintHis = '$pcH',

prevMedHis = '$MedHis',pervSurHis = '$SurHis', otherIllSur = '$illSur', currentMed =

'$meds', otherConditions = '$conditions',FMHistory = '$FMHistory', Cigarettes =

'$Cigarettes',dailyTasks = '$dailyTasks',alone = '$alone', Allergies =

'$Allergies',SystemsReview = '$systemsReview' WHERE id = '$id' AND stay_status =

'$stay_status'";

//execute the query

$result=mysql_query($sql);

//set the update flag

$updateFlag = "true";

}

If an open record doesn’t, create a new record. The first step is to create a random

number for the session identifier

//create a random number to identify the "stay" session

srand(date("s"));

$randNumber= rand()% 9999999999;

//query the database to see if the session number already exists

$sql = "SELECT * FROM MedicalInfo WHERE session = $randNumber";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

//check that at least one row was returned

$rowCheck = mysql_num_rows($result);

if($rowCheck == 0)

{

//do nothing, random number hasn't been used before

}

else //find a new random number that hasn't been used before

{

while($rowChecks != 0)

$randNumber= rand()% 9999999999;

$sql = "SELECT * FROM MedicalInfo WHERE session = $randNumber";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

Page 59: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

//check that at least one row was returned

$rowCheck = mysql_num_rows($result);

}

The next step is to create a new entry in the table with the new session identifier. This

achieved as follows:

//if the database hasn’t been updated

if($updateFlag!="true")

{

$stay_status = "true";

//Create a new open "stay"

//build the SQL Query

$sql = "INSERT INTO

MedicalInfo(presentcomplaint,presentcomplaintHis,prevMedHis,pervSurHis,otherIllSur,

currentMed,otherConditions,id,stay_status,date,FMHistory,Cigarettes,dailyTasks,alone,Allerg

ies,SystemsReview,session)VALUES('$pc','$pcH','$MedHis','$SurHis','$illsur','$meds','$condi

tions','$id','$stay_status','$date','$FMHistory','$Cigarettes','$dailyTasks','$alone','$Allergies','$s

ystemsReview','$randNumber')";

//execute the SQL query

$result=mysql_query($sql);

//store the session variable

session_register("session");

$session = $randNumber;

}

7.3.2.4 Uploading the doctor’s diagnosisThe diagnosis can only be uploaded if there is an open stay associated with the

patient. The system must check to see if an open stay exists, and is an open stay does

exist, the diagnosis will be updated. However if an open stay for the patient doesn’t

exist the system will create a new stay, filling in only the necessary fields of the

database table. The diagnosis is entered through a HTML form. The main parts of the

PHP code are described below:

Start a PHP session

<?php

//start the PHP session

session_start();

?>

Page 60: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

Get the diagnosis from the HTML page, and the patient ID as stored in the session

variables

//Get the ID as stored in the session variable

$id = $_SESSION["id"];

//Get the Doctor’s diagnosis as posted in the previous HTML form

$diagnosis = $_REQUEST["diagnosis"];

Try to find an existing open stay. If one is found update the diagnosis entry in the

medical details table

$sql = "SELECT * FROM MedicalInfo WHERE id = $id";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

//loop thru returned for until you find an open one

while($updateFlag!='true' AND $row = mysql_fetch_array($result))

{

//extract first row//

extract($row);

//check to see if an open stay exists

if($row['id']=$id && $row['stay_status']!= 'false')

{

//found an open "stay" and update it

$sql = "UPDATE MedicalInfo SET Diagnosis = '$diagnosis' WHERE id = '$id' AND

stay_status = '$stay_status'";

$result=mysql_query($sql);

$updateFlag = "true";

}

}

Otherwise create a new record. This involves creating a unique random number for

the session (as described in earlier code) and making a new medical details record

with the new diagnosis

//If the database has been updated earlier

if($updateFlag!="true")

{

//set stay_status = true, since you want to create an open stay

$stay_status = "true";

//Create a new open "stay" using the random number create earlier as a session

//identifier

Page 61: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

$sql = "INSERT INTO MedicalInfo(Diagnosis,id,

stay_status,session)VALUES('$diagnosis','$id','$stay_status','$randNumber');

$result=mysql_query($sql);

//save session variable

session_register('session');

$session = $randNumber;

}

7.3.2.5 Uploading Multimedia informationThe database will also hold multimedia such as patient x-rays, video and pictures. The

multimedia files will be uploaded to a folder on the server, and the medical details

table will hold the URL (Universal Resource Locator) pointing to the file.

The code for uploading the multimedia file consists of a HTML form and a PHP file.

The HTML code includes the following:

This HTML code allows the user to browse through their documents to find the file

for uploading; it also specifies the maximum size of files

<input type = "hidden" name = MAX_FILE_SIZE" value ="300000"/><b><font size="4">X-Ray</font><font size="4"> of Patient</font></b><input name = "userxray" type = "file" size="20" /> <br>

upload.php then handles the uploading of the file to the server. The process is outlined

below:

Set the upload directory and the file name (The file name will be the session variable)

$uploadDir = '/home/king/public_html/uploads/picture/';

$uploadFile = $uploadDir.$session;

Next store the URL to the file in the database. If an open stay exists update the URL

entry. If an open stay doesn’t exist, create one and fill in the URL string

while($updateFlag!='true' AND $row = mysql_fetch_array($result))

{

//extract first row//

extract($row);

//check to see if an open stay exists

if($row['id']=$id && $row['stay_status']!= 'false')

{

//found an open "stay" and update it

$sql = "UPDATE MedicalInfo SET Xray = '$uploadFile'

WHERE id = '$id' AND stay_status = '$stay_status'";

$result=mysql_query($sql);

$updateFlag = "true";

Page 62: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

}

}

//if the database hasn’t been updated (ie. if no open stay exists, create a new one)

if($updateFlag!="true")

{$stay_status = "true";

//Create a new open "stay" using the random number created earlier as a session

//identifier

$sql = "INSERT INTO MedicalInfo(Xray,id,

stay_status,session)VALUES('$uploadFile','$id','$stay_status','$session');

$result=mysql_query($sql);

}

Next upload the file to the server

move_uploaded_file($_FILES['userpicture']['tmp_name'], $uploadFile)

The process is repeated for all the multimedia files to be uploaded to the server.

7.3.2.6 Retrieving patient personal informationThe code for displaying personal details has two functions; it must query the database

to find all the personal details relating to the patient, and it must build a dynamic web-

page to display the results:

Get the patient’s ID from the URL

//Get the patient tag number from the URL

$id = $_GET['number'];

Connect to the database (see previous code)

Query the personal details table of the database and display the results

//Display patient's lastname

$sql = "SELECT lastname FROM PersonalDetails where id = '$id'";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

echo "<h2>Lastname:</h2> <h3>{$row['lastname']}</h3><br>";

//Display patient's firstname

$sql = "SELECT firstname FROM PersonalDetails where id = '$id'";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

Page 63: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

echo "<h2>Firstname:</h2> <h3>{$row['firstname']}</h3><br>";

//Display patient's address

$sql = "SELECT address FROM PersonalDetails where id = '$id'";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

echo "<h2>Address:</h2> <h3>{$row['address']}</h3><br>";

7.3.2.7 Display Medical DetailsThe procedure for displaying medical details is a very similar. It’s just a process of

querying the database and displaying the results as shown in the code segment below:

//Display the patient’s presenting complaint

$sql = "SELECT presentcomplaint FROM MedicalInfo where id = '$id' AND stay_status =

'true'";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

echo "<h2>Presenting Complaint:</h2> <h3>{$row['presentcomplaint']}</h3><br>";

//Display history of Presenting Complaint

$sql = "SELECT presentcomplaintHis FROM MedicalInfo where id = '$id' AND stay_status =

'true'";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

echo "<h2>History of Presenting Complaint:</h2>

<h3>{$row['presentcomplaintHis']}</h3><br>";

7.3.2.8 Retrieval and display of nurses’ observationsThe retrieval of nurses’ observations is slightly more complicated than the retrieval of

medical or personal information. When a patient is in hospital, nurses’ observations

are taken every day. Therefore every stay object is associated with many nurses’

observations. The process of displaying nurses’ observations is two fold. The first step

involved generating a web page which contains a list of hyperlinks to the individual

nurses’ observations:

Find an open stay relating to the patient in the medical records table

//Find an open stay in the Medical Details table

$sql = "SELECT * FROM MedicalInfo WHERE id = $id AND stay_status = 'true'";

Page 64: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

If an open record is found, extract its session number, and then search the nurses

information table for that session number

//check that at least one row was returned

$rowCheck = mysql_num_rows($result);

//if at least one record was returned

if($rowCheck > 0){

extract($row);

//Get the medical records session number

$Stay_session= $row 'session'];

//search nursesInfo table for that session number

$sql = "SELECT * FROM NursesInfo WHERE Stay_session = $Stay_session";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

Finally generate a web page with hyperlinks to the individual nurses’ observation

//code loops thru the returned nurses sessions

extract($row);

//Build a URL with the nurse’s session number encoded into it

$url = "http://excelsior/~king/RetrieveObs.php?";

$temp = 'Nurses_session=';

$date = $row['date'];

$Nurse_session = $row['Nurse_session'];

$url = $url.$temp.$Nurse_session;

//Display the date as the hyperlink

echo '<h2><a href='.$url.'>'.$date.'</a></h2>';

echo '<br><br>';

A list of hyperlinks is created, displayed to the user as a list of dates, but actually links

to a page that will display the individual nurses’ observations. It also passes the

nurses’ session number to the retrieval page.

Each hyperlink links to retrieveObs.php. This PHP page extracts the nurses’ session

number from the URL

//Get the Nurses’ session number from the URL

$Nurse_session = $_GET["Nurses_session"];

It the extracts and displays the nurses’ observation details as follows:

//pulse rate

Page 65: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

$sql = "SELECT pulse FROM NursesInfo where Nurse_session = $Nurse_session";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

echo "<h2>Pulse Rate:</h2> <h3>{$row['pulse']}</h3><br>";

//Is the patient receiving oxygen

$sql = "SELECT oxygen FROM NursesInfo where Nurse_session = $Nurse_session";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

echo "<h2>Is the patient receiving oxygen:</h2> <h3>{$row['oxygen']}</h3><br>";

7.3.2.9 Retrieving and displaying Multimedia dataMultimediaInfo.php displays a page that contains links to the patient’s x-ray, picture

and video. The first step is to find an open stay

//Find an open stay in the MedicalInfo table relating to the Patient ID

$sql = "SELECT * FROM MedicalInfo WHERE id = '$id' AND stay_status = '$stay_status'";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

The hyperlinks are generated as follows:

//This code converts the URLS from type

//home/king/public_html/uploads/pic1

//to http://excelsior/~king/uploads/pic1

$arr1 = explode("/", $row['Xray']);

$temp1 = $arr1[4].'/'.$arr1[5].'/'.$arr1[6];

$arr2 = explode("/", $row['Picture']);

$temp2 = $arr2[4].'/'.$arr2[5].'/'.$arr2[6];

$arr3 = explode("/", $row['Video']);

$temp3 = $arr3[4].'/'.$arr3[5].'/'.$arr3[6] ;

$xrayUrl = 'http://excelsior/~king/'.$temp1;

$pictureUrl = 'http://excelsior/~king/'.$temp2;

$videoUrl = 'http://excelsior/~king/'.$temp3 ;

echo '<h2><a href='.$xrayUrl.'> Patient X-Ray</a></h2>';

Page 66: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

echo '<br><br>';

echo '<h2><p><a href='.$pictureUrl.'> Patient picture</a></p><h2>';

echo '<br><br>';

echo '<h2><p><a href='.$videoUrl.'> Patient Video</a></p><h2>';

7.3.2.10 Displaying Past medical recordsA very important feature of this system is that it allows medical personnel to view a

patient’s previous medical records. Again the process is two fold. Firstly, a page is

generated with a list of hyperlink to all the patient’s previous records

Find all the closed records. Generate hyperlinks with the individual session numbers

appended to the URL

//Find all close entries in the MedicalInfo table relating to the patient’s ID

$sql = "SELECT * FROM MedicalInfo WHERE id = $id AND stay_status = 'false'";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$rowCheck = mysql_num_rows($result);

//loop thru returned records

while($row = mysql_fetch_array($result))

{

extract($row);

//build a hyperlink to the retrieveRecord page, encoding the session number into the

//URL

$url = "http://excelsior/~king/RetrieveRecords.php?";

$temp = 'session=';

$date = $row['date'];

$session = $row['session'];

$url = $url.$temp.$session.'&id='.$id;

//Display the date as the Hyperlink text

echo '<h2><a href='.$url.'>'.$date.'</a></h2>';

echo '<br><br>';

}

RetrieveRecords.php extracts the Stay session number form the URL

//Get the session number from the URL

$session = $_GET["session"];

It then searches for that session number in the medical records tables, and displays the

results:

//Presenting complaint

Page 67: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

$sql = "SELECT presentcomplaint FROM MedicalInfo where id = '$id' AND stay_status =

'false' AND session = '$session'";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

echo "<h2>Presenting Complaint:</h2> <h3>{$row['presentcomplaint']}</h3><br>";

//Display history of Presenting Complaint

$sql = "SELECT presentcomplaintHis FROM MedicalInfo where id = '$id' AND stay_status =

'false' AND session = '$session'";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

echo "<h2>History of Presenting Complaint:</h2>

<h3>{$row['presentcomplaintHis']}</h3><br>";

//Display previous Medical History

$sql = "SELECT prevMedHis FROM MedicalInfo where id = '$id' AND stay_status = 'false'

AND session = '$session'";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$row = mysql_fetch_array($result);

echo "<h2>Previous Medical History:</h2> <h3>{$row['prevMedHis']}</h3><br>";

It displays links to x-rays, pictures and videos relating to the patient’s previous stay

//The picture URL is just the $url variable plus the session number

$url = "http://excelsior/~king/uploads/picture/";

$url = $url.$session;

$temp = "Picture of the Patient";

echo '<h2><a href='.$url.'>'.$temp.'</a></h2>';

echo '<br><br>';

//The same is true for the x-rays and video

$url = "http://excelsior/~king/uploads/xray/";

$url =$url.$session;

$temp = "X-ray of the Patient";

echo '<h2><a href='.$url.'>'.$temp.'</a></h2>';

echo '<br><br>';

$url = "http://excelsior/~king/uploads/video/";

$url = $url.$session;

$temp = "Video of the Patient";

Page 68: RFID PATIENT TAGGING AND DATABASE SYSTEM

RFID Patient Tagging and Database System April 2004

echo '<h2><a href='.$url.'>'.$temp.'</a></h2>';

echo '<br><br>';

Finally it displays links to all the nurses’ observations relating to the patient’s stay in

hospital, giving a complete record of the patient’s previous stay.

$sql = "SELECT * FROM NursesInfo WHERE Stay_session = $session";

$result = mysql_query($sql) or die("Debug: Couldn't execute query");

$rowCheck = mysql_num_rows($result);

while($row = mysql_fetch_array($result))

{

extract($row);

$url = "http://excelsior/~king/RetrieveObs.php?";

$temp = 'Nurses_session=';

$date = $row['date'];

$Nurse_session = $row['Nurse_session'];

$url = $url.$temp.$Nurse_session;

echo '<h2><a href='.$url.'>'.$date.'</a></h2>';

echo '<br><br>';

}