Search in sources :

Example 1 with Prescription

use of com.hci.carebase.domain.Prescription 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)

Aggregations

Intent (android.content.Intent)1 OnClick (butterknife.OnClick)1 PatientSource (com.hci.carebase.data.interfaces.PatientSource)1 Appointment (com.hci.carebase.domain.Appointment)1 Doctor (com.hci.carebase.domain.Doctor)1 Patient (com.hci.carebase.domain.Patient)1 Prescription (com.hci.carebase.domain.Prescription)1 Summary (com.hci.carebase.domain.Summary)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1