Search in sources :

Example 1 with Patient

use of trial.Patient in project project1-ICS372 by sandip-rai.

the class AddPatientActivity method onClickAddToPatientList.

/**
 * Adds the patient to the Patient List in the Clinical Trial
 * Method assigned to buttonAddPatientToList
 * @param view the current view
 */
public void onClickAddToPatientList(View view) {
    // Grab the editText field where the user enters the patientId
    EditText editTextPatientId = (EditText) findViewById(R.id.editTextAddPatientId);
    // Get the patientId
    String patientId = editTextPatientId.getText().toString();
    if (patientId == null || patientId.equals("")) {
        // make sure the user has entered a  patient ID
        makeToast("Please enter a patient ID");
    } else if (clinicalTrial.addPatient(patientId)) {
        Patient p = clinicalTrial.findPatient(patientId);
        p.setState(new PatientStateActive(p));
        makeToast("Added! Ready for next patient!");
        editTextPatientId.setText("");
    } else {
        makeToast("That patient is already in this trial.");
    }
}
Also used : EditText(android.widget.EditText) PatientStateActive(trial.PatientStateActive) Patient(trial.Patient)

Example 2 with Patient

use of trial.Patient in project project1-ICS372 by sandip-rai.

the class ButtonAddReadingListener method actionPerformed.

/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
@Override
public void actionPerformed(ActionEvent e) {
    // Get the new entered values
    Patient patient = (Patient) guiController.getMainMenuView().getComboBoxPatients().getSelectedItem();
    String readingType = (String) guiController.getMainMenuView().getComboBoxReadingType().getSelectedItem();
    String readingValue = guiController.getMainMenuView().getValueInput().getText();
    String readingDate = guiController.getMainMenuView().getDateInput().getText();
    String dateFormat = guiController.getClinicalTrial().getSettings().getDateFormat();
    Clinic clinic = (Clinic) guiController.getMainMenuView().getComboBoxClinics().getSelectedItem();
    try {
        // Prompt the user if reading values aren't filled
        if (readingValue.equals("") || readingDate.equals("")) {
            JOptionPane.showMessageDialog(null, "Please fill in the values for every field.");
        } else {
            // If all values are filled, add them to to corresponding Patient
            SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
            // Change date from String to Date
            Date date = formatter.parse(readingDate);
            // add the new readings to that patient
            if (patient.addReading(null, readingType, readingValue, date, clinic)) {
                // Prompt if the reading is added
                JOptionPane.showMessageDialog(null, "New reading has been added.");
            } else {
                // Prompt if patient is not active in trial
                JOptionPane.showMessageDialog(null, "Invalid reading.");
            }
            // Clear the textfields for new input
            guiController.getMainMenuView().getValueInput().setText("");
        }
    } catch (NullPointerException ex) {
        // Catch the error if no patient is selected for adding readings.
        guiController.getMainMenuView().displayErrorMessage(null, "Please select a Patient to add readings.");
    } catch (ParseException e1) {
        JOptionPane.showMessageDialog(null, "Please enter a valid date formated " + dateFormat);
        e1.printStackTrace();
    }
}
Also used : Clinic(trial.Clinic) Patient(trial.Patient) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with Patient

use of trial.Patient in project project1-ICS372 by sandip-rai.

the class PatientUnitTest method PatientTest.

/**
 * Patient test.
 */
@Test
public void PatientTest() {
    // test constructor, isActive, getPatientId, get Readings
    p = new Patient(patientId);
    Assert.assertTrue(p.isActive());
    Assert.assertEquals(patientId, p.getPatientId());
    Assert.assertEquals(0, p.getReadings().size());
    // test addReading to active
    Assert.assertTrue(p.addReading("001", "Weight", "150.5", new Date(), c));
    Assert.assertEquals(1, p.getReadings().size());
    // test add duplicate id reading
    Assert.assertFalse(p.addReading("001", "Weight", "99", new Date(), c));
    // test setActive
    p.setActive(false);
    Assert.assertFalse(p.isActive());
    // test addReading to inactive
    Assert.assertFalse(p.addReading("002", "Weight", "100", new Date(), c));
}
Also used : Patient(trial.Patient) Date(java.util.Date) Test(org.junit.Test)

Example 4 with Patient

use of trial.Patient in project project1-ICS372 by sandip-rai.

the class PatientUnitTest method PatientTest.

/**
 * Patient test.
 */
