CMPUT301F18T24 / Mark-Me

This is an Android app for keeping track of medical issues.
Apache License 2.0
4 stars 4 forks source link

Elastic Search - Problems and Records #50

Open vppatel111 opened 5 years ago

vppatel111 commented 5 years ago

Implemented adding and searching problems. Here are example implementations:

// Both these functions assume the user has logged in already.
// Example adding problem.
public void testAddProblem() {

    try {
        ProblemModel newProblem = new ProblemModel("Test1", "This is a description.");
        new ElasticSearchIOController.AddProblemTask().execute(newProblem);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

// Example getting problem.
public void testGetProblem() {

    UserProfileController profileController = UserProfileController.getInstance();

    try {
        ArrayList<ProblemModel> problems = new ArrayList<>();
        problems = new ElasticSearchIOController.GetProblemTask().execute(profileController.user.getUserID()).get();

        for (ProblemModel problem : problems) {
            Log.d("Vishal_Problem: ", problem.getProblemID());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}
vppatel111 commented 5 years ago

I so far implemented adding records, I still want to test if pictures are properly being saved and retrieved from the elasticsearch database. Implementation of getting records is still pending.

vppatel111 commented 5 years ago

I discovered a bug, when I convert the JSON pulled from elastic search into problem objects, it skips the constructor so the list of records in the problem model is initialized to null which causes problems when adding records to a problem. I implemented a temporary fix but we should implement a permanent one in the future.

vppatel111 commented 5 years ago

Implemented adding and getting records. Note: I need a problemID and I assume that the user has logged on. Here are example implementations:

    // Both these functions assume the user has logged in already.
    // Example adding record.
    public void testAddRecord() {

        UserProfileController profileController = UserProfileController.getInstance();
        try {
            ArrayList<ProblemModel> problems = new ArrayList<>();
            problems = new ElasticSearchIOController.GetProblemTask().execute(profileController.user.getUserID()).get();

            RecordModel newRecord = new RecordModel("TestRecord2", "Record description");

            newRecord.addPhoto(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888));
            newRecord.setBodyLocation(new BodyLocation(EBodyPart.ABDOMEN));
            Location newLocation = new Location("");
            newLocation.setLatitude(0.0d);
            newLocation.setLongitude(0.0d);
            newRecord.setMapLocation(newLocation);

            problems.get(0).initializeRecordModel(); // This fixes the null records arraylist.

            problems.get(0).addRecord(newRecord);

            // Pass the problem for which you want to save all records.
            new ElasticSearchIOController.AddRecordTask().execute(problems.get(0));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // Example getting record.
    public void testGetRecord() {

        UserProfileController profileController = UserProfileController.getInstance();
        try {
            ArrayList<ProblemModel> problems = new ArrayList<>();
            problems = new ElasticSearchIOController.GetProblemTask().execute(profileController.user.getUserID()).get();

            ArrayList<RecordModel> records = new ArrayList<>();

            // I know that the first problem pulled will have some records in elasticsearch db.
            records = new ElasticSearchIOController.GetRecordTask().execute(problems.get(0).getProblemID()).get();

            for (RecordModel record : records) {
                Log.d("Vishal", record.getRecordID());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }