Android Open Source - clinicalguide Patients Fragment






From Project

Back to project page clinicalguide.

License

The source code is released under:

Apache License

If you think the Android project clinicalguide listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.get.oxicam.clinicalguide.ui;
//from w ww .  j ava 2s. co m
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.get.oxicam.clinicalguide.ClinicalGuideActivity;
import org.get.oxicam.clinicalguide.R;
import org.get.oxicam.clinicalguide.db.Database;
import org.get.oxicam.clinicalguide.db.PatientDetails;
import org.get.oxicam.clinicalguide.xml.data.PatientAttribute;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.util.FloatMath;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class PatientsFragment extends ListFragment {

  public static final String ARG_KEY_NEXT_FRAGMENT = "nextFragment";
  public static final String ARG_KEY_SELECTED_PATIENT = "patient";
  
  private ClinicalGuideActivity mActivity;
  private SimpleAdapter mAdapter;

  private List<PatientDetails> mPatients;
  
  /**
   * Initializes the PatientsFragment.
   */
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mActivity = (ClinicalGuideActivity) getActivity();
    mActivity.setTitle("Select Patient");

    // get patient data from DB and put it in th list view
//    mPatientData = new PatientDetailsDataSource(mActivity);
//    mPatientData.open();
    
    mPatients = (new Database(mActivity)).getAllPatientDetailRecords();

    setHasOptionsMenu(true);
    populateList();
  }

  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.patients_fragment, menu);
  //  getMenuInflater().inflate(R.menu.patients_fragment, menu);
  //  EditText et = (EditText) menu.findItem(R.id.menu_subjectinfo);
  //  et.setText("Patient Name, Age",android.widget.TextView.BufferType.NORMAL);
    //hide home button here
    MenuItem item = menu.findItem(R.id.menu_home);
    item.setVisible(false);
    //try to overide xml
  //  item = menu.findItem(R.id.menu_add_patient);
  //    item.setIcon(R.drawable.ic_patient);
  //    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
  
    case R.id.menu_add_patient:
      Bundle b = new Bundle();
      b.putInt("viewMode", PatientDetailsFragment.MODE_ADD);
      
      Fragment frag = new PatientDetailsFragment();
      frag.setArguments(b);
      mActivity.setContent(frag);
      return true;
      
    default:
      return super.onOptionsItemSelected(item);
    }
  }

  /**
   * Called if a item in the ListView is clicked.
   */
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    PatientDetails selectedPatient = mPatients.get(position);
    
    // open next fragment
    Bundle args = getArguments();
    if(args != null) {
      String fragName = args.getString(ARG_KEY_NEXT_FRAGMENT);
      if(fragName != null) {
        Bundle b = new Bundle();
        b.putSerializable(ARG_KEY_SELECTED_PATIENT, selectedPatient);
        Fragment next = Fragment.instantiate(mActivity, fragName);
        next.setArguments(b);
        mActivity.setContent(next);
      }
    }
  }

  private void populateList() {
    // populate a HashMap with all list items
    ArrayList<HashMap<String, Object>> itemData = new ArrayList<HashMap<String, Object>>();
    for (PatientDetails p : mPatients) {
      HashMap<String, Object> map = new HashMap<String, Object>();
      
      for (PatientAttribute attribute : p.getAttributes()) {
        if (attribute.name.equals("firstname")) {
          map.put("name", attribute.answer);
        }
        else if (attribute.name.equals("lastname")) {
          map.put("surname", attribute.answer);
        }
        else if (attribute.name.equals("gender")) {
          map.put("gender", attribute.answer);
        }
        Database db = new Database(mActivity);
        float age = db.getPatientAge(p.getPatientID());
        map.put("age", ", " + (int)FloatMath.floor(age));
        map.put("accessory", "\uE75E");
      }
      itemData.add(map);
    }

    // Specify source tag to corresponding target ID mapping
    String[] sourceTags = { "name", "surname", "gender", "age","accessory" };
    int[] targetIds = { R.id.patientName, R.id.patientSurname, R.id.patientGender, R.id.patientAge , R.id.patientAccessoryView};

    // create the ListAdapter
    mAdapter = new SimpleAdapter(getActivity(), itemData,
        R.layout.patients_list_item, sourceTags, targetIds);
    setListAdapter(mAdapter);
  }
  
  @Override
  public void onResume() {
//    mPatientData.open();
    super.onResume();
  }

  @Override
  public void onPause() {
//    mPatientData.close();
    super.onPause();
  }
}




Java Source Code List

.PatientDetailsDataSource.java
org.get.oxicam.clinicalguide.ClinicalGuideActivity.java
org.get.oxicam.clinicalguide.FileUtils.java
org.get.oxicam.clinicalguide.LoginActivity.java
org.get.oxicam.clinicalguide.db.DatabaseHelper.java
org.get.oxicam.clinicalguide.db.Database.java
org.get.oxicam.clinicalguide.db.FollowupDataSource.java
org.get.oxicam.clinicalguide.db.FollowupDetails.java
org.get.oxicam.clinicalguide.db.FollowupSQLHelper.java
org.get.oxicam.clinicalguide.db.HistoryDetailsDataSource.java
org.get.oxicam.clinicalguide.db.HistoryDetailsSQLHelper.java
org.get.oxicam.clinicalguide.db.HistoryDetails.java
org.get.oxicam.clinicalguide.db.PatientDetailsSQLHelper.java
org.get.oxicam.clinicalguide.db.PatientDetails.java
org.get.oxicam.clinicalguide.db.RegistrationValidator.java
org.get.oxicam.clinicalguide.db.Validator.java
org.get.oxicam.clinicalguide.encryption.Encryption.java
org.get.oxicam.clinicalguide.ui.AnswersReviewFragment.java
org.get.oxicam.clinicalguide.ui.AssessmentDetailFragment.java
org.get.oxicam.clinicalguide.ui.ClassificationFragment.java
org.get.oxicam.clinicalguide.ui.ClassificationListItem.java
org.get.oxicam.clinicalguide.ui.DatePickerFragment.java
org.get.oxicam.clinicalguide.ui.ExportFragment.java
org.get.oxicam.clinicalguide.ui.ExportscreenListItem.java
org.get.oxicam.clinicalguide.ui.FollowUpFragment.java
org.get.oxicam.clinicalguide.ui.FormScreenFragment.java
org.get.oxicam.clinicalguide.ui.HomescreenFragment.java
org.get.oxicam.clinicalguide.ui.HomescreenListItem.java
org.get.oxicam.clinicalguide.ui.ListItemOnClickListener.java
org.get.oxicam.clinicalguide.ui.MainSymptomFragment.java
org.get.oxicam.clinicalguide.ui.MainSymptomListItem.java
org.get.oxicam.clinicalguide.ui.NumberTickerValueChangeListener.java
org.get.oxicam.clinicalguide.ui.NumberTicker.java
org.get.oxicam.clinicalguide.ui.PatientDetailsFragment.java
org.get.oxicam.clinicalguide.ui.PatientHistoryFragment.java
org.get.oxicam.clinicalguide.ui.PatientsFragment.java
org.get.oxicam.clinicalguide.ui.QuestionListItem.java
org.get.oxicam.clinicalguide.ui.QuestionnaireFragment.java
org.get.oxicam.clinicalguide.ui.StatScreenFragment.java
org.get.oxicam.clinicalguide.ui.SummaryScreenFragment.java
org.get.oxicam.clinicalguide.ui.TextViewCustomFont.java
org.get.oxicam.clinicalguide.ui.TreatmentConfirmationDialog.java
org.get.oxicam.clinicalguide.ui.TreatmentFragment.java
org.get.oxicam.clinicalguide.ui.TreatmentListItem.java
org.get.oxicam.clinicalguide.ui.ViewDetailScreenFragment.java
org.get.oxicam.clinicalguide.xml.CGFormParser.java
org.get.oxicam.clinicalguide.xml.CGParser.java
org.get.oxicam.clinicalguide.xml.CGStatsParser.java
org.get.oxicam.clinicalguide.xml.DateHelper.java
org.get.oxicam.clinicalguide.xml.FormGenerator.java
org.get.oxicam.clinicalguide.xml.ParserHelper.java
org.get.oxicam.clinicalguide.xml.StatsGenerator.java
org.get.oxicam.clinicalguide.xml.XMLHandler.java
org.get.oxicam.clinicalguide.xml.data.AbstractAnswer.java
org.get.oxicam.clinicalguide.xml.data.Annotation.java
org.get.oxicam.clinicalguide.xml.data.AnswerValidator.java
org.get.oxicam.clinicalguide.xml.data.Answer.java
org.get.oxicam.clinicalguide.xml.data.Assessment.java
org.get.oxicam.clinicalguide.xml.data.CombinedAnswer.java
org.get.oxicam.clinicalguide.xml.data.FollowUp.java
org.get.oxicam.clinicalguide.xml.data.FormQuery.java
org.get.oxicam.clinicalguide.xml.data.Info.java
org.get.oxicam.clinicalguide.xml.data.Option.java
org.get.oxicam.clinicalguide.xml.data.PatientAttribute.java
org.get.oxicam.clinicalguide.xml.data.Question.java
org.get.oxicam.clinicalguide.xml.data.Questionnaire.java
org.get.oxicam.clinicalguide.xml.data.SimpleAnswer.java
org.get.oxicam.clinicalguide.xml.data.Symptom.java
org.get.oxicam.clinicalguide.xml.data.TreatmentAction.java
org.get.oxicam.clinicalguide.xml.data.Treatment.java
org.get.oxicam.clinicalguide.xml.data.User.java
org.get.oxicam.clinicalguide.xml.forms.FormCell.java
org.get.oxicam.clinicalguide.xml.forms.FormColumn.java
org.get.oxicam.clinicalguide.xml.forms.FormDuration.java
org.get.oxicam.clinicalguide.xml.forms.Form.java
org.get.oxicam.clinicalguide.xml.query.QueryHelper.java
org.get.oxicam.clinicalguide.xml.query.QueryResultCell.java
org.get.oxicam.clinicalguide.xml.query.QueryResultRow.java
org.get.oxicam.clinicalguide.xml.query.QueryResultTable.java
org.get.oxicam.clinicalguide.xml.stats.AbstractStatsQuestion.java
org.get.oxicam.clinicalguide.xml.stats.StatsAnswerHolder.java
org.get.oxicam.clinicalguide.xml.stats.StatsColumnCompare.java
org.get.oxicam.clinicalguide.xml.stats.StatsComparatorOperator.java
org.get.oxicam.clinicalguide.xml.stats.StatsCompareConstraint.java
org.get.oxicam.clinicalguide.xml.stats.StatsConstraint.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionAverage.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionCount.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionExtrema.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionFactory.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionList.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionPercentage.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionRatio.java
org.get.oxicam.clinicalguide.xml.stats.StatsSubject.java
org.get.oxicam.clinicalguide.xml.stats.StatsTimespan.java
org.get.oxicam.clinicalguide.xml.stats.Stats.java