List of usage examples for org.joda.time LocalDate now
public static LocalDate now()
ISOChronology
in the default time zone. From source file:org.projectbuendia.client.ui.dialogs.EditPatientDialogFragment.java
License:Apache License
private void populateFields(Bundle args) { String idPrefix = ""; String id = Utils.valueOrDefault(args.getString("id"), ""); Matcher matcher = ID_PATTERN.matcher(id); if (matcher.matches()) { idPrefix = matcher.group(1);//from w ww .jav a2 s.c o m id = matcher.group(2); } if (idPrefix.isEmpty() && id.isEmpty()) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity()); idPrefix = pref.getString("last_id_prefix", ""); } mIdPrefix.setText(idPrefix); mId.setText(id); mGivenName.setText(Utils.valueOrDefault(args.getString("givenName"), "")); mFamilyName.setText(Utils.valueOrDefault(args.getString("familyName"), "")); LocalDate birthdate = Utils.toLocalDate(args.getString("birthdate")); if (birthdate != null) { Period age = new Period(birthdate, LocalDate.now()); mAgeYears.setText(String.valueOf(age.getYears())); mAgeMonths.setText(String.valueOf(age.getMonths())); } switch (args.getInt("gender", Patient.GENDER_UNKNOWN)) { case Patient.GENDER_FEMALE: mSexFemale.setChecked(true); break; case Patient.GENDER_MALE: mSexMale.setChecked(true); break; } }
From source file:org.projectbuendia.client.ui.dialogs.EditPatientDialogFragment.java
License:Apache License
public void onSubmit() { String idPrefix = mIdPrefix.getText().toString().trim(); String id = mId.getText().toString().trim(); String givenName = Utils.toNonemptyOrNull(mGivenName.getText().toString().trim()); String familyName = Utils.toNonemptyOrNull(mFamilyName.getText().toString().trim()); String ageYears = mAgeYears.getText().toString().trim(); String ageMonths = mAgeMonths.getText().toString().trim(); LocalDate birthdate = null;//from w w w .j av a 2s . co m LocalDate admissionDate = LocalDate.now(); if (!ageYears.isEmpty() || !ageMonths.isEmpty()) { birthdate = LocalDate.now().minusYears(Integer.parseInt("0" + ageYears)) .minusMonths(Integer.parseInt("0" + ageMonths)); } // TODO: This should start out as "Sex sex = null" and then get set to female, male, // other, or unknown if any button is selected (there should be four buttons) -- so // that we can distinguish "no change to sex" (null) from "change sex to unknown" ("U"). int sex = Patient.GENDER_UNKNOWN; switch (mSex.getCheckedRadioButtonId()) { case R.id.patient_sex_female: sex = Patient.GENDER_FEMALE; break; case R.id.patient_sex_male: sex = Patient.GENDER_MALE; break; } id = idPrefix.isEmpty() ? id : idPrefix + "/" + id; Utils.logUserAction("patient_submitted", "id", id, "given_name", givenName, "family_name", familyName, "age_years", ageYears, "age_months", ageMonths, "sex", "" + sex); PatientDelta delta = new PatientDelta(); delta.id = Optional.of(id); delta.givenName = Optional.fromNullable(givenName); delta.familyName = Optional.fromNullable(familyName); delta.birthdate = Optional.fromNullable(birthdate); delta.gender = Optional.of(sex); delta.admissionDate = Optional.of(admissionDate); if (!idPrefix.isEmpty()) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity()); pref.edit().putString("last_id_prefix", idPrefix).commit(); } Bundle args = getArguments(); if (args.getBoolean("new")) { if (id != null || givenName != null || familyName != null || birthdate != null || sex != Patient.GENDER_UNKNOWN) { mModel.addPatient(mCrudEventBus, delta); } } else { mModel.updatePatient(mCrudEventBus, args.getString("uuid"), delta); } // TODO: While the network request is in progress, show a spinner and/or keep the // dialog open but greyed out -- keep the UI blocked to make it clear that there is a // modal operation going on, while providing a way for the user to abort the operation. }
From source file:org.projectbuendia.client.ui.dialogs.OrderExecutionDialogFragment.java
License:Apache License
void updateUi(boolean orderExecutedNow) { Bundle args = getArguments();//from w w w . j a v a 2s.c o m LocalDate date = new DateTime(Utils.getLong(args, "intervalStartMillis")).toLocalDate(); List<DateTime> executionTimes = new ArrayList<>(); for (long millis : args.getLongArray("executionTimes")) { executionTimes.add(new DateTime(millis)); } // Show what was ordered and when the order started. mOrderInstructions.setText(args.getString("instructions")); DateTime start = Utils.getDateTime(args, "orderStartMillis"); mOrderStartTime.setText(getResources().getString(R.string.order_started_on_date_at_time, Utils.toShortString(start.toLocalDate()), Utils.toTimeOfDayString(start))); // Describe how many times the order was executed during the selected interval. int count = executionTimes.size() + (orderExecutedNow ? 1 : 0); boolean plural = count != 1; mOrderExecutionCount.setText(Html.fromHtml(getResources().getString( date.equals(LocalDate.now()) ? (plural ? R.string.order_execution_today_plural_html : R.string.order_execution_today_singular_html) : (plural ? R.string.order_execution_historical_plural_html : R.string.order_execution_historical_singular_html), count, Utils.toShortString(date)))); // Show the list of times that the order was executed during the selected interval. boolean editable = args.getBoolean("editable"); Utils.showIf(mOrderExecutionList, executionTimes.size() > 0 || editable); List<String> htmlItems = new ArrayList<>(); for (DateTime executionTime : executionTimes) { htmlItems.add(Utils.toTimeOfDayString(executionTime)); } if (editable) { DateTime encounterTime = Utils.getDateTime(args, "encounterTimeMillis"); htmlItems.add( orderExecutedNow ? "<b>" + Utils.toTimeOfDayString(encounterTime) + "</b>" : "<b> </b>"); // keep total height stable } mOrderExecutionList.setText(Html.fromHtml(Joiner.on("<br>").join(htmlItems))); }
From source file:org.projectbuendia.client.ui.FunctionalTestCase.java
License:Apache License
/** * Adds a new patient using the new patient form. Assumes that the UI is * in the location selection activity, and leaves the UI in the same * activity. Note: this function will not work during {@link #setUp()} * as it relies on {@link #waitForProgressFragment()}. * @param delta an AppPatientDelta containing the data for the new patient; * use Optional.absent() to leave fields unset * @param locationName the name of a location to assign to the new patient, * or null to leave unset (assumes this name is unique among locations) *//*from w w w . j a va 2 s . c o m*/ protected void inLocationSelectionAddNewPatient(AppPatientDelta delta, String locationName) { LOG.i("Adding patient: %s (location %s)", delta.toContentValues().toString(), locationName); onView(withId(R.id.action_add)).perform(click()); onView(withText("New Patient")).check(matches(isDisplayed())); if (delta.id.isPresent()) { onView(withId(R.id.patient_creation_text_patient_id)).perform(typeText(delta.id.get())); } if (delta.givenName.isPresent()) { onView(withId(R.id.patient_creation_text_patient_given_name)).perform(typeText(delta.givenName.get())); } if (delta.familyName.isPresent()) { onView(withId(R.id.patient_creation_text_patient_family_name)) .perform(typeText(delta.familyName.get())); } if (delta.birthdate.isPresent()) { Period age = new Period(delta.birthdate.get().toLocalDate(), LocalDate.now()); if (age.getYears() < 1) { onView(withId(R.id.patient_creation_text_age)).perform(typeText(Integer.toString(age.getMonths()))); onView(withId(R.id.patient_creation_radiogroup_age_units_months)).perform(click()); } else { onView(withId(R.id.patient_creation_text_age)).perform(typeText(Integer.toString(age.getYears()))); onView(withId(R.id.patient_creation_radiogroup_age_units_years)).perform(click()); } } if (delta.gender.isPresent()) { if (delta.gender.get() == AppPatient.GENDER_MALE) { onView(withId(R.id.patient_creation_radiogroup_age_sex_male)).perform(click()); } else if (delta.gender.get() == AppPatient.GENDER_FEMALE) { onView(withId(R.id.patient_creation_radiogroup_age_sex_female)).perform(click()); } } if (delta.admissionDate.isPresent()) { // TODO/completeness: Support admission date in addNewPatient(). // The following code is broken -- hopefully fixed by Espresso 2.0. // onView(withId(R.id.patient_creation_admission_date)).perform(click()); // selectDateFromDatePickerDialog(mDemoPatient.admissionDate.get()); } if (delta.firstSymptomDate.isPresent()) { // TODO/completeness: Support first symptoms date in addNewPatient(). // The following code is broken -- hopefully fixed by Espresso 2.0. // onView(withId(R.id.patient_creation_symptoms_onset_date)).perform(click()); // selectDateFromDatePickerDialog(mDemoPatient.firstSymptomDate.get()); } if (delta.assignedLocationUuid.isPresent()) { // TODO/completeness: Support assigned location in addNewPatient(). // A little tricky as we need to select by UUID. // onView(withId(R.id.patient_creation_button_change_location)).perform(click()); } if (locationName != null) { onView(withId(R.id.patient_creation_button_change_location)).perform(click()); onView(withText(locationName)).perform(click()); } EventBusIdlingResource<SingleItemCreatedEvent<AppPatient>> resource = new EventBusIdlingResource<>( UUID.randomUUID().toString(), mEventBus); onView(withId(R.id.patient_creation_button_create)).perform(click()); Espresso.registerIdlingResources(resource); // wait for patient to be created }
From source file:org.projectbuendia.client.ui.FunctionalTestCase.java
License:Apache License
/** * Ensures that a demo patient exists, creating one if necessary. Assumes * that the UI is in the user login activity, and leaves the UI back in * the user login activity. Note: this function will not work during * {@link #setUp()} as it relies on {@link #waitForProgressFragment()}. *//*from w ww . j a va 2 s . co m*/ protected void inUserLoginInitDemoPatient() { if (sDemoPatientId != null) { // demo patient exists and is reusable return; } AppPatientDelta delta = new AppPatientDelta(); String id = "" + (System.currentTimeMillis() % 100000); delta.id = Optional.of(id); delta.givenName = Optional.of("Given" + id); delta.familyName = Optional.of("Family" + id); delta.firstSymptomDate = Optional.of(LocalDate.now().minusMonths(7)); delta.gender = Optional.of(Patient.GENDER_FEMALE); delta.birthdate = Optional.of(DateTime.now().minusYears(12).minusMonths(3)); // Setting location within the AppPatientDelta is not yet supported. // delta.assignedLocationUuid = Optional.of(Zone.TRIAGE_ZONE_UUID); inUserLoginGoToLocationSelection(); inLocationSelectionAddNewPatient(delta, "S1"); // add the patient sDemoPatientId = id; // record ID so future tests can reuse the patient pressBack(); // return to user login activity }
From source file:org.projectbuendia.client.ui.patientcreation.PatientCreationActivity.java
License:Apache License
@Override protected void onCreateImpl(Bundle savedInstanceState) { super.onCreateImpl(savedInstanceState); App.getInstance().inject(this); CrudEventBus crudEventBus = mCrudEventBusProvider.get(); mController = new PatientCreationController(new MyUi(), crudEventBus, mModel); mAlertDialog = new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_info) .setTitle(R.string.title_add_patient_cancel) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override// w w w . j av a 2 s . c o m public void onClick(DialogInterface dialog, int i) { finish(); } }).setNegativeButton("No", null).create(); setContentView(R.layout.activity_patient_creation); ButterKnife.inject(this); DateTime now = DateTime.now(); mAdmissionDateSetListener = new DateSetListener(mAdmissionDate, LocalDate.now()); mAdmissionDatePickerDialog = new DatePickerDialog(this, mAdmissionDateSetListener, now.getYear(), now.getMonthOfYear() - 1, now.getDayOfMonth()); mAdmissionDatePickerDialog.setTitle(R.string.admission_date_picker_title); mAdmissionDatePickerDialog.getDatePicker().setCalendarViewShown(false); mSymptomsOnsetDateSetListener = new DateSetListener(mSymptomsOnsetDate, null); mSymptomsOnsetDatePickerDialog = new DatePickerDialog(this, mSymptomsOnsetDateSetListener, now.getYear(), now.getMonthOfYear() - 1, now.getDayOfMonth()); mSymptomsOnsetDatePickerDialog.setTitle(R.string.symptoms_onset_date_picker_title); mSymptomsOnsetDatePickerDialog.getDatePicker().setCalendarViewShown(false); mLocationSelectedCallback = new AssignLocationDialog.LocationSelectedCallback() { @Override public boolean onNewTentSelected(String newTentUuid) { mLocationUuid = newTentUuid; updateLocationUi(); return true; } }; // Pre-populate admission date with today. mAdmissionDate.setText(Dates.toMediumString(DateTime.now().toLocalDate())); }
From source file:org.projectbuendia.client.ui.patientcreation.PatientCreationController.java
License:Apache License
public boolean createPatient(String id, String givenName, String familyName, String age, int ageUnits, int sex, LocalDate admissionDate, LocalDate symptomsOnsetDate, String locationUuid) { // Validate the input. mUi.clearValidationErrors();// w ww . j a v a 2s . c o m boolean hasValidationErrors = false; if (id == null || id.equals("")) { mUi.showValidationError(Ui.FIELD_ID, R.string.patient_validation_missing_id); hasValidationErrors = true; } if (age == null || age.equals("")) { mUi.showValidationError(Ui.FIELD_AGE, R.string.patient_validation_missing_age); hasValidationErrors = true; } if (admissionDate == null) { mUi.showValidationError(Ui.FIELD_ADMISSION_DATE, R.string.patient_validation_missing_admission_date); hasValidationErrors = true; } int ageInt = 0; try { ageInt = Integer.parseInt(age); } catch (NumberFormatException e) { mUi.showValidationError(Ui.FIELD_AGE, R.string.patient_validation_whole_number_age_required); hasValidationErrors = true; } if (ageInt < 0) { mUi.showValidationError(Ui.FIELD_AGE, R.string.patient_validation_negative_age); hasValidationErrors = true; } if (ageUnits != AGE_YEARS && ageUnits != AGE_MONTHS) { mUi.showValidationError(Ui.FIELD_AGE_UNITS, R.string.patient_validation_select_years_or_months); hasValidationErrors = true; } if (sex != SEX_MALE && sex != SEX_FEMALE) { mUi.showValidationError(Ui.FIELD_SEX, R.string.patient_validation_select_gender); hasValidationErrors = true; } if (admissionDate != null && admissionDate.isAfter(LocalDate.now())) { mUi.showValidationError(Ui.FIELD_ADMISSION_DATE, R.string.patient_validation_future_admission_date); hasValidationErrors = true; } if (symptomsOnsetDate != null && symptomsOnsetDate.isAfter(LocalDate.now())) { mUi.showValidationError(Ui.FIELD_SYMPTOMS_ONSET_DATE, R.string.patient_validation_future_onset_date); hasValidationErrors = true; } Utils.logUserAction("add_patient_submitted", "valid", "" + !hasValidationErrors); if (hasValidationErrors) { return false; } AppPatientDelta patientDelta = new AppPatientDelta(); patientDelta.id = Optional.of(id); patientDelta.givenName = Optional.of(Utils.nameOrUnknown(givenName)); patientDelta.familyName = Optional.of(Utils.nameOrUnknown(familyName)); patientDelta.birthdate = Optional.of(getBirthdateFromAge(ageInt, ageUnits)); patientDelta.gender = Optional.of(sex); patientDelta.assignedLocationUuid = Optional.of(Utils.valueOrDefault(locationUuid, Zone.DEFAULT_LOCATION)); patientDelta.admissionDate = Optional.of(admissionDate); patientDelta.firstSymptomDate = Optional.fromNullable(symptomsOnsetDate); mModel.addPatient(mCrudEventBus, patientDelta); return true; }
From source file:org.projectbuendia.client.utils.date.Dates.java
License:Apache License
/** Converts a birthdate to a string describing age in months or years. */ public static String birthdateToAge(LocalDate birthdate) { // TODO: Localization Period age = new Period(birthdate, LocalDate.now()); if (age.getYears() >= 2) { return "" + age.getYears() + " y"; } else {/*from ww w . ja v a 2 s .c o m*/ return "" + (age.getYears() * 12 + age.getMonths()) + " mo"; } }
From source file:org.projectbuendia.client.utils.RelativeDateTimeFormatter.java
License:Apache License
public String format(LocalDate date) { return format(date, LocalDate.now()); }
From source file:org.projectbuendia.client.utils.Utils.java
License:Apache License
/** Converts a birthdate to a string describing age in months or years. */ public static String birthdateToAge(LocalDate birthdate, Resources resources) { Period age = new Period(birthdate, LocalDate.now()); int years = age.getYears(), months = age.getMonths(); return years >= 5 ? resources.getString(R.string.abbrev_n_years, years) : resources.getString(R.string.abbrev_n_months, months + years * 12); }