HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

I expect great things from Enterprise JavaBeans this year, one of which is dominating the e-business front as the component model of choice for server-side application development.

Giving House Calls a New Meaning
E-business is multifaceted, encompassing e-commerce (monetary transactions over the Internet), business-to-business solutions and internal Web-based applications that provide flexibility and innovation in the services companies offer. E-business innovation has improved customer care and fostered repeat business for companies like Amazon.com, Dell and numerous online investment sites, to name a few.

However, early last year I was fascinated by the story a friend told me about her father, a radiologist from Boston, who used e-business technology to provide an extremely valuable solution to his customer, a patient with a fractured leg. During a visit to her home, my friend's father received a request on his cell phone for his opinion on a patient. He logged onto the hospital's Web site with his daughter's laptop and diagnosed the fracture by viewing X-rays over the Web!

This article provides a similar demonstration of the value of e-business above and beyond e-commerce. And if you had any doubts, the e-business solution I provide in this month's EJB Home, Acme HealthCare's e-Patient, is based on the following technologies: Enterprise JavaBeans and Java servlets. E-Patient is by no means industrial strength, but it's been developed with techniques not yet covered in EJB Home, such as EJB Handles and stateful session beans. I'll also provide ideas that I'll address appropriately in a future article on how to improve the application in the areas of robustness and performance.

Acme HealthCare's E-Patient Requirements Overview
The doctors at Acme HealthCare wanted the ability to enter and review patient information - even diagnose patients - by way of the Internet. In particular, doctors who had practices spanning multiple hospitals needed to be able to perform an initial "distributed" diagnosis from one location, then finish the patient assessment once they arrived at the hospital where the patient was located. Two use cases were modeled to cover usage of the e-Patient application (see Figure 1):

  1. Enter Patient Info
  2. Diagnose Patient

Figure 1
Figure 1:

In Enter Patient Info the actor is either a nurse or a doctor. He or she enters the patient's history into the Patient Information Form and submits it. The next use case, Diagnose Patient, involves the doctor's entering a diagnosis and submitting it.

If a nurse was the actor in the Enter Patient Info use case, he or she must call the doctor to say that a patient record needs to be reviewed. The doctor who receives the call pulls up the patient record in a browser to make the initial diagnosis, which provides an avenue for others to treat the patient until the doctor arrives.

Acme HealthCare's E-Patient Technical Overview
The Java platform has all the necessary elements to solve the business requirements. The technical solution presented below specifically involves Enterprise JavaBeans with view and controller responsibilities handled in Java servlets. Included in the design are a simple static HTML form (see Figure 2) and a servlet that processes the submitted data. The current design doesn't include a database, but I'll discuss this below, along with other ideas for design improvements.

Figure 2
Figure 2:

At the heart of the system is the PatientSessionBean, a session bean that contains patient information and business logic. The bean is deployed as a stateful session bean to allow a client to access it multiple times without losing state between requests. Code for the enterprise bean component is given in Listings 1, 2 and 3 (remote interface, home interface and session bean, respectively).

An interesting feature of a stateful session bean is its ability to be passivated and activated by its container for memory and performance reasons. After a period of time has passed between client calls, the EJB container will store all nontransient, serializable attributes of the PatientSessionBean in some form of temporary persistent storage. This is usually just a file, but could be more robust depending on the container implementation. The next time the client calls the bean, the EJB container will allocate memory for the enterprise bean and service the request, a process called activation. Since the bean instance has been stored, a handle is used to return the bean to the active instance pool. EJB Handle objects are found through the EJBObject interface method getHandle(). Storing Handle objects can be done either persistently through serialization or you can just hold onto them in memory, as seen in Listing 4 of the PatientTrackSessionServlet.

While a session bean isn't meant to live beyond a hardware or software failure, passivation does provide a pseudopersistent environment that allows EJB servers to handle higher volumes of users in a stateful server architecture.

User Interface
The entry point into e-Patient for the nurse actor in Enter Patient Info is the Patient Information Form, a static HTML form for entering information about the patient. When submitted, however, a Java servlet, as indicated in the tag, processes it:

