Android Open Source - openhds-tablet Queries






From Project

Back to project page openhds-tablet.

License

The source code is released under:

OPENHDS PLATFORM OPENSOURCE LICENSE AGREEMENT Copyright (c) 2013 University of Southern Maine. All rights reserved. Redistribution and use in source and binary forms, with or without mo...

If you think the Android project openhds-tablet 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.openhds.mobile;
//from   w ww.j a  va 2  s.  c  om
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;

/**
 * Centralized location to put queries on data to reduce duplication
 */
public class Queries {

    private Queries() {
    }

    public static boolean individualByExtId(ContentResolver resolver, String extId) {
        return queryForSingleRow(resolver, OpenHDS.Individuals.CONTENT_ID_URI_BASE,
                OpenHDS.Individuals.COLUMN_INDIVIDUAL_EXTID, extId);
    }

    private static boolean queryForSingleRow(ContentResolver resolver, Uri uri, String column, String value) {
        Cursor cursor = getCursor(resolver, uri, column, value);
        return isFound(cursor);
    }

    private static Cursor getCursor(ContentResolver resolver, Uri uri, String column, String value) {
        return resolver.query(uri, null, column + " = ?", new String[] { value }, null);
    }

    public static Cursor getIndividualByExtId(ContentResolver resolver, String extId) {
        return getCursor(resolver, OpenHDS.Individuals.CONTENT_ID_URI_BASE,
                OpenHDS.Individuals.COLUMN_INDIVIDUAL_EXTID, extId);
    }

    public static Cursor getIndividualsByResidency(ContentResolver resolver, String extId) {
        return getCursor(resolver, OpenHDS.Individuals.CONTENT_ID_URI_BASE,
                OpenHDS.Individuals.COLUMN_INDIVIDUAL_RESIDENCE, extId);
    }

    private static boolean isFound(Cursor cursor) {
        boolean found = false;
        if (cursor != null) {
            found = cursor.moveToFirst();
            cursor.close();
        }

        return found;
    }

    public static boolean hasLocationByExtId(ContentResolver resolver, String temp) {
        return queryForSingleRow(resolver, OpenHDS.Locations.CONTENT_ID_URI_BASE,
                OpenHDS.Locations.COLUMN_LOCATION_EXTID, temp);
    }

    public static Cursor getLocationByExtId(ContentResolver resolver, String extId) {
        return getCursor(resolver, OpenHDS.Locations.CONTENT_ID_URI_BASE, OpenHDS.Locations.COLUMN_LOCATION_EXTID,
                extId);
    }

    public static Cursor getLocationsByHierachy(ContentResolver resolver, String extId) {
        return getCursor(resolver, OpenHDS.Locations.CONTENT_ID_URI_BASE, OpenHDS.Locations.COLUMN_LOCATION_HIERARCHY,
                extId);
    }

    public static Cursor getHierarchyByExtId(ContentResolver contentResolver, String hierarchy) {
        return getCursor(contentResolver, OpenHDS.HierarchyItems.CONTENT_ID_URI_BASE,
                OpenHDS.HierarchyItems.COLUMN_HIERARCHY_EXTID, hierarchy);
    }

    public static Cursor getHierarchysByLevel(ContentResolver contentResolver, String hierarchyTopLevel) {
        return getCursor(contentResolver, OpenHDS.HierarchyItems.CONTENT_ID_URI_BASE,
                OpenHDS.HierarchyItems.COLUMN_HIERARCHY_LEVEL, hierarchyTopLevel);
    }

    public static Cursor getHierarchysByParent(ContentResolver contentResolver, String extId) {
        return getCursor(contentResolver, OpenHDS.HierarchyItems.CONTENT_ID_URI_BASE,
                OpenHDS.HierarchyItems.COLUMN_HIERARCHY_PARENT, extId);
    }

