Search in sources :

Example 1 with PatientStateCompleted

use of trial.PatientStateCompleted 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 2 with PatientStateCompleted

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

the class PatientListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_patient_list);
    // Get the toolbar and assign
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.patient_list);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // Grab the spinner
    final Spinner patientListSpinner = (Spinner) findViewById(R.id.spinnerPatientIdinPatientList);
    ArrayAdapter<Patient> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, clinicalTrial.getAllPatients());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    patientListSpinner.setAdapter(adapter);
    // Status spinner
    final Spinner patientStatusSpinner = (Spinner) findViewById(R.id.spinnerStatusPatientList);
    final ArrayAdapter<CharSequence> adapterStatus = ArrayAdapter.createFromResource(this, R.array.statusList, android.R.layout.simple_spinner_item);
    adapterStatus.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    patientStatusSpinner.setAdapter(adapterStatus);
    // Update status spinner on patient spinner selection
    patientListSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (clinicalTrial.getAllPatients().size() > 0) {
                Patient p = (Patient) patientListSpinner.getSelectedItem();
                String state = p.getState().toString();
                if (state != null) {
                    int spinnerPosition = adapterStatus.getPosition(state);
                    patientStatusSpinner.setSelection(spinnerPosition);
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    // Update patient state on status spinner selection
    patientStatusSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (clinicalTrial.getAllPatients().size() > 0) {
                Patient p = (Patient) patientListSpinner.getSelectedItem();
                switch((String) patientStatusSpinner.getSelectedItem()) {
                    case "Active":
                        p.setState(new PatientStateActive(p));
                        break;
                    case "Withdrawn":
                        p.setState(new PatientStateWithdrawn(p));
                        break;
                    case "Failed":
                        p.setState(new PatientStateFailed(p));
                        break;
                    case "Completed":
                        p.setState(new PatientStateCompleted(p));
                        break;
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}
Also used : PatientStateFailed(trial.PatientStateFailed) Spinner(android.widget.Spinner) Patient(trial.Patient) View(android.view.View) AdapterView(android.widget.AdapterView) PatientStateWithdrawn(trial.PatientStateWithdrawn) PatientStateCompleted(trial.PatientStateCompleted) PatientStateActive(trial.PatientStateActive) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Patient (trial.Patient)2 PatientStateActive (trial.PatientStateActive)2 PatientStateCompleted (trial.PatientStateCompleted)2 PatientStateFailed (trial.PatientStateFailed)2 PatientStateWithdrawn (trial.PatientStateWithdrawn)2 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 Spinner (android.widget.Spinner)1 Date (java.util.Date)1 Test (org.junit.Test)1