Android Open Source - chat.android Immunizations Summary Activity






From Project

Back to project page chat.android.

License

The source code is released under:

GNU General Public License

If you think the Android project chat.android 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.chat.android;
//  ww w .j  a  va  2s . co m
import java.util.List;

import org.chat.android.models.Client;
import org.chat.android.models.Household;
import org.chat.android.models.Vaccine;
import org.chat.android.models.VaccineRecorded;
import org.chat.android.models.Worker;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class ImmunizationsSummaryActivity extends BaseActivity {
  private int visitId = 0;
  private int hhId = 0;
  private int clientId = 0;
  private Client client = null;
  private Mail m;
  String emailContentStr = "";
  
    @Override    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = getApplicationContext();
        setContentView(R.layout.activity_immunization_summary);
        
        Bundle b = getIntent().getExtras();
    visitId = b.getInt("visitId");
    hhId = b.getInt("hhId");
    clientId = b.getInt("clientId");
    client = ModelHelper.getClientForId(getHelper(), clientId);
    String missingVaccines = getMissingVaccines(client);
    
    TextView tv = (TextView) findViewById(R.id.missing_vaccines_box);
    // String msg = getResources().getString(getResources().getIdentifier("immunization_missing_vaccines_text", "string", getPackageName()));
    tv.setText(missingVaccines);
    }
    
    private String getMissingVaccines(Client client) {
      Boolean referralFlag = false;
      String mv = "";
      List<Vaccine> vList = ModelHelper.getVaccinesForAge(getHelper(), client.getAge());
      List<VaccineRecorded> vaccinesRecorded = null;
      
      int stopReferCount = 0;
      for (Vaccine vaccine : vList) {
        // will return null if it doesn't exist
        VaccineRecorded vr = ModelHelper.getVaccineRecordedForClientIdAndVaccineId(getHelper(), client.getId(), vaccine.getId());
        if (vr == null) {
          mv += "\n- ";
          mv += vaccine.getShortName();
          referralFlag = true;
        } else {
          // disturbing implicit check, need confirm from Lisa. If any vaccines missing but 'last' vaccines are there (ie ages 0.75 and 1.5), do not refer
          if (vaccine.getAge() == 0.75 || vaccine.getAge() == 1.5) {
            // if stopReferCount is 4, then we don't need to refer
            stopReferCount++;
          }
        }
      }
      
      if (referralFlag == true && stopReferCount < 4) {
        sendReferral(mv);
        mv = "Refer " + client.getFirstName() + " " + client.getLastName() + " for the required immunizations:" + mv;
      } else {
         mv = client.getFirstName() + " " + client.getLastName() + " is missing some vaccinations, but has their most recent vaccines";
       }
      
      return mv;
    }
    
    public void completeImmunizationSummary(View v) {
      // CHAAccessed object is updated as completed (ie end_time is added) in ImmunizationReceivedActivity
      String msg = getResources().getString(getResources().getIdentifier("immunization_completed_text", "string", getPackageName()));
      BaseActivity.toastHelper(this,msg +" " + client.getFirstName() + " " + client.getLastName() );
      finish();
    }
    
    
    // semi-duplicated from ReferralFragment. TODO - abstract me and set logical params
    private void sendReferral(String mv) {
      Client c = ModelHelper.getClientForId(getHelper(), clientId);
      String clientFName = c.getFirstName();
      String clientLName = c.getLastName();
      Household hh = ModelHelper.getHouseholdForId(getHelper(), hhId);
      String hhName = hh.getHhName();
      int workerId = hh.getWorkerId();
      Worker worker = ModelHelper.getWorkerForId(getHelper(), workerId);
      String fName = worker.getFirstName();
      String lName = worker.getLastName();
      Log.i("Related Info", "household name:"+hhName+",volunteer Name:"+fName+" "+lName);
      
      // currently have the phone_numbers saved as ints, may be better to change to string (would prevent the 0 at the beginning of the number from getting dropped)
      String workerPhoneNum = "0" + Integer.toString(worker.getPhoneNumber());
      m = new Mail("chatreferral@gmail.com", "health001"); 
      String[] toArr = {"lmbutler.ssa@gmail.com"}; // This is an array, you can add more emails, just separate them with a coma      
      
      //send sms
      String nursePhoneNum = "0812567890";          // now Fikile's number. Ok? Still need to switch the target email
      String smsMessage = "Vaccination referral for - Household [Household name] by Volunteer [Volunteer Name].  See email for details or phone volunteer at: [Phone Number]";
      smsMessage = smsMessage.replace("[Household name]", hhName);
      smsMessage = smsMessage.replace("[Volunteer Name]", fName+" "+lName);
      smsMessage = smsMessage.replace("[Phone Number]", workerPhoneNum);
      
      PackageManager pm = context.getPackageManager();
      if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
        new SendSMS().execute(nursePhoneNum, smsMessage);
      } else {
        BaseActivity.toastHelper(this, "This device does not seem to be equipped with SMS capabilities. Please send a PlsCall SMS to Fikile at 0812567890 to explain the serious health condition.");
      }
      
      emailContentStr = emailContentStr + ("\n") + "Missing vaccinations: " + mv;
      
      //send email
      StringBuilder strBuilder = new StringBuilder();
      String emailTitleStr = "Vaccination referral for - Child name: [Child name] at Household: [Household name]; assessment performed by [Home Visitor Name]. Child is missing vaccinations";
      emailTitleStr = emailTitleStr.replace("[Household name]", hhName);
      emailTitleStr = emailTitleStr.replace("[Child name]", clientFName+" "+clientLName);
      emailTitleStr = emailTitleStr.replace("[Home Visitor Name]", fName+" "+lName);

      strBuilder.append(emailTitleStr);
      strBuilder.append("\n\n");
      strBuilder.append(emailContentStr);
      new SendMail().execute(toArr, "chatreferral@gmail.com", "Health referral", strBuilder.toString());
    }
    
    protected boolean sendSMSMessage(String phoneNo, String message) {
        Log.i("Send SMS", "");
        
        try {
           SmsManager smsManager = SmsManager.getDefault();
           smsManager.sendTextMessage(phoneNo, null, message, null, null);
           Log.i("Send SMS", "SMS sent");
           return true;
        } catch (Exception e) {
          Log.i("Send SMS", "SMS failed, please try again");
          e.printStackTrace();
          return false;
        }
     }
     
    private class SendMail extends AsyncTask<Object, Integer, Boolean> {

    @Override
    protected Boolean doInBackground(Object... params) {
      return ImmunizationsSummaryActivity.this.sendEmail((String[])params[0],String.valueOf(params[1]),String.valueOf(params[2]),String.valueOf(params[3]));
    }

    @Override
    protected void onPostExecute(Boolean result) {
      super.onPostExecute(result);
      if(!result)
      {
        showToast("Email was not sent.");
        String warningStr = "Unable to send Email automatically. Please send a PlsCall SMS to Fikile at 0812567890 to explain the serious health condition";
        showAlertDialog("Send Email failed",warningStr);
      }
      else
        showToast("Email was sent successfully.");
    }
     }
    
    private class SendSMS extends AsyncTask<Object, Integer, Boolean> {

    @Override
    protected Boolean doInBackground(Object... params) {
      return ImmunizationsSummaryActivity.this.sendSMSMessage(String.valueOf(params[0]),String.valueOf(params[1]));
    }

    @Override
    protected void onPostExecute(Boolean result) {
      super.onPostExecute(result);
      if(!result)
      {
        showToast("SMS was not sent.");
        String warningStr = "Unable to send SMS automatically.  Please send a PlsCall SMS to Fikile at 0812567890 to explain the serious health condition";
        showAlertDialog("Send SMS failed",warningStr);
      }
      else
        showToast("SMS was sent successfully.");
    }
    }
    
    public boolean sendEmail(String[] toArr, String fromArr, String subject, String message){
      m.setTo(toArr); // load array to setTo function
      m.setFrom(fromArr); // who is sending the email 
      m.setSubject(subject); 
      m.setBody(message); 
      boolean isSuccess=false;

      try { 
        //m.addAttachment("/sdcard/myPicture.jpg");  // path to file you want to attach
        if(m.send()) { 
          // success
          
          Log.i("Send Email", "send email successful");
          isSuccess=true;
        } else { 
          // failure
          Log.i("Send Email", "send email failed");
          isSuccess=false;
        } 
      } catch(Exception e) { 
        // some other problem
        Log.i("Send Email", "send email failed becaues of other problem");
        e.printStackTrace();
        isSuccess=false;
      } 
      return isSuccess;

    }
     
    private void showAlertDialog(String title, String message)
    {
    AlertDialog.Builder alert = new AlertDialog.Builder(context);
  
    alert.setTitle(title);
    alert.setMessage(message);
  
    alert.setPositiveButton(context.getText(R.string.action_confirm), new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
           // Do something with value!
       }
    });
  
    alert.show();
     }
 
     private void showToast(String s) {
       BaseActivity.toastHelper(this, s);
     }
}




Java Source Code List

org.chat.android.BaseActivity.java
org.chat.android.CHADelivery.java
org.chat.android.CHAOverviewActivity.java
org.chat.android.CHASelectChildActivity.java
org.chat.android.CHASelectChildAdapter.java
org.chat.android.ChatUtil.java
org.chat.android.ClientsAdapter.java
org.chat.android.DatabaseHelper.java
org.chat.android.GPSTracker.java
org.chat.android.HealthDeliveryActivity.java
org.chat.android.HealthDetailsActivity.java
org.chat.android.HealthOverviewActivity.java
org.chat.android.HealthOverviewRecordActivity.java
org.chat.android.HomeActivity.java
org.chat.android.ImmunizationsReceivedActivity.java
org.chat.android.ImmunizationsSummaryActivity.java
org.chat.android.LoginActivity.java
org.chat.android.Mail.java
org.chat.android.ModelHelper.java
org.chat.android.MyApplication.java
org.chat.android.ResourcesActivity.java
org.chat.android.RestoreVisitActivity.java
org.chat.android.ServiceDeliveryActivity.java
org.chat.android.ServiceDeliveryAdapter.java
org.chat.android.ServiceDetailsActivity.java
org.chat.android.ServiceOtherActivity.java
org.chat.android.ServiceOverviewActivity.java
org.chat.android.ServicesAdapter.java
org.chat.android.SetupDB.java
org.chat.android.SetupVisitActivity.java
org.chat.android.SyncResourcesActivity.java
org.chat.android.Auth.AccountGeneral.java
org.chat.android.Auth.AuthenticatorService.java
org.chat.android.Auth.Authenticator.java
org.chat.android.Auth.ChatAuthServerAuthenticate.java
org.chat.android.Auth.MainActivity.java
org.chat.android.Auth.ServerAuthenticate.java
org.chat.android.Sync.StubProvider.java
org.chat.android.Sync.SyncAdapter.java
org.chat.android.Sync.SyncService.java
org.chat.android.Sync.provider.ChatContentProvider.java
org.chat.android.models.Attendance.java
org.chat.android.models.CHAAccessed.java
org.chat.android.models.Client.java
org.chat.android.models.HealthPage.java
org.chat.android.models.HealthSelectRecorded.java
org.chat.android.models.HealthSelect.java
org.chat.android.models.HealthTheme.java
org.chat.android.models.HealthTopicAccessed.java
org.chat.android.models.HealthTopic.java
org.chat.android.models.Household.java
org.chat.android.models.PageAssessment1.java
org.chat.android.models.PageSelect1.java
org.chat.android.models.PageText1.java
org.chat.android.models.PageVideo1.java
org.chat.android.models.ResourceAccessed.java
org.chat.android.models.Resource.java
org.chat.android.models.Role.java
org.chat.android.models.ServiceAccessed.java
org.chat.android.models.Service.java
org.chat.android.models.TopicVideo.java
org.chat.android.models.Util.java
org.chat.android.models.VaccineRecorded.java
org.chat.android.models.Vaccine.java
org.chat.android.models.VideoAccessed.java
org.chat.android.models.Video.java
org.chat.android.models.Visit.java
org.chat.android.models.Worker.java
org.chat.android.pages.Assessment1Fragment.java
org.chat.android.pages.BaseFragment.java
org.chat.android.pages.ReferralFragment.java
org.chat.android.pages.Select1Fragment.java
org.chat.android.pages.Text1Fragment.java
org.chat.android.pages.Video1Fragment.java