    public static boolean hasFieldWorker(ContentResolver resolver, String extId, String password) {
        Cursor cursor = resolver.query(OpenHDS.FieldWorkers.CONTENT_ID_URI_BASE,
                new String[] { OpenHDS.FieldWorkers.COLUMN_FIELDWORKER_EXTID },
                OpenHDS.FieldWorkers.COLUMN_FIELDWORKER_EXTID + " = ? AND "
                        + OpenHDS.FieldWorkers.COLUMN_FIELDWORKER_PASSWORD + " = ?", new String[] { extId, password },
                null);
        return isFound(cursor);
    }

    public static Cursor getFieldWorkByExtId(ContentResolver resolver, String extId) {
        return getCursor(resolver, OpenHDS.FieldWorkers.CONTENT_ID_URI_BASE,
                OpenHDS.FieldWorkers.COLUMN_FIELDWORKER_EXTID, extId);
    }

    public static boolean hasSocialGroupByExtId(ContentResolver resolver, String temp) {
        return queryForSingleRow(resolver, OpenHDS.SocialGroups.CONTENT_ID_URI_BASE,
                OpenHDS.SocialGroups.COLUMN_SOCIALGROUP_EXTID, temp);
    }

    public static Cursor getSocialGroupByName(ContentResolver resolver, String groupName) {
        return getCursor(resolver, OpenHDS.SocialGroups.CONTENT_ID_URI_BASE,
                OpenHDS.SocialGroups.COLUMN_SOCIALGROUP_GROUPNAME, groupName);
    }

    public static Cursor getSocialGroupsByIndividualExtId(ContentResolver resolver, String extId) {
        Uri uri = OpenHDS.Individuals.CONTENT_SG_URI_BASE.buildUpon().appendPath(extId).build();
        return resolver.query(uri, null, "x." + OpenHDS.IndividualGroups.COLUMN_INDIVIDUALUUID + " = ?",
                new String[] { extId }, "s." + OpenHDS.SocialGroups._ID);
    }

    public static Cursor allSocialGroups(ContentResolver resolver) {
        return resolver.query(OpenHDS.SocialGroups.CONTENT_ID_URI_BASE, null, null, null, null);
    }

    public static Cursor allRounds(ContentResolver contentResolver) {
        return contentResolver.query(OpenHDS.Rounds.CONTENT_ID_URI_BASE, null, null, null, null);
    }

    public static Cursor allLocations(ContentResolver contentResolver) {
        return contentResolver.query(OpenHDS.Locations.CONTENT_ID_URI_BASE, null, null, null, null);
    }

    public static Cursor getRelationshipByIndividualA(ContentResolver resolver, String extId) {
        return getCursor(resolver, OpenHDS.Relationships.CONTENT_ID_URI_BASE,
                OpenHDS.Relationships.COLUMN_RELATIONSHIP_INDIVIDUAL_A, extId);
    }

    public static Cursor getRelationshipByIndividualB(ContentResolver resolver, String extId) {
        return getCursor(resolver, OpenHDS.Relationships.CONTENT_ID_URI_BASE,
                OpenHDS.Relationships.COLUMN_RELATIONSHIP_INDIVIDUAL_B, extId);
    }
}




Java Source Code List