<form method=POST action="http://vergetg1:7001/PatientTrackSessionServlet">

The tag is hard-coded to access my machine, probably not the best idea for a production application, but feel free to download the source code from www.JavaDevelopersJournal.com and modify it to suit your needs.

Once our Web server receives the HTTP request for submission, the PatientTrackSessionServlet processes it by parsing the form parameters and potentially modifying or creating a new PatientSessionBean. PatientTrackSession.java is not listed in full here.

The PatientTrackSessionServlet (see Listing 4) is multithreaded (e.g., a singleton servlet) and uses a hashtable to handle synchronization issues when multiple clients access it concurrently. It uses the hashtable patientCache to hold instances of javax.ejb.Handle, representing currently tracked PatientSessionBeans (active or passivated).

Implementing the Enter Patient Info Use Case
When a nurse or doctor submits the patient information to the system, the PatientTrackSessionServlet takes the patient information from the HttpRequest object, then checks to see if the patient is already entered into the system by checking the patientCache for a valid Handle object. If the patient isn't in the system, a new patient is created with the submitted information, and else use case, Diagnose Patient, is executed (see Listing 4).

Implementing the Diagnose Patient Use Case
In this use case the patient's doctor is validated and the diagnosis is updated. Currently, only the patient's doctor has access to the patient's records. When the patient information is submitted and the patient currently exists, the Handle object referring to the PatientSessionBean is used to get a proxy to the session bean.

patient = (Patient)handle.getEJBObject(); // get EJBObject from handle

If the session bean had been passivated during this time, the container would activate it and return a proxy (EJBObject) of the component. Considering that a valid EJBObject is returned, the diagnosis is updated accordingly when the Web page is submitted.

The stateful session bean solution solves our business requirement of allowing a doctor to enter an initial diagnosis, then return to the patient record to update it once more information is known. The technical implementation of e-Patient is adequate to show some nice features of EJB such as Handles and stateful session beans. There is room for improvement, however. Let's look at some enhancements that could be made to this e-business solution.

Feature Enhancements
Our e-business solution for patient care has a number of areas in its business requirements and technical solution that could be improved. Patient confidentiality and data security are important in health care, so business requirements restricting access to patient records should be better defined. A login process should be implemented to prevent unauthorized users from accessing the system. Likewise, EJB's support of Access Control Lists (ACLs) could be used to restrict access in a role-based manner. For instance, nurses may have the ability to enter patient information but not make a diagnosis.

Also, stateful session beans are perhaps not the best solution for keeping patient records. They should be stored instead in a database to prevent loss of data in the event of a system failure.

Last, servlets are important in a Web-enabled Java application, but JavaServer Pages (JSPs) are increasingly taking precedence over servlet development.

JSPs improve productivity by allowing HTML developers to script the user interface of the application while Java developers plug in Java code where needed. Migrating the servlets in our solution to JSPs would be an evolutionary move toward future productivity gains.

I'll expand this solution in a future article to include some of the new features discussed and cover more interesting areas of EJB in the process.

This month we explored the topic of e-business with Enterprise JavaBeans. We covered EJB Handles, accessing enterprise beans from a servlet and the possibility of designing stateful server architectures based on stateful session beans.

The Java platform provides a foundation to build complex Web solutions. When core business processes become e-business enabled, employees perform their jobs more efficiently, bringing value to other employees, suppliers and customers alike. For example, the added value that an e-business solution brings could be the difference between life and death!

Author Bio
Jason Westra is a managing partner with Verge Technologies Group, Inc., a Java consulting firm specializing in Enterprise JavaBeans solutions.
He can be reached at: [email protected].


Listing 1: 

package PatientTrackSession; 

import java.rmi.RemoteException; 
import java.util.Vector; 
import javax.ejb.EJBObject; 

 *  Patient is the remote interface representing a stateful 
 *  session bean, PatientSessionBean. 