@Test
public void PatientTest() {
    // test constructor, isActive, getPatientId, get Readings
    p = new Patient(patientId);
    p.setState(new PatientStateActive(p));
    Assert.assertTrue(p.getState().toString().equals("Active"));
    Assert.assertEquals(patientId, p.getState().getPatientId());
    Assert.assertEquals(0, p.getState().getReadings().size());
    // test addReading and getReadings to active
    Assert.assertTrue(p.getState().addReading("001", "Weight", "150.5", new Date(), c));
    Assert.assertEquals(1, p.getState().getReadings().size());
    // test add duplicate id reading
    Assert.assertFalse(p.getState().addReading("001", "Weight", "99", new Date(), c));
    // test set to PatientStateWithdrawn
    p.setState(new PatientStateWithdrawn(p));
    Assert.assertTrue(p.getState().toString().equals("Withdrawn"));
    // test addReading and getReadings on Withdrawn
    Assert.assertFalse(p.getState().addReading("002", "Weight", "100", new Date(), c));
    Assert.assertTrue(p.getState().getReadings() == null);
    // test set to PatientStateFailed
    p.setState(new PatientStateFailed(p));
    Assert.assertTrue(p.getState().toString().equals("Failed"));
    // test addReading and getReadings on Failed
    Assert.assertFalse(p.getState().addReading("002", "Weight", "100", new Date(), c));
    Assert.assertTrue(p.getState().getReadings() == null);
    // test set to PatientStateCompleted
    p.setState(new PatientStateCompleted(p));
    Assert.assertTrue(p.getState().toString().equals("Completed"));
    // test addReading and getReadings on Complete
    Assert.assertFalse(p.getState().addReading("002", "Weight", "100", new Date(), c));
    Assert.assertFalse(p.getState().getReadings() == null);
}
Also used : PatientStateFailed(trial.PatientStateFailed) PatientStateCompleted(trial.PatientStateCompleted) PatientStateActive(trial.PatientStateActive) Patient(trial.Patient) Date(java.util.Date) PatientStateWithdrawn(trial.PatientStateWithdrawn) Test(org.junit.Test)

Example 5 with Patient

use of trial.Patient in project project1-ICS372 by sandip-rai.

the class AddPatientInfoActivity method onClickAddReadingsToSelectedPatient.

public void onClickAddReadingsToSelectedPatient(View view) {
    // get selected patients id from spinner and pass it to clinicalTrial to find that patient
    // Spinner patientListSpinner = (Spinner) findViewById(R.id.spinnerReadingPatientId);
    // String patientId = patientListSpinner.getSelectedItem().toString();
    // Get the patientId from the textView which is passed from PatientListActivity
    TextView patientIdText = (TextView) findViewById(R.id.textViewPatientId);
    String patientId = patientIdText.getText().toString();
    Patient patient = clinicalTrial.findPatient(patientId);
    // get selected reading type from spinner
    Spinner readingTypeSpinner = (Spinner) findViewById(R.id.spinnerReadingType);
    String readingType = readingTypeSpinner.getSelectedItem().toString();
    EditText editTextReadingId = (EditText) findViewById(R.id.editTextReadingId);
    String readingId = editTextReadingId.getText().toString();
    EditText editTextDate = (EditText) findViewById(R.id.editTextDate);
    String textDate = editTextDate.getText().toString();
    EditText editTextValue = (EditText) findViewById(R.id.editTextValue);
    String value = editTextValue.getText().toString();
    Spinner spinnerClinicId = (Spinner) findViewById(R.id.spinnerClinicId);
    String clinicInSpinner = null;
    String[] clinicArray;
    String clinicId = null;
    try {
        clinicInSpinner = spinnerClinicId.getSelectedItem().toString();
        clinicArray = clinicInSpinner.split(":");
        clinicId = clinicArray[0];
    } catch (NullPointerException e) {
        makeToast("Patient is not currently active.");
    }
    Clinic clinic = clinicalTrial.findClinic(clinicId);
    String dateFormat = clinicalTrial.getSettings().getDateFormat();
    SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
    // Change date from String to Date
    Date date = null;
    try {
        date = formatter.parse(textDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    if (value.equals("") || textDate.equals("") || readingId.equals("") || clinicId.equals("")) {
        makeToast("Please fill in the values for every field.");
    } else if (clinicInSpinner == null) {
        makeToast("Please select/add a clinic.");
    // }// else if(date == null){
    // makeToast("Please enter date in a correct format");
    } else if (!patient.getState().toString().equals("Active")) {
        makeToast("Patient is not currently active.");
    } else {
        // add the new readings to that patient
        if (patient.addReading(readingId, readingType, value, date, clinic)) {
            // Prompt if the reading is added
            makeToast("New reading has been added.");
            editTextReadingId.setText("");
            editTextDate.setText("");
            editTextValue.setText("");
        }
    }
}
Also used : EditText(android.widget.EditText) Clinic(trial.Clinic) Spinner(android.widget.Spinner) Patient(trial.Patient) TextView(android.widget.TextView) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

Patient (trial.Patient)10 Date (java.util.Date)5 SimpleDateFormat (java.text.SimpleDateFormat)3 Clinic (trial.Clinic)3 PatientStateActive (trial.PatientStateActive)3 Toolbar (android.support.v7.widget.Toolbar)2 EditText (android.widget.EditText)2 Spinner (android.widget.Spinner)2 TextView (android.widget.TextView)2 ParseException (java.text.ParseException)2 Test (org.junit.Test)2 PatientStateCompleted (trial.PatientStateCompleted)2 PatientStateFailed (trial.PatientStateFailed)2 PatientStateWithdrawn (trial.PatientStateWithdrawn)2 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 TableLayout (android.widget.TableLayout)1 TableRow (android.widget.TableRow)1 DisplayPatientListView (gui.views.DisplayPatientListView)1