org.openhds.mobile.BadXmlException.java
org.openhds.mobile.Converter.java
org.openhds.mobile.FieldWorkerProvider.java
org.openhds.mobile.FormsProviderAPI.java
org.openhds.mobile.InstanceProviderAPI.java
org.openhds.mobile.OpenHDS.java
org.openhds.mobile.Queries.java
org.openhds.mobile.activity.AbstractActivity.java
org.openhds.mobile.activity.FieldWorkerLoginActivity.java
org.openhds.mobile.activity.FilterActivity.java
org.openhds.mobile.activity.FilterFormActivity.java
org.openhds.mobile.activity.FilterLocationActivity.java
org.openhds.mobile.activity.FilterVisitActivity.java
org.openhds.mobile.activity.FormListActivity.java
org.openhds.mobile.activity.FormViewActivity.java
org.openhds.mobile.activity.OpeningActivity.java
org.openhds.mobile.activity.ServerPreferencesActivity.java
org.openhds.mobile.activity.ShowMapActivity.java
org.openhds.mobile.activity.SupervisorLoginActivity.java
org.openhds.mobile.activity.SupervisorMainActivity.java
org.openhds.mobile.activity.SyncDatabaseActivity.java
org.openhds.mobile.activity.UpdateActivity.java
org.openhds.mobile.adapter.AdapterContent.java
org.openhds.mobile.adapter.MapAdapter.java
org.openhds.mobile.database.DatabaseAdapter.java
org.openhds.mobile.database.DeathUpdate.java
org.openhds.mobile.database.ExternalInMigrationUpdate.java
org.openhds.mobile.database.HouseholdUpdate.java
org.openhds.mobile.database.InternalInMigrationUpdate.java
org.openhds.mobile.database.LocationUpdate.java
org.openhds.mobile.database.MembershipUpdate.java
org.openhds.mobile.database.OutMigrationUpdate.java
org.openhds.mobile.database.PregnancyOutcomeUpdate.java
org.openhds.mobile.database.RelationshipUpdate.java
org.openhds.mobile.database.Updatable.java
org.openhds.mobile.database.VisitUpdate.java
org.openhds.mobile.fragment.EventFragment.java
org.openhds.mobile.fragment.ProgressFragment.java
org.openhds.mobile.fragment.SelectionFilterFragment.java
org.openhds.mobile.fragment.SelectionFilterLocFragment.java
org.openhds.mobile.fragment.SelectionFormFragment.java
org.openhds.mobile.fragment.SelectionFragment.java
org.openhds.mobile.fragment.ValueFormFragment.java
org.openhds.mobile.fragment.ValueFragment.java
org.openhds.mobile.fragment.ValueLocFragment.java
org.openhds.mobile.listener.CollectEntitiesListener.java
org.openhds.mobile.listener.OdkFormLoadListener.java
org.openhds.mobile.listener.RetrieveFieldWorkersListener.java
org.openhds.mobile.listener.TaskCompleteListener.java
org.openhds.mobile.listener.ValueSelectedListener.java
org.openhds.mobile.model.Child.java
org.openhds.mobile.model.FieldWorker.java
org.openhds.mobile.model.FilledForm.java
org.openhds.mobile.model.FilledParams.java
org.openhds.mobile.model.FormFiller.java
org.openhds.mobile.model.FormSubmissionRecord.java
org.openhds.mobile.model.FormXmlReader.java
org.openhds.mobile.model.Form.java
org.openhds.mobile.model.HierarchySelection.java
org.openhds.mobile.model.Individual.java
org.openhds.mobile.model.LocationHierarchy.java
org.openhds.mobile.model.LocationVisit.java
org.openhds.mobile.model.Location.java
org.openhds.mobile.model.Membership.java
org.openhds.mobile.model.PregnancyObservationUpdate.java
org.openhds.mobile.model.PregnancyOutcome.java
org.openhds.mobile.model.Relationship.java
org.openhds.mobile.model.Result.java
org.openhds.mobile.model.Round.java
org.openhds.mobile.model.SocialGroup.java
org.openhds.mobile.model.StateMachine.java
org.openhds.mobile.model.Supervisor.java
org.openhds.mobile.model.UpdateEvent.java
org.openhds.mobile.model.UpdateParams.java
org.openhds.mobile.model.UpdateStatus.java
org.openhds.mobile.model.Visit.java
org.openhds.mobile.provider.OpenHDSProvider.java
org.openhds.mobile.task.AbstractHttpTask.java
org.openhds.mobile.task.AuthenticateTask.java
org.openhds.mobile.task.DownloadFormsTask.java
org.openhds.mobile.task.FieldWorkerLoginTask.java
org.openhds.mobile.task.OdkFormLoadTask.java
org.openhds.mobile.task.OdkGeneratedFormLoadTask.java
org.openhds.mobile.task.SupervisorLoginTask.java
org.openhds.mobile.task.SyncEntitiesTask.java
org.openhds.mobile.task.SyncFormsTask.java
org.openhds.mobile.utilities.L.java
org.openhds.mobile.utilities.Logg.java
org.openhds.mobile.utilities.UrlUtils.java