Android Open Source - SymptomManagement Symptom Management Provider






From Project

Back to project page SymptomManagement.

License

The source code is released under:

Apache License

If you think the Android project SymptomManagement 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 com.android.capstone.db;
/*  w w w . j a  va  2s.c o m*/

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;

public class SymptomManagementProvider extends ContentProvider {

  
  private static final UriMatcher sUriMatcher = buildUriMatcher();
    private SymptomManagementDbHelper mOpenHelper;

    private static final int USER_INFO = 100;
    private static final int MEDICATIONS = 200;
    private static final int CHECKINS = 300;
    private static final int REMINDERS = 400;
    private static final int USER_INFO_ID = 101;
    private static final int MEDICATIONS_ID = 201;
    private static final int CHECKINS_ID = 301;

  
  
  
    private static UriMatcher buildUriMatcher() {
        final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
        final String authority = SymptomManagementContract.CONTENT_AUTHORITY;

        matcher.addURI(authority, SymptomManagementContract.PATH_USER_INFO, USER_INFO);
        matcher.addURI(authority, SymptomManagementContract.PATH_MEDICATIONS, MEDICATIONS);
        matcher.addURI(authority, SymptomManagementContract.PATH_CHECKINS, CHECKINS);
        matcher.addURI(authority, SymptomManagementContract.PATH_REMINDERS, REMINDERS);
        
        matcher.addURI(authority, SymptomManagementContract.PATH_USER_INFO + "/#", USER_INFO_ID);
        matcher.addURI(authority, SymptomManagementContract.PATH_MEDICATIONS + "/#", MEDICATIONS_ID);
        matcher.addURI(authority, SymptomManagementContract.PATH_CHECKINS + "/#", CHECKINS_ID);
        
       return matcher;
       
    }
    

    
    
  
  
  @Override
  public boolean onCreate() {
    mOpenHelper = new SymptomManagementDbHelper(getContext());
    return true;
  }

  
  
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        final int match = sUriMatcher.match(uri);
        int rowsDeleted;
        
        switch (match) {
            case USER_INFO:
                rowsDeleted = db.delete(SymptomManagementContract.UserInfoEntry.TABLE_NAME, selection, selectionArgs);
                break;
                
            case MEDICATIONS:
                rowsDeleted = db.delete(SymptomManagementContract.MedicationsEntry.TABLE_NAME, selection, selectionArgs);
                break;
                
            case CHECKINS:
                rowsDeleted = db.delete(SymptomManagementContract.CheckinsEntry.TABLE_NAME, selection, selectionArgs);
                break;  
            
            case REMINDERS:
                rowsDeleted = db.delete(SymptomManagementContract.RemindersEntry.TABLE_NAME, selection, selectionArgs);    
                break;
                
            default:
                throw new UnsupportedOperationException("Unknown uri: " + uri);
        }
        
