Search in sources :

Example 1 with Patient

use of com.hci.carebase.domain.Patient in project Carebase by robertsimoes.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    /**
     * Set Toolbar
     */
    Toolbar myToolbar = (Toolbar) findViewById(R.id.general_fragments_toolbar);
    setSupportActionBar(myToolbar);
    ILocalCache cache = new LocalCacheDb(this);
    String userId = cache.getUserId();
    boolean isFirstInstall = cache.isFirstInstall();
    if (isFirstInstall) {
        cache.setFirstInstall(false);
        startActivity(new Intent(this, IntroActivity.class));
    }
    /* Get Patient Info */
    src.getPatient(userId, new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Toast.makeText(MainActivity.this, "Welcome Back!", Toast.LENGTH_SHORT).show();
            Log.d("TAG", "SUCCESS \n\n\n\n ------");
            Patient p = dataSnapshot.getValue(Patient.class);
            fragmentArgs = new Bundle();
            fragmentArgs.putSerializable(Const.BUNDLE_KEY_PATIENT, p);
            BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.main_bottom_navigation);
            bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {

                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.action_inbox:
                            invalidateOptionsMenu();
                            selectedFragment = InboxFragment.newInstance(fragmentArgs);
                            currentFragment = Frag.INBOX;
                            break;
                        case R.id.action_appointments:
                            invalidateOptionsMenu();
                            AppointmentsFragment f = AppointmentsFragment.newInstance(fragmentArgs);
                            f.setCallback(MainActivity.this);
                            selectedFragment = f;
                            currentFragment = Frag.APPOINTMENTS;
                            break;
                        case R.id.action_rx:
                            invalidateOptionsMenu();
                            selectedFragment = RxFragment.newInstance(fragmentArgs);
                            currentFragment = Frag.RX;
                            break;
                        case R.id.action_profile:
                            invalidateOptionsMenu();
                            selectedFragment = ProfileFragment.newInstance(fragmentArgs);
                            currentFragment = Frag.PROFILE_EDIT;
                            break;
                    }
                    refreshFragmentUI(selectedFragment);
                    return true;
                }
            });
        // Before the application or user has picked anything to display
        // Let's just display the inbox fragment by default so that when the app loads up
        // we pick that.
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e("ERR", "Could not load patient snapshot" + databaseError.getDetails());
        }
    });
}
Also used : IntroActivity(com.hci.carebase.ui.activities.IntroActivity) Bundle(android.os.Bundle) Patient(com.hci.carebase.domain.Patient) ILocalCache(com.hci.carebase.data.interfaces.ILocalCache) Intent(android.content.Intent) MenuItem(android.view.MenuItem) DataSnapshot(com.google.firebase.database.DataSnapshot) LocalCacheDb(com.hci.carebase.data.datasource.LocalCacheDb) DatabaseError(com.google.firebase.database.DatabaseError) BottomNavigationView(android.support.design.widget.BottomNavigationView) NonNull(android.support.annotation.NonNull) AppointmentsFragment(com.hci.carebase.ui.fragments.AppointmentsFragment) ValueEventListener(com.google.firebase.database.ValueEventListener) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with Patient

use of com.hci.carebase.domain.Patient in project Carebase by robertsimoes.

the class DebugFragment method onPatientCreate.

@OnClick(R.id.debug_but_patient_create)
public void onPatientCreate(View v) {
    final Patient p = Faker.fakePatient();
    Log.d("Patient", p.toString());
    String fakeUser = UUID.randomUUID().toString();
    provider.createPatient(p, fakeUser, new OnCompleteListener<Void>() {

        @Override
        public void onComplete(@NonNull Task<Void> task) {
            String result = "Create Patient " + p.getFirstName() + " " + p.getLastName();
            results.setText(result);
        }
    });
}
Also used : Patient(com.hci.carebase.domain.Patient) OnClick(butterknife.OnClick)

Example 3 with Patient

use of com.hci.carebase.domain.Patient in project Carebase by robertsimoes.

the class Faker method fakePatient.

public static Patient fakePatient() {
    int num = (int) Math.floor(Math.random() * 2);
    Patient p = patients[num];
    p.getSummaries().add(summaries[num]);
    // p.getHealthInfo().getMedicalConditions() = conditions[num];
    p.getScripts().add(scripts[num]);
    return p;
}
Also used : Patient(com.hci.carebase.domain.Patient)

Example 4 with Patient

