Back to project page sana.
The source code is released under:
Copyright (c) 2010, Moca All rights reserved. The source code for Moca is licensed under the BSD license as follows: Redistribution and use in source and binary forms, with or without modification, ...
If you think the Android project sana listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.moca.db; /*w w w . j a v a2s . c o m*/ import java.util.Calendar; import java.util.List; import org.moca.procedure.Procedure; import org.moca.procedure.ProcedureElement; import org.moca.procedure.ValidationError; import android.util.Log; public class PatientValidator { private static final String TAG = PatientValidator.class.toString(); public static boolean validate(Procedure p, PatientInfo pi) throws ValidationError { boolean result = true; //patient authentication checks for existing patients if (p.current().hasSpecialElement()) { if (!validateSpecialElements(p, pi)) { return false; } } return result; } public static void populateSpecialElements(Procedure p, PatientInfo pi) { if (pi == null || !pi.isConfirmed() || !p.current().hasSpecialElement()) { return; } List<ProcedureElement> specialElements = p.current().getSpecialElements(); for (ProcedureElement element : specialElements) { String id = element.getId(); if (pi != null) { element.setAnswer(pi.getAnswerForId(id)); } } } private static boolean validateSpecialElements(Procedure p, PatientInfo pi) throws ValidationError { List<ProcedureElement> specialElements = p.current().getSpecialElements(); if (pi == null) pi = new PatientInfo(); for (ProcedureElement el : specialElements) { String element_id = el.getId(); String element_answer = el.getAnswer().trim().toLowerCase(); if (element_id.equals("patientId")) { } else if (element_id.equals("patientFirstName")) { } else if (element_id.equals("patientLastName")) { } else if (element_id.equals("patientGender")) { } else if (element_id.equals("patientBirthdateMonth")) { String year = p.current().getElementValue("patientBirthdateYear"); try { int yearValue = Integer.parseInt(year); int currentYear = Calendar.getInstance().get(Calendar.YEAR); Log.i(TAG, "Validating year: " + yearValue + " against " + currentYear); if (yearValue > currentYear || yearValue < currentYear-120) { throw new ValidationError("The year entered is not valid (in the future or too far in the past). Please try again."); } } catch (Exception e) { throw new ValidationError("The year entered is not a number. Please enter a number."); } } } return true; } }