Copyright (c) 2010, Moca
All rights reserved.
The source code for Moca is licensed under the BSD license as follows:
Redistribution and use in source and binary forms, with or without modification, ...
If you think the Android project sana 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.moca.task;
//fromwww.java2s.comimport org.moca.db.PatientInfo;
import org.moca.net.MDSInterface;
import org.moca.util.MocaUtil;
import org.moca.util.UserDatabase;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
publicclass PatientLookupTask extends AsyncTask<String, Void, PatientInfo> {
privatestaticfinal String TAG = PatientLookupTask.class.toString();
private Context mContext;
private PatientLookupListener listener = null;
public PatientLookupTask(Context c) {
mContext = c;
}
publicvoid setPatientLookupListener(PatientLookupListener listener) {
this.listener = listener;
}
@Override
protected PatientInfo doInBackground(String... params) {
String patientId = params[0];
Log.i(TAG, "Looking up patient record for " + patientId);
PatientInfo pi = null;
try {
if (MocaUtil.checkConnection(mContext)) {
String mdsPatientInfo = MDSInterface.getUserInfo(mContext, patientId);
pi = UserDatabase.getPatientFromMDSRecord(patientId, mdsPatientInfo);
Log.i(TAG, "Acquired patient record from MDS");
}
} catch (Exception e) {
Log.e(TAG, "Could not get patient record from MDS: " + e.toString());
e.printStackTrace();
}
try {
if (pi == null) {
pi = UserDatabase.getPatientFromLocalDatabase(mContext, patientId);
Log.i(TAG, "Acquired patient record from local Patient cache.");
}
} catch (Exception e) {
Log.e(TAG, "Could not get patient record from local database: " + e.toString());
e.printStackTrace();
}
if (pi == null) {
pi = new PatientInfo();
pi.setPatientIdentifier(patientId);
pi.setConfirmed(false);
}
return pi;
}
@Override
protectedvoid onPostExecute(PatientInfo pi) {
if (listener != null && pi != null) {
if (!pi.isConfirmed()) {
listener.onPatientLookupFailure(pi.getPatientIdentifier());
} else {
listener.onPatientLookupSuccess(pi);
}
}
}
}