1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
| import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;
import javax.microedition.rms.RecordStoreNotOpenException;
public class GestionDesPatients extends MIDlet implements CommandListener {
private Form formSaisiePatient;
private List listePatients;
private static TextField txtID;
private static TextField txtPrenom;
private static TextField txtNom;
private static DateField dateNais;
private Ticker tickerPub;
private Command cmdSauvegarder;
private Command cmdLister;
private Vector vPatients;
private Vector vListePatients;
private int n;
private String[] elements;
private Command cmdDetails;
private Command cmdBack;
private Form infoPatients;
private Command cmdBack2;
private static RecordStore bd;
private static ChoiceGroup cgGroupeSanguin;
private static ChoiceGroup cgSexe;
private static TextField txtMaladieFamiliale;
private static TextField txtAntecedantMedical;
public GestionDesPatients() {
// Formulaire de saisie d'informations du patient
formSaisiePatient = new Form (" Gestion Des Patients");
tickerPub = new Ticker("Bienvenue sur le portail des patients...");
formSaisiePatient.setTicker(tickerPub);
txtID = new TextField("ID : ","",6,TextField.NUMERIC);
formSaisiePatient.append(txtID);
txtPrenom = new TextField("PRENOM : ","",15,TextField.ANY);
formSaisiePatient.append(txtPrenom);
txtNom = new TextField("NOM : ","",15,TextField.ANY);
formSaisiePatient.append(txtNom);
dateNais = new DateField("Date Of Birth : ",DateField.DATE);
formSaisiePatient.append(dateNais);
// Liste de choix du groupe sanguin
String[] labelGrpSanguins = {"A","B","O"};
Image[] GroupOfImages = new Image[3];
try {
Image a = Image.createImage("/icones/A.png"), b = Image.createImage("/icones/B.png"), o = Image.createImage("/icones/O.png");
GroupOfImages [0] = a;
GroupOfImages [1] = b;
GroupOfImages [2] = o;
} catch (IOException e) {
e.printStackTrace();
}
cgGroupeSanguin = new ChoiceGroup ("Groupes sanguins",Choice.POPUP, labelGrpSanguins, GroupOfImages);
formSaisiePatient.append(cgGroupeSanguin);
// Liste de choix du sexe
String[] label = {"Masculin","Feminin"};
Image[] imgGroup = new Image[2];
try {
imgGroup[0] = Image.createImage("/icones/m.jpg");;
imgGroup[1] = Image.createImage("/icones/f.jpg");
} catch (IOException e){
e.printStackTrace();
}
cgSexe = new ChoiceGroup("Sexe : ",Choice.POPUP,label,imgGroup);
formSaisiePatient.append(cgSexe);
txtMaladieFamiliale = new TextField("Maladie Familiale : ","",1000,TextField.ANY);
formSaisiePatient.append(txtMaladieFamiliale);
txtAntecedantMedical = new TextField("Antecedant Medical : ","",1000,TextField.ANY);
formSaisiePatient.append(txtAntecedantMedical);
cmdSauvegarder = new Command("SAUVER",Command.SCREEN,0);
formSaisiePatient.addCommand(cmdSauvegarder);
cmdLister = new Command("LISTER",Command.SCREEN,0);
formSaisiePatient.addCommand(cmdLister);
formSaisiePatient.setCommandListener(this);
// Liste des patients enrégistrés
vListePatients = new Vector ();
vListePatients = recupererLesPatients(vListePatients);
n = vListePatients.size(); int i=0;
while (i<n) {
Patient p = (Patient) vListePatients.elementAt(i);
elements [i] = p.getNom();
i++;
}
listePatients = new List("Liste Des Patients", List.IMPLICIT ,elements ,null);
cmdDetails = new Command("Détails", Command.ITEM, 0);
cmdBack = new Command("Retour", Command.ITEM, 0);
listePatients.setSelectCommand(cmdDetails);
listePatients.setSelectCommand(cmdBack);
listePatients.setCommandListener(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
chargerLesPatientsDansLaBD (bd , vPatients);
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
// Display.getDisplay(this).setCurrent(formSaisiePatient);
// Display.getDisplay(this).setCurrent(formSaisiePatient);
try {
if (bd.getNumRecords() == 0) {
Display.getDisplay(this).setCurrent(formSaisiePatient);
}
} catch (RecordStoreNotOpenException e) {
e.printStackTrace();
}
try {
if (bd.getNumRecords() != 0) {
Display.getDisplay(this).setCurrent(listePatients);
}
} catch (RecordStoreNotOpenException e) {
e.printStackTrace();
}
}
public static Date StringToDate(String s)
{
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(s.substring(0, 2)));
c.set(Calendar.MONTH, Integer.parseInt(s.substring(3, 5)) - 1);
c.set(Calendar.YEAR, Integer.parseInt(s.substring(6, 10)));
return c.getTime();
}
public static Vector recupererLesPatients (Vector lesP) {
int incrementation = 1, temoin=1;
String id, prenOm, noM, dateNaiss, gSg, sex, malH, antM;
Date dateN;
try {
//RecordStore.openRecordStore("BD_Patients", false);
while (incrementation < bd.getNumRecords()) {
Patient p;
if (temoin == 1) {
id = bd.getRecord(incrementation).toString();
prenOm = bd.getRecord(incrementation+=1).toString();
noM = bd.getRecord(incrementation+=1).toString();
dateNaiss = bd.getRecord(incrementation+=1).toString();
gSg = bd.getRecord(incrementation+=1).toString();
sex = bd.getRecord(incrementation+=1).toString();
malH = bd.getRecord(incrementation+=1).toString();
antM = bd.getRecord(incrementation+=1).toString();
dateN = StringToDate(dateNaiss);
p = new Patient (id, prenOm, noM, dateN, gSg, sex, malH, antM);
lesP.addElement(p);
}else if (temoin != 1) {
id = bd.getRecord(incrementation).toString();
prenOm = bd.getRecord(incrementation+=1).toString();
noM = bd.getRecord(incrementation+=1).toString();
dateNaiss = bd.getRecord(incrementation+=1).toString();
gSg = bd.getRecord(incrementation+=1).toString();
sex = bd.getRecord(incrementation+=1).toString();
malH = bd.getRecord(incrementation+=1).toString();
antM = bd.getRecord(incrementation+=1).toString();
dateN = StringToDate(dateNaiss);
p = new Patient (id, prenOm, noM, dateN, gSg, sex, malH, antM);
lesP.addElement(p);
}
incrementation++;
temoin++;
}
} catch (RecordStoreFullException e) {
e.printStackTrace();
} catch (RecordStoreNotFoundException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
}
return lesP;
}
public static Vector putItInTheInVector (Vector v) {
Patient pat = new Patient(txtID.getString(), txtPrenom.getString(), txtNom.getString(), dateNais.getDate(), cgGroupeSanguin.getString(cgGroupeSanguin.getSelectedIndex()), cgSexe.getString(cgSexe.getSelectedIndex()), txtMaladieFamiliale.getString(), txtAntecedantMedical.getString());
v = new Vector ();
v.addElement(pat);
return v;
}
public static RecordStore chargerLesPatientsDansLaBD (RecordStore db, Vector v) {
try {
db = RecordStore.openRecordStore("BD_Patients", false);
//0 id - 1 prenom
int iter = 0;
while(iter < v.size()){
Patient pat = (Patient) v.elementAt(iter);
db.addRecord(pat.getId().getBytes(), 0, pat.getId().getBytes().length);
db.addRecord(pat.getPrenom().getBytes(), 0, pat.getPrenom().getBytes().length);
db.addRecord(pat.getNom().getBytes(), 0, pat.getNom().getBytes().length);
db.addRecord(pat.getDateNaiss().toString().getBytes(), 0, pat.getDateNaiss().toString().getBytes().length);
db.addRecord(pat.getGroupeSanguin().getBytes(), 0, pat.getGroupeSanguin().getBytes().length);
db.addRecord(pat.getSexe().getBytes(), 0, pat.getSexe().getBytes().length);
db.addRecord(pat.getMaladieFamiliale().getBytes(), 0, pat.getMaladieFamiliale().getBytes().length);
db.addRecord(pat.getAntecedantMedical().getBytes(), 0, pat.getAntecedantMedical().getBytes().length);
iter++;
}
db.closeRecordStore();
} catch (RecordStoreFullException e) {
e.printStackTrace();
} catch (RecordStoreNotFoundException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
}
return db;
}
public void commandAction(Command arg0, Displayable arg1) {
if(arg0 == cmdSauvegarder){
vPatients = putItInTheInVector(vPatients);
// On écrit dans la base de données
bd = chargerLesPatientsDansLaBD (bd, vPatients);
// Alert
Alert message = new Alert ("Données sauvées !");
Display.getDisplay(this).setCurrent(message, formSaisiePatient);
}
// Pour lister, il faut que la base de données contienne des éléments
try {
if ((arg0 == cmdLister) && (bd.getNumRecords() != 0)) {
Display.getDisplay(this).setCurrent(listePatients);
} else if ((arg0 == cmdLister) && (bd.getNumRecords() == 0)) {
// Alert
Alert message = new Alert ("Base de données est vide !");
Display.getDisplay(this).setCurrent(message, formSaisiePatient);
}
} catch (RecordStoreNotOpenException e) {
e.printStackTrace();
}
if (arg0 == cmdDetails) {
infoPatients = new Form ("Informations Patient");
Vector vListePatient = new Vector ();
vListePatient = recupererLesPatients(vListePatient);
Patient p = (Patient) vListePatient.elementAt(listePatients.getSelectedIndex());
StringItem id = new StringItem ("iD : ", p.getId());
infoPatients.append(id);
StringItem prenom = new StringItem ("Prénom : ", p.getPrenom());
infoPatients.append(prenom);
StringItem nom = new StringItem ("Nom : ", p.getNom());
infoPatients.append(nom);
StringItem birthdate = new StringItem ("Date Of Birth : ", p.getDateNaiss().toString());
infoPatients.append(birthdate);
StringItem grpSang = new StringItem ("Groupe Sanguin : ", p.getGroupeSanguin());
infoPatients.append(grpSang);
StringItem sexe = new StringItem ("Sexe : ", p.getSexe());
infoPatients.append(sexe);
StringItem malaFamil = new StringItem ("Maladie(s) Familiale(s) : ", p.getMaladieFamiliale());
infoPatients.append(malaFamil);
StringItem antMedicaux = new StringItem ("Antécédant(s) Médical(aux) : ", p.getAntecedantMedical());
infoPatients.append(antMedicaux);
cmdBack2 = new Command ("Retour",Command.BACK,0);
infoPatients.addCommand(cmdBack2);
infoPatients.setCommandListener(this);
Display.getDisplay(this).setCurrent(infoPatients);
}
if (arg0 == cmdBack) {
Display.getDisplay(this).setCurrent(formSaisiePatient);
}
if (arg0 == cmdBack2) {
Display.getDisplay(this).setCurrent(listePatients);
}
}
} |
Partager