use of m.co.rh.id.a_medic_log.base.entity.MedicineIntake in project a-medic-log by rh-id.
the class MedicineIntakeDetailPage method onMenuItemClick.
@Override
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
if (id == R.id.menu_save) {
boolean isUpdate = isUpdate();
Context context = mSvProvider.getContext();
MedicineIntake medicineIntake = mMedicineIntakeSubject.getValue();
if (mNewMedicineIntakeCmd.valid(medicineIntake)) {
mRxDisposer.add("onMenuItemClick_saveMedicineIntake", mNewMedicineIntakeCmd.execute(medicineIntake).observeOn(AndroidSchedulers.mainThread()).subscribe((medicineIntake1, throwable) -> {
String errorMessage;
String successMessage;
if (isUpdate) {
errorMessage = context.getString(R.string.error_failed_to_update_medicine_intake);
successMessage = context.getString(R.string.success_updating_medicine_intake);
} else {
errorMessage = context.getString(R.string.error_failed_to_add_medicine_intake);
successMessage = context.getString(R.string.success_adding_medicine_intake);
}
if (throwable != null) {
mSvProvider.get(ILogger.class).e(TAG, errorMessage, throwable);
mNavigator.pop();
} else {
mSvProvider.get(ILogger.class).i(TAG, successMessage);
mNavigator.pop(Result.with(medicineIntake));
}
}));
} else {
String error = mNewMedicineIntakeCmd.getValidationError();
mSvProvider.get(ILogger.class).i(TAG, error);
}
return true;
}
return false;
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineIntake in project a-medic-log by rh-id.
the class MedicineIntakeDetailPage method initState.
@Override
protected void initState(Activity activity) {
super.initState(activity);
if (isUpdate()) {
mMedicineIntakeSubject = new SerialBehaviorSubject<>(getMedicineIntake());
} else {
MedicineIntake medicineIntake = new MedicineIntake();
medicineIntake.medicineId = getMedicineId();
mMedicineIntakeSubject = new SerialBehaviorSubject<>(medicineIntake);
}
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineIntake in project a-medic-log by rh-id.
the class MedicineIntakeDetailPage method updateTakenDateTime.
private void updateTakenDateTime(Date date) {
MedicineIntake medicineIntake = mMedicineIntakeSubject.getValue();
medicineIntake.takenDateTime = date;
mMedicineIntakeSubject.onNext(medicineIntake);
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineIntake in project a-medic-log by rh-id.
the class NoteDaoTest method insertUpdateDelete_noteState.
@Test
public void insertUpdateDelete_noteState() {
NoteDao noteDao = mAppDatabase.noteDao();
MedicineDao medicineDao = mAppDatabase.medicineDao();
String noteContent = "test note";
String noteTagTag = "sample tag";
String medicineName = "test medicine name";
String medicineIntakeDesc = "test medicine intake";
String medicineReminderMessage = "test medicine reminder message";
NoteState noteState = new NoteState();
Note note = new Note();
note.content = noteContent;
noteState.updateNote(note);
NoteTag noteTag = new NoteTag();
noteTag.tag = noteTagTag;
noteState.updateNoteTagSet(Collections.singletonList(noteTag));
List<MedicineState> medicineStateList = new ArrayList<>();
MedicineState medicineState = new MedicineState();
Medicine medicine = new Medicine();
medicine.name = medicineName;
medicineState.updateMedicine(medicine);
MedicineReminder medicineReminder = new MedicineReminder();
medicineReminder.message = medicineReminderMessage;
medicineState.updateMedicineReminderList(Collections.singletonList(medicineReminder));
medicineStateList.add(medicineState);
noteState.updateMedicineStates(medicineStateList);
// INSERT NOTE
noteDao.insertNote(noteState);
assertEquals(1, noteDao.countNote());
assertEquals(1, noteDao.countNoteTag());
assertEquals(1, medicineDao.countMedicine());
assertEquals(1, medicineDao.countMedicineReminder());
assertEquals(0, medicineDao.countMedicineIntake());
Note noteFromInsert = noteDao.findNoteById(noteState.getNoteId());
assertEquals(noteContent, noteFromInsert.content);
List<NoteTag> noteTagListFromInsert = noteDao.findNoteTagsByNoteId(noteState.getNoteId());
assertEquals(1, noteTagListFromInsert.size());
assertEquals(noteTagTag, noteTagListFromInsert.get(0).tag);
List<Medicine> medicineListFromInsert = noteDao.findMedicinesByNoteId(noteState.getNoteId());
assertEquals(1, medicineListFromInsert.size());
assertEquals(medicineName, medicineListFromInsert.get(0).name);
List<MedicineReminder> medicineReminderListFromInsert = medicineDao.findMedicineRemindersByMedicineId(medicineListFromInsert.get(0).id);
assertEquals(1, medicineReminderListFromInsert.size());
assertEquals(medicineReminderMessage, medicineReminderListFromInsert.get(0).message);
// try insert medicine intake
MedicineIntake medicineIntake = new MedicineIntake();
medicineIntake.medicineId = medicineListFromInsert.get(0).id;
medicineIntake.description = medicineIntakeDesc;
medicineDao.insert(medicineIntake);
// after that update note
String noteContentUpdate = noteContent + " updated ";
noteState.getNote().content = noteContentUpdate;
// UPDATE NOTE
noteDao.updateNote(noteState);
assertEquals(1, noteDao.countNote());
assertEquals(1, noteDao.countNoteTag());
assertEquals(1, medicineDao.countMedicine());
assertEquals(1, medicineDao.countMedicineReminder());
assertEquals(1, medicineDao.countMedicineIntake());
Note noteFromUpdate = noteDao.findNoteById(noteState.getNoteId());
assertEquals(noteContentUpdate, noteFromUpdate.content);
List<NoteTag> noteTagListFromUpdate = noteDao.findNoteTagsByNoteId(noteState.getNoteId());
assertEquals(1, noteTagListFromUpdate.size());
assertEquals(noteTagTag, noteTagListFromUpdate.get(0).tag);
List<Medicine> medicineListFromUpdate = noteDao.findMedicinesByNoteId(noteState.getNoteId());
assertEquals(1, medicineListFromUpdate.size());
assertEquals(medicineName, medicineListFromUpdate.get(0).name);
List<MedicineReminder> medicineReminderListFromUpdate = medicineDao.findMedicineRemindersByMedicineId(medicineListFromUpdate.get(0).id);
assertEquals(1, medicineReminderListFromUpdate.size());
assertEquals(medicineReminderMessage, medicineReminderListFromUpdate.get(0).message);
// ensure medicine intake not deleted when updating note state
MedicineIntake updateNoteMedicineIntake = medicineDao.findLastMedicineIntake(medicineIntake.medicineId);
assertNotNull(updateNoteMedicineIntake);
assertEquals(medicineIntakeDesc, updateNoteMedicineIntake.description);
// DELETE NOTE
noteDao.deleteNote(noteState);
assertEquals(0, noteDao.countNote());
assertEquals(0, noteDao.countNoteTag());
assertEquals(0, medicineDao.countMedicine());
assertEquals(0, medicineDao.countMedicineReminder());
assertEquals(0, medicineDao.countMedicineIntake());
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineIntake in project a-medic-log by rh-id.
the class MedicineIntakeListSV method confirmDeleteMedicineIntake.
private void confirmDeleteMedicineIntake(MedicineIntake medicineIntake) {
Context context = mSvProvider.getContext();
mRxDisposer.add("confirmDeleteMedicineIntake_deleteMedicineIntake", mDeleteMedicineIntakeCmd.execute(medicineIntake).observeOn(AndroidSchedulers.mainThread()).subscribe((note, throwable) -> {
String errorMessage = context.getString(R.string.error_failed_to_delete_medicine_intake);
String successMessage = context.getString(R.string.success_deleting_medicine_intake);
if (throwable != null) {
mSvProvider.get(ILogger.class).e(TAG, errorMessage, throwable);
} else {
mSvProvider.get(ILogger.class).i(TAG, successMessage);
mMedicineIntakeRecyclerViewAdapter.notifyItemDeleted(medicineIntake);
}
}));
}
Aggregations