        if (selection == null || rowsDeleted != 0) {
            getContext().getContentResolver().notifyChange(uri, null);
        }
        return rowsDeleted;
        
  }

  
  
  
  @Override
  public String getType(Uri uri) {
    
        final int match = sUriMatcher.match(uri);

        switch (match) {
            case USER_INFO:
                return SymptomManagementContract.UserInfoEntry.CONTENT_TYPE;
            case MEDICATIONS:
                return SymptomManagementContract.MedicationsEntry.CONTENT_TYPE;
            case CHECKINS:
                return SymptomManagementContract.CheckinsEntry.CONTENT_TYPE;
            case REMINDERS:
                return SymptomManagementContract.RemindersEntry.CONTENT_TYPE;
            case MEDICATIONS_ID:
                return SymptomManagementContract.MedicationsEntry.CONTENT_ITEM_TYPE;
            case CHECKINS_ID:
                return SymptomManagementContract.CheckinsEntry.CONTENT_TYPE;
            default:
                throw new UnsupportedOperationException("Unknown uri: " + uri);
        }
    
  }

  
  
  @Override
  public Uri insert(Uri uri, ContentValues values) {
    
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        final int match = sUriMatcher.match(uri);
        Uri returnUri;

        switch (match) {
        
            case USER_INFO: {
                long _id = db.replace(SymptomManagementContract.UserInfoEntry.TABLE_NAME, null, values);
                if ( _id > 0 )
                    returnUri = SymptomManagementContract.UserInfoEntry.buildUserInfoUri(_id);
                else
                    throw new android.database.SQLException("Failed to insert row into " + uri);
                break;
            }
            
            case MEDICATIONS: {
                long _id = db.replace(SymptomManagementContract.MedicationsEntry.TABLE_NAME, null, values);
                if ( _id > 0 )
                    returnUri = SymptomManagementContract.MedicationsEntry.buildMedicationsUri(_id);
                else
                    throw new android.database.SQLException("Failed to insert row into " + uri);
                break;
            }
            
            case CHECKINS: {
                long _id = db.replace(SymptomManagementContract.CheckinsEntry.TABLE_NAME, null, values);
                if ( _id > 0 )
                    returnUri = SymptomManagementContract.CheckinsEntry.buildCheckinsUri(_id);
                else
                    throw new android.database.SQLException("Failed to insert row into " + uri);
                break;
            }
            
            case REMINDERS: {
                long _id = db.replace(SymptomManagementContract.RemindersEntry.TABLE_NAME, null, values);
                if ( _id > 0 )
                    returnUri = SymptomManagementContract.RemindersEntry.buildRemindersUri(_id);
                else
                    throw new android.database.SQLException("Failed to insert row into " + uri);
                break;
            }
            
            default:
                throw new UnsupportedOperationException("Unknown uri: " + uri);
         }
        
        
        getContext().getContentResolver().notifyChange(uri, null);
        return returnUri;
        
    }
  

  
  @Override
  public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    
    Cursor retCursor;
        switch (sUriMatcher.match(uri)) {
            
            case USER_INFO:
            {
                retCursor = mOpenHelper.getReadableDatabase().query(
                        SymptomManagementContract.UserInfoEntry.TABLE_NAME,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                 );
                break;
            }
            
            case MEDICATIONS: {
                retCursor = mOpenHelper.getReadableDatabase().query(
                        SymptomManagementContract.MedicationsEntry.TABLE_NAME,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                 );
                break;
            }
          
            case CHECKINS: {
                retCursor = mOpenHelper.getReadableDatabase().query(
                        SymptomManagementContract.CheckinsEntry.TABLE_NAME,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
            
            
            case REMINDERS: {
                retCursor = mOpenHelper.getReadableDatabase().query(
                        SymptomManagementContract.RemindersEntry.TABLE_NAME,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
            
           
           
            case USER_INFO_ID: {
              retCursor = mOpenHelper.getReadableDatabase().query(
                       SymptomManagementContract.UserInfoEntry.TABLE_NAME,
                       projection,
                       SymptomManagementContract.UserInfoEntry._ID + " = '" + ContentUris.parseId(uri) + "'",
                       null,
                       null,
                       null,
                       sortOrder
               );
               break;
           }
            
            case MEDICATIONS_ID: {
               retCursor = mOpenHelper.getReadableDatabase().query(
                        SymptomManagementContract.MedicationsEntry.TABLE_NAME,
                        projection,
                        SymptomManagementContract.MedicationsEntry.COLUMN_USER_ID + " = '" + ContentUris.parseId(uri) + "'",
                        null,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
           
            case CHECKINS_ID: {
              retCursor = mOpenHelper.getReadableDatabase().query(
                        SymptomManagementContract.CheckinsEntry.TABLE_NAME,
                        projection,
                        SymptomManagementContract.CheckinsEntry.COLUMN_USER_ID + " = '" + ContentUris.parseId(uri) + "'",
                        null,
                        null,
                        null,
                        sortOrder
                );
                break;
            }

            default:
                throw new UnsupportedOperationException("Unknown uri: " + uri);
        }
        
        
        retCursor.setNotificationUri(getContext().getContentResolver(), uri);
        return retCursor;
    
  }
  
  
  

  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    
          final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
          final int match = sUriMatcher.match(uri);
          int rowsUpdated;

          switch (match) {
          
              case USER_INFO:
                  rowsUpdated = db.update(SymptomManagementContract.UserInfoEntry.TABLE_NAME, values, selection, selectionArgs);
                  break;
                  
              case MEDICATIONS:
                  rowsUpdated = db.update(SymptomManagementContract.MedicationsEntry.TABLE_NAME, values, selection, selectionArgs);
                  break;
                  
              case CHECKINS:
                  rowsUpdated = db.update(SymptomManagementContract.CheckinsEntry.TABLE_NAME, values, selection, selectionArgs);
                  break;
                  
              case REMINDERS:
                  rowsUpdated = db.update(SymptomManagementContract.RemindersEntry.TABLE_NAME, values, selection, selectionArgs);
                  break;
                  
              default:
                  throw new UnsupportedOperationException("Unknown uri: " + uri);
          }
          
          if (rowsUpdated != 0) {
              getContext().getContentResolver().notifyChange(uri, null);
          }
     
       return rowsUpdated;
    
   }






  @Override
  public int bulkInsert(Uri uri, ContentValues[] values) {
    
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        final int match = sUriMatcher.match(uri);
        
        switch (match) {
        
            case USER_INFO:
                db.beginTransaction();
                int returnCount = 0;
                try {
                    for (ContentValues value : values) {
                        long _id = db.replace(SymptomManagementContract.UserInfoEntry.TABLE_NAME, null, value);
                        if (_id != -1) {
                            returnCount++;
                        }
                    }
                    db.setTransactionSuccessful();
                } finally {
                    db.endTransaction();
                }
                getContext().getContentResolver().notifyChange(uri, null);
                return returnCount;
           
                
           case CHECKINS:
                db.beginTransaction();
                int returnCount1 = 0;
                try {
                    for (ContentValues value : values) {
                        long _id = db.replace(SymptomManagementContract.CheckinsEntry.TABLE_NAME, null, value);
                        if (_id != -1) {
                            returnCount1++;
                        }
                    }
                    db.setTransactionSuccessful();
                } finally {
                    db.endTransaction();
                }
                getContext().getContentResolver().notifyChange(uri, null);
                return returnCount1;
                
                
           case REMINDERS:
               db.beginTransaction();
               int returnCount2 = 0;
               try {
                   for (ContentValues value : values) {
                       long _id = db.replace(SymptomManagementContract.RemindersEntry.TABLE_NAME, null, value);
                       if (_id != -1) {
                           returnCount2++;
                       }
                   }
                   db.setTransactionSuccessful();
               } finally {
                   db.endTransaction();
               }
               getContext().getContentResolver().notifyChange(uri, null);
               return returnCount2;
            
            default:
                return super.bulkInsert(uri, values);
        }
        
  }
  
  
  
  
  
  
  
  
  
  
}




Java Source Code List

android.UnusedStub.java
com.android.capstone.BaseActivity.java
com.android.capstone.DatePickerFragment.java
com.android.capstone.MainActivity.java
com.android.capstone.RegisterFragment.java
com.android.capstone.data.CheckinSvcApi.java
com.android.capstone.data.Checkin.java
com.android.capstone.data.Doctor.java
com.android.capstone.data.GPlusProfile.java
com.android.capstone.data.MedicationCheckinQA.java
com.android.capstone.data.Medications.java
com.android.capstone.data.Patient.java
com.android.capstone.data.VDoctor.java
com.android.capstone.data.VPatient.java
com.android.capstone.db.SymptomManagementContract.java
com.android.capstone.db.SymptomManagementDbHelper.java
com.android.capstone.db.SymptomManagementProvider.java
com.android.capstone.doctor.CheckinLogsListAdapter.java
com.android.capstone.doctor.CheckinLogs_Doctor_Fragment.java
com.android.capstone.doctor.DisplayCheckinActivity.java
com.android.capstone.doctor.DoctorMain_Fragment.java
com.android.capstone.doctor.Doctor_Main_CursorAdapter.java
com.android.capstone.doctor.Doctor_VPatient_Activity.java
com.android.capstone.doctor.Doctor_VPatient_Fragment.java
com.android.capstone.doctor.MedicationsListAdapter.java
com.android.capstone.doctor.MedicationsListFragment.java
com.android.capstone.doctor.alarm.CheckPainIntentService.java
com.android.capstone.doctor.alarm.CheckPain.java
com.android.capstone.doctor.alarm.CheckinAlarmService.java
com.android.capstone.doctor.alarm.OnBootReceiver.java
com.android.capstone.gcm.GcmBroadcastReceiver.java
com.android.capstone.gcm.GcmIntentService.java
com.android.capstone.patient.CheckinNowActivity.java
com.android.capstone.patient.PatientMain_Fragment.java
com.android.capstone.patient.Patient_Main_CursorAdapter.java
com.android.capstone.patient.ReminderCursorAdapter.java
com.android.capstone.patient.RemindersActivity.java
com.android.capstone.patient.TimePickerFragment.java
com.android.capstone.patient.checkin_now.model.AbstractWizardModel.java
com.android.capstone.patient.checkin_now.model.BranchPage.java
com.android.capstone.patient.checkin_now.model.CheckinNow_Model.java
com.android.capstone.patient.checkin_now.model.ModelCallbacks.java
com.android.capstone.patient.checkin_now.model.MultipleFixedChoicePage.java
com.android.capstone.patient.checkin_now.model.PageList.java
com.android.capstone.patient.checkin_now.model.PageTreeNode.java
com.android.capstone.patient.checkin_now.model.Page.java
com.android.capstone.patient.checkin_now.model.ReviewItem.java
com.android.capstone.patient.checkin_now.model.SingleFixedChoicePage.java
com.android.capstone.patient.checkin_now.ui.MultipleChoiceFragment.java
com.android.capstone.patient.checkin_now.ui.PageFragmentCallbacks.java
com.android.capstone.patient.checkin_now.ui.ReviewFragment.java
com.android.capstone.patient.checkin_now.ui.SingleChoiceFragment.java
com.android.capstone.patient.checkin_now.ui.StepPagerStrip.java
com.android.capstone.task.AddCheckinTask.java
com.android.capstone.task.AddMedicationsTask.java
com.android.capstone.task.AddPatientTask.java
com.android.capstone.task.GetClientCategoryTask.java
com.android.capstone.task.GetClientInfoTask.java
com.android.capstone.task.GetUserImageTask.java
com.android.capstone.task.RegisterDoctorTask.java
com.android.capstone.task.RegisterPatientTask.java
com.android.capstone.utils.CommonUtils.java
com.android.capstone.utils.RetrofitUtils.java
com.android.capstone.utils.SharedPrefUtils.java
com.android.capstone.views.CheckinLogsView.java
com.android.capstone.views.FloatingActionButton.java
com.coursera.capstone.checkin.Application.java
com.coursera.capstone.checkin.client.CheckinSvcApi.java
com.coursera.capstone.checkin.client.TokenSvcApi.java
com.coursera.capstone.checkin.controller.CheckinSvc.java
com.coursera.capstone.data.CheckinUtils.java
com.coursera.capstone.data.Checkin.java
com.coursera.capstone.data.ClientUtils.java
com.coursera.capstone.data.Constants.java
com.coursera.capstone.data.DoctorUtils.java
com.coursera.capstone.data.Doctor.java
com.coursera.capstone.data.InvalidRequestException.java
com.coursera.capstone.data.Medications.java
com.coursera.capstone.data.Message.java
com.coursera.capstone.data.MulticastResult.java
com.coursera.capstone.data.PMF.java
com.coursera.capstone.data.PatientUtils.java
com.coursera.capstone.data.Patient.java
com.coursera.capstone.data.Result.java
com.coursera.capstone.data.Sender.java
com.coursera.capstone.data.Token.java
com.coursera.capstone.data.VDoctor.java
com.coursera.capstone.data.VPatient.java
com.coursera.capstone.interceptor.AuthorizationInterceptor.java
com.coursera.capstone.interceptor.Checker.java