Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/12/08 07:34:55 (4 months ago)
Author:
dkayiwa
Message:

xforms module: upgrading to use 1.2.04 version of the openmrs api

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/xforms/trunk/src/org/openmrs/module/xforms/DefaultPatientSerializer.java

    r3055 r4171  
    11package org.openmrs.module.xforms; 
    2  
    32 
    43import java.io.DataInputStream; 
    54import java.io.DataOutputStream; 
    65import java.io.IOException; 
    7 import java.util.*
     6import java.util.List
    87 
    98import org.apache.commons.logging.Log; 
     
    1514 
    1615/** 
    17  * Provides default serialization of patients to clients. 
    18  * This class is used when sending a list of patients to clients like 
    19  * mobile devices that may want to collect patient data in for instance offline mode. 
     16 * Provides default serialization of patients to clients. This class is used 
     17 * when sending a list of patients to clients like mobile devices that may want 
     18 * to collect patient data in for instance offline mode. 
    2019 *  
    21  * For those who want a different serialization format for patients, 
    22  * just implement the SerializableData interface and specify the class 
    23  * using the openmrs global property {xforms.patientSerializer}.  
    24  * The jar containing this class can then be 
    25  * put under the webapps/openmrs/web-inf/lib folder. 
    26  * One of the reasons one could want a different serialization format 
    27  * is for performance by doing a more optimized and compact format. 
    28  * Onother reason i can foresee is for non java clients who may say 
    29  * want the patients in xml or any other format, because the default 
    30  * implementation assumes java clients. 
     20 * For those who want a different serialization format for patients, just 
     21 * implement the SerializableData interface and specify the class using the 
     22 * openmrs global property {xforms.patientSerializer}. The jar containing this 
     23 * class can then be put under the webapps/openmrs/web-inf/lib folder. One of 
     24 * the reasons one could want a different serialization format is for 
     25 * performance by doing a more optimized and compact format. Onother reason i 
     26 * can foresee is for non java clients who may say want the patients in xml or 
     27 * any other format, because the default implementation assumes java clients. 
    3128 *  
    3229 * @author Daniel 
    33  * 
     30 *  
    3431 */ 
    35 public class DefaultPatientSerializer implements SerializableData
     32public class DefaultPatientSerializer implements SerializableData
    3633 
    3734        private Log log = LogFactory.getLog(this.getClass()); 
    38          
    39          
    40         public DefaultPatientSerializer(){ 
    41                  
     35 
     36        public DefaultPatientSerializer() { 
     37 
    4238        } 
    4339 
     
    4541         * Serializes a patient to the stream. 
    4642         *  
    47          * @param patient - the patient to serialize. 
    48          * @param dos  - the stream to write to. 
     43         * @param patient - 
     44         *            the patient to serialize. 
     45         * @param dos - 
     46         *            the stream to write to. 
    4947         */ 
    50         protected void serialize(Patient patient, DataOutputStream dos)
    51                 try
     48        protected void serialize(Patient patient, DataOutputStream dos)
     49                try
    5250                        SerializationUtils.writeInteger(dos, patient.getPatientId()); 
    53                          
     51 
    5452                        PersonName personName = patient.getPersonName(); 
    5553                        SerializationUtils.writeUTF(dos, personName.getPrefix()); 
     
    5957                        SerializationUtils.writeUTF(dos, patient.getGender()); 
    6058                        SerializationUtils.writeDate(dos, patient.getBirthdate()); 
    61                          
    62                         if(patient.getPatientIdentifier() != null) 
    63                                 SerializationUtils.writeUTF(dos, patient.getPatientIdentifier().toString()); 
     59 
     60                        if (patient.getPatientIdentifier() != null) 
     61                                SerializationUtils.writeUTF(dos, patient.getPatientIdentifier() 
     62                                                .toString()); 
    6463                        else 
    6564                                dos.writeBoolean(false); 
    66                                                  
    67                         dos.writeBoolean(false); //flag to tell whether this is a new patient or not. 
    68                 } 
    69                 catch(IOException e)
     65 
     66                        dos.writeBoolean(false); // flag to tell whether this is a new 
     67                                                                               // patient or not. 
     68                } catch (IOException e)
    7069                        log.error(e); 
    7170                } 
    7271        } 
    73          
     72 
    7473        /** 
    75          * @see org.openmrs.module.xforms.SerializableData#serialize(java.io.DataOutputStream, java.lang.Object) 
     74         * @see org.openmrs.module.xforms.SerializableData#serialize(java.io.DataOutputStream, 
     75         *      java.lang.Object) 
    7676         */ 
    77         public void serialize(DataOutputStream dos,Object data)
    78                 try
    79                         if(data == null) 
     77        public void serialize(DataOutputStream dos, Object data)
     78                try
     79                        if (data == null) 
    8080                                return; 
    81                         PatientData patientData = (PatientData)data; //data will always be a patient data. 
    82                          
    83                         List<Patient> patients = patientData.getPatients();  
    84                         if(patients == null || patients.size() == 0) 
     81                        PatientData patientData = (PatientData) data; // data will always 
     82                                                                                                                        // be a patient 
     83                                                                                                                        // data. 
     84 
     85                        List<Patient> patients = patientData.getPatients(); 
     86                        if (patients == null || patients.size() == 0) 
    8587                                return; 
    86                          
     88 
    8789                        dos.writeInt(patients.size()); 
    88                         for(Patient patient : patients) 
    89                                 serialize(patient,dos); 
    90                          
    91                         List<PatientTableField> fields = patientData.getFields();  
    92                         if(fields == null || fields.size() == 0) 
     90                        for (Patient patient : patients) 
     91                                serialize(patient, dos); 
     92 
     93                        List<PatientTableField> fields = patientData.getFields(); 
     94                        if (fields == null || fields.size() == 0) 
    9395                                return; 
    9496                        dos.writeByte(fields.size()); 
    95                         for(PatientTableField field : fields)
     97                        for (PatientTableField field : fields)
    9698                                dos.writeInt(field.getId()); 
    9799                                dos.writeUTF(field.getName()); 
    98100                        } 
    99                          
    100                         List<PatientTableFieldValue> fieldVals = patientData.getFieldValues();  
    101                         if(fieldVals == null || fieldVals.size() == 0) 
     101 
     102                        List<PatientTableFieldValue> fieldVals = patientData 
     103                                        .getFieldValues(); 
     104                        if (fieldVals == null || fieldVals.size() == 0) 
    102105                                return; 
    103106                        dos.writeInt(fieldVals.size()); 
    104                         for(PatientTableFieldValue fieldVal : fieldVals)
     107                        for (PatientTableFieldValue fieldVal : fieldVals)
    105108                                dos.writeInt(fieldVal.getFieldId()); 
    106109                                dos.writeInt(fieldVal.getPatientId()); 
    107110                                dos.writeUTF(fieldVal.getValue().toString()); 
    108111                        } 
    109                          
    110                 }catch(IOException e)
     112 
     113                } catch (IOException e)
    111114                        log.error(e); 
    112115                } 
    113116        } 
    114          
     117 
    115118        /** 
    116          * @see org.openmrs.module.xforms.SerializableData#deSerialize(java.io.DataInputStream, java.lang.Object) 
     119         * @see org.openmrs.module.xforms.SerializableData#deSerialize(java.io.DataInputStream, 
     120         *      java.lang.Object) 
    117121         */ 
    118         public Object deSerialize(DataInputStream dis,Object data){ 
    119                 return null; //not necessary for now because patients come back as xforms. 
     122        public Object deSerialize(DataInputStream dis, Object data) { 
     123                return null; // not necessary for now because patients come back as 
     124                                                // xforms. 
    120125        } 
    121126}