use of com.hci.carebase.domain.Patient in project Carebase by robertsimoes.

the class LoginRegisterActivity method onExecSignUpButtonClick.

@OnClick(R.id.vs_signup_button_exec_signup)
public void onExecSignUpButtonClick(View v) {
    PatientSource src = CollectionsProvider.patients();
    if (signup_signUpPasswordEt.getText().toString().equals(signup_signUpConfirmEt.getText().toString())) {
        progressDialog = ProgressDialog.show(this, "Please wait...", "Processing...", true);
        (fauth.createUserWithEmailAndPassword(signup_signUpEmailEt.getText().toString(), signup_signUpPasswordEt.getText().toString())).addOnCompleteListener(task -> {
            progressDialog.dismiss();
            if (task.isSuccessful()) {
                Toast.makeText(this, "Registration successful", Toast.LENGTH_LONG).show();
                String uid = fauth.getUid();
                cache.storeUserId(uid);
                Doctor d = new Doctor(signup_signUpDoctorFnameEt.getText().toString(), signup_signUpDoctorLnameEt.getText().toString());
                Appointment a = new Appointment(new Date(), "University Hospital", d, "", "");
                Calendar c = Calendar.getInstance();
                c.add(Calendar.YEAR, 1);
                Date finishDate = c.getTime();
                Patient p = new Patient(signup_patient_fname.getText().toString(), signup_patient_lname.getText().toString(), signup_signUpHCardNum.getText().toString(), d, new ArrayList<Appointment>() {

                    {
                        add(a);
                    }
                }, new ArrayList<Summary>() {

                    {
                        add(Faker.fakeSummary());
                    }
                }, new ArrayList<Prescription>() {

                    {
                        add(Faker.fakeScript());
                    }
                }, Faker.fakeInfo(), finishDate);
                src.createPatient(p, uid, task1 -> {
                    if (task1.isSuccessful()) {
                        Intent intent = new Intent(this, IntroActivity.class);
                        startActivity(intent);
                        finish();
                    } else {
                        Toast.makeText(this, task1.getException().getMessage() != null ? task1.getException().getMessage() : "Error signing up, please try again", Toast.LENGTH_LONG).show();
                    }
                });
            } else {
                Toast.makeText(this, task.getException().getMessage() != null ? task.getException().getMessage() : "Error signing up, please try again", Toast.LENGTH_LONG).show();
            }
        });
    } else {
        Toast.makeText(this, "Passwords not equal!", Toast.LENGTH_LONG).show();
        signup_signUpPasswordEt.getText().clear();
        signup_signUpConfirmEt.getText().clear();
    }
}
Also used : Appointment(com.hci.carebase.domain.Appointment) Prescription(com.hci.carebase.domain.Prescription) Calendar(java.util.Calendar) Patient(com.hci.carebase.domain.Patient) Intent(android.content.Intent) PatientSource(com.hci.carebase.data.interfaces.PatientSource) Doctor(com.hci.carebase.domain.Doctor) Date(java.util.Date) Summary(com.hci.carebase.domain.Summary) OnClick(butterknife.OnClick)

Example 5 with Patient

use of com.hci.carebase.domain.Patient in project Carebase by robertsimoes.

the class DebugFragment method onPatientGet.

@OnClick(R.id.debug_but_patient_get)
public void onPatientGet(View v) {
    String id = patientGet.getText().toString();
    // String id = "-L8bwHp6Kr6GoU1DvU4Z";
    provider.getPatient(id, new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Patient p = dataSnapshot.getValue(Patient.class);
            if (p != null) {
                Log.d("Fetched: ", p.toString());
                results.setText("Fetched! " + p.toString());
            } else {
                Log.d("Fetched: ", "No user");
                results.setText("No user");
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Patient(com.hci.carebase.domain.Patient) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) OnClick(butterknife.OnClick)

Aggregations

Patient (com.hci.carebase.domain.Patient)7 OnClick (butterknife.OnClick)4 DataSnapshot (com.google.firebase.database.DataSnapshot)3 DatabaseError (com.google.firebase.database.DatabaseError)3 ValueEventListener (com.google.firebase.database.ValueEventListener)3 Intent (android.content.Intent)2 NonNull (android.support.annotation.NonNull)2 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 BottomNavigationView (android.support.design.widget.BottomNavigationView)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)1 Task (com.google.android.gms.tasks.Task)1 LocalCacheDb (com.hci.carebase.data.datasource.LocalCacheDb)1