@Override
  protected String doInBackground(String... values) {

    String baseUrl = values[0];
    int count = values.length - 1;

    for (int i = 0; i < values.length; i++) Log.i("XXXX", "value: " + values[i]);

    if (count > 0) {
      try {
        // Ensure directory exists
        FileUtils.createFolder(FileUtils.FORMS_PATH);

        // Open db for editing
        mPatientDbAdapter.open();

        for (int i = 1; i < values.length; i++) {
          try {
            String formId = values[i];
            publishProgress(
                "form " + formId, Integer.valueOf(i).toString(), Integer.valueOf(count).toString());

            StringBuilder url = new StringBuilder(baseUrl);
            url.append("&formId=");
            url.append(formId);

            URL u = new URL(url.toString());
            HttpURLConnection c = (HttpURLConnection) u.openConnection();
            InputStream is = c.getInputStream();

            String path = FileUtils.FORMS_PATH + formId + ".xml";

            File f = new File(path);
            OutputStream os = new FileOutputStream(f);
            byte buf[] = new byte[1024];
            int len;
            while ((len = is.read(buf)) > 0) {
              os.write(buf, 0, len);
            }
            os.flush();
            os.close();
            is.close();

            mPatientDbAdapter.updateFormPath(Integer.valueOf(formId), path);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }

        mPatientDbAdapter.close();
      } catch (Exception e) {
        e.printStackTrace();
        return e.getLocalizedMessage();
      }
    }

    return null;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.observation_chart);

    if (!FileUtils.storageReady()) {
      showCustomToast(getString(R.string.error_storage));
      finish();
    }

    // TODO Check for invalid patient IDs
    String patientIdStr = getIntent().getStringExtra(Constants.KEY_PATIENT_ID);
    Integer patientId = Integer.valueOf(patientIdStr);
    mPatient = getPatient(patientId);

    mObservationFieldName = getIntent().getStringExtra(Constants.KEY_OBSERVATION_FIELD_NAME);

    setTitle(getString(R.string.app_name) + " > " + getString(R.string.view_observation));

    TextView textView = (TextView) findViewById(R.id.title_text);
    if (textView != null) {
      textView.setText(mObservationFieldName);
    }

    XYSeriesRenderer r = new XYSeriesRenderer();
    r.setLineWidth(3.0f);
    r.setColor(getResources().getColor(R.color.chart_red));
    r.setPointStyle(PointStyle.CIRCLE);
    r.setFillPoints(true);

    mRenderer.addSeriesRenderer(r);
    mRenderer.setShowLegend(false);
    // mRenderer.setXTitle("Encounter Date");
    // mRenderer.setAxisTitleTextSize(18.0f);
    mRenderer.setLabelsTextSize(11.0f);
    // mRenderer.setXLabels(10);
    mRenderer.setShowGrid(true);
    mRenderer.setLabelsColor(getResources().getColor(android.R.color.black));
  }