public interface Patient extends EJBObject 
    public String getDoctor() throws RemoteException; 
    public boolean isDoctor(String aDoctor) throws RemoteException; 
    public void setName(String aName) throws RemoteException; 
    public String getName() throws RemoteException; 
    public void setDOBirth(String aDOB) throws RemoteException; 
    public String getDOBirth() throws RemoteException; 
    public void setGender(String aGender) throws RemoteException; 
    public String getGender() throws RemoteException; 
    public void setAllergies(Vector aAllergies) throws RemoteException; 
    public Vector getAllergies() throws RemoteException; 
    public void setLastVisitDate(String aLVD) throws RemoteException; 
    public String getLastVisitDate() throws RemoteException; 
    public void setDiagnosis(String aDiagnosis) throws RemoteException; 
    public String getDiagnosis() throws RemoteException; 

Listing 2: 

package PatientTrackSession; 

import javax.ejb.EJBHome; 
import javax.ejb.CreateException; 
import java.rmi.RemoteException; 

public interface PatientHome extends EJBHome 
    public Patient create(String aDoctorName) throws Create 
    Exception, RemoteException; 

Listing 3: 

package PatientTrackSession; 

import javax.ejb.SessionBean; 
import java.util.Vector; 
import java.rmi.RemoteException; 
import javax.ejb.SessionContext; 
import javax.ejb.CreateException; 

public class PatientSessionBean implements SessionBean 
    // Business Attributes 
    private String doctor; 
    private String name; 
    private String DOBirth; 
    private String gender; 
    private Vector allergies; 
    private String lastVisitDate; 
    private String diagnosis; 
    // Business Methods 
    public String getDoctor() { 
        return doctor; 
    public boolean isDoctor(String aDoctor) { 
        if (aDoctor == null) 
            return false; 
        String curDoctor = this.getDoctor(); 
        return curDoctor.equalsIgnoreCase(aDoctor); 
    public void setName(String aName) { 
        name = aName; 
    public String getName(){ 
        return name; 

 public void setDOBirth(String aDOB) { 
        DOBirth = aDOB; 
    public String getDOBirth() { 
        return DOBirth; 
    public void setGender(String aGender) { 
        gender = aGender; 
    public String getGender(){ 
        return gender; 
    public void setAllergies(Vector 
    aAllergies) { 
        allergies = aAllergies; 
    public Vector getAllergies() { 
        return allergies; 
    public void setLastVisitDate(String 
    aLVD) { 
        lastVisitDate = aLVD; 
    public String getLastVisitDate() { 
        return lastVisitDate; 
    public void setDiagnosis(String 
    aDiagnosis) { 
        diagnosis = aDiagnosis; 
    public String getDiagnosis() { 
        return diagnosis; 
    // These method(s) satisfy the Ses- 
    // sionBean interface contract 
    private transient SessionContext ctx; 
    public void ejbCreate(String aDoctor) 
        throws CreateException, Remote- 
        doctor = aDoctor; 
    public void setSessionContext(Ses- 
    sionContext aCtx) { 
        ctx = aCtx; 
    public void ejbActivate() { 
    public void ejbPassivate() { 
    public void ejbRemove() { 

Listing 4: 

// get parameters from HttpRequest above… 

// check to see if servlet has handle   // to the patient yet 
        handle = (Handle)patient 
        if (handle == null) { 
            patient = newPatient(name, 
            doctor, gender, dateOfBirth, 
            dateOfLastVisit, allergies, 
            // add patient's handle to cache 
        else { 
            // if patient already 
            // exists in servlet 
            // cache, get his/her 
            // latest diagnosis from 
            // the doctor. 
            System.out.println("Patient: "+name+" handle found on cache."); 
            patient = (Patient)handle- 
            .getEJBObject(); // get 
            EJBObject from handle 
            if (patient != null) { 
                // only same doctor 
                // can make diagnosis 
                if (patient.isDoctor(doctor)) { 
                else { 
                    are not authorized 
                    to modify Patient 
            else { 
                System.out.println("no EJBObject for handle"); 
                out.println("ERROR: Could not find patient!"); 


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.