Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AC-450 Created Admission simple #696

Merged
merged 16 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class LocationRoomDAOTest {
public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule();

private AppDatabase mDatabase;
private LocationEntity expectedLocationEntity1 = createDemoLocationEntity(10L, "name", "description", "display");
private LocationEntity expectedLocationEntity2 = createDemoLocationEntity(20L, "name2", "description2", "display2");
private LocationEntity expectedLocationEntity1 = createDemoLocationEntity(10L, "uuid1", "name", "description", "display");
private LocationEntity expectedLocationEntity2 = createDemoLocationEntity(20L, "uuid2", "name2", "description2", "display2");

@Before
public void initDb() {
Expand Down Expand Up @@ -78,6 +78,16 @@ public void findLocationByName_ShouldFindCorrectLocationByName() {
&& Objects.equals(actualLocationEntity.getDisplay(), "display"));
}

@Test
public void findLocationByUUID_ShouldFindCorrectLocationByUUID() {
mDatabase.locationRoomDAO().saveLocation(expectedLocationEntity1);
mDatabase.locationRoomDAO().findLocationByUUID(expectedLocationEntity1.getUuid())
.test()
.assertValue(actualLocationEntity -> Objects.equals(actualLocationEntity.getName(), "name")
&& Objects.equals(actualLocationEntity.getDescription(), "description")
&& Objects.equals(actualLocationEntity.getDisplay(), "display"));
}

@Test
public void deleteAllLocations_ShouldDeleteAllSavedLoactions() {
mDatabase.locationRoomDAO().saveLocation(expectedLocationEntity1);
Expand All @@ -90,11 +100,11 @@ public void deleteAllLocations_ShouldDeleteAllSavedLoactions() {
.assertValue(locationEntities -> Objects.equals(locationEntities.size(), 0));
}

private LocationEntity createDemoLocationEntity(Long id, String name, String description, String display) {
private LocationEntity createDemoLocationEntity(Long id, String uuid, String name, String description, String display) {
LocationEntity entity = new LocationEntity();
entity.setId(id);
entity.setDisplay(display);
entity.setUuid("uuid");
entity.setUuid(uuid);
entity.setName(name);
entity.setDescription(description);
entity.setAddress_1("address 1");
Expand Down
10 changes: 10 additions & 0 deletions openmrs-client/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.formentrypatientlist.FormEntryPatientListActivity" />
</activity>

<activity android:name=".activities.formadmission.FormAdmissionActivity"
android:label="@string/admission"
android:theme="@style/AppThemeOrig"
android:parentActivityName=".activities.formlist.FormListActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.openmrs.mobile.activities.formlist.FormListActivity"/>
</activity>

<activity
android:name=".activities.formentrypatientlist.FormEntryPatientListActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.openmrs.mobile.activities.syncedpatients.SyncedPatientsActivity
import org.openmrs.mobile.utilities.ApplicationConstants
import org.openmrs.mobile.utilities.ImageUtils
import org.openmrs.mobile.utilities.ThemeUtils
import org.openmrs.mobile.utilities.ToastUtil

class DashboardFragment : ACBaseFragment<DashboardContract.Presenter>(), DashboardContract.View, View.OnClickListener {

Expand Down Expand Up @@ -206,7 +207,7 @@ class DashboardFragment : ACBaseFragment<DashboardContract.Presenter>(), Dashboa
R.id.registryPatientView -> startNewActivity(AddEditPatientActivity::class.java)
R.id.captureVitalsView -> startNewActivity(FormEntryPatientListActivity::class.java)
R.id.activeVisitsView -> startNewActivity(ActiveVisitsActivity::class.java)
R.id.dashboardProviderManagementView -> startNewActivity(ProviderManagerDashboardActivity::class.java)
R.id.dashboardProviderManagementView -> ToastUtil.error(getString(R.string.failed_to_open_vitals_form));
Copy link
Collaborator Author

@rishabh-997 rishabh-997 Jun 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that users can't corrupt the database accidentally. Will be removed in the PR which will remove this error.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment it @rishabh-997 it will help

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we dont give any warning, user will keep pressing icon. And the encoded string here is An error occured, Invalid or Corrupt file which is very apt

else -> {
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/

package org.openmrs.mobile.activities.formadmission;

import android.os.Bundle;
import android.view.Menu;

import androidx.appcompat.app.ActionBar;

import org.openmrs.mobile.R;
import org.openmrs.mobile.activities.ACBaseActivity;
import org.openmrs.mobile.utilities.ApplicationConstants;

public class FormAdmissionActivity extends ACBaseActivity {

Long patientID;
String encounterType;
String formName;

public static FormAdmissionFragment newInstance() {
return new FormAdmissionFragment();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form_admission);
ActionBar actionBar = getSupportActionBar();

if (actionBar != null) {
actionBar.setElevation(0);
actionBar.setDisplayHomeAsUpEnabled(true);
}
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
patientID = bundle.getLong(ApplicationConstants.BundleKeys.PATIENT_ID_BUNDLE);
encounterType = (String) bundle.get(ApplicationConstants.BundleKeys.ENCOUNTERTYPE);
formName = (String) bundle.get(ApplicationConstants.BundleKeys.FORM_NAME);
}

FormAdmissionFragment formAdmissionFragment = (FormAdmissionFragment) getSupportFragmentManager().findFragmentById(R.id.admissionFormContentFrame);
if (formAdmissionFragment == null) {
formAdmissionFragment = FormAdmissionFragment.newInstance();
}
if (!formAdmissionFragment.isActive()) {
addFragmentToActivity(getSupportFragmentManager(),
formAdmissionFragment, R.id.admissionFormContentFrame);
}

new FormAdmissionPresenter(formAdmissionFragment, patientID, encounterType, formName, getApplicationContext());
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/

package org.openmrs.mobile.activities.formadmission;

import org.openmrs.mobile.activities.BasePresenterContract;
import org.openmrs.mobile.activities.BaseView;
import org.openmrs.mobile.models.Location;
import org.openmrs.mobile.models.Provider;
import org.openmrs.mobile.models.Resource;

import java.util.List;

public interface FormAdmissionContract {

interface View extends BaseView<Presenter> {

void updateProviderAdapter(List<Provider> providerList);

void showToast(String error);

void updateLocationAdapter(List<Location> locationList);

void enableSubmitButton(boolean value);

void quitFormEntry();

void updateEncounterRoleList(List<Resource> encounterRoleList);
}

interface Presenter extends BasePresenterContract {

void getProviders(FormAdmissionFragment formAdmissionFragment);

void updateViews(List<Provider> providerList);

void getLocation(String url);

void getEncounterRoles();

void createEncounter(String providerUUID, String locationUUID, String encounterRoleUUID);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/

package org.openmrs.mobile.activities.formadmission;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.openmrs.mobile.R;
import org.openmrs.mobile.activities.ACBaseFragment;
import org.openmrs.mobile.application.OpenMRS;
import org.openmrs.mobile.databinding.FragmentFormAdmissionBinding;
import org.openmrs.mobile.models.Location;
import org.openmrs.mobile.models.Provider;
import org.openmrs.mobile.models.Resource;
import org.openmrs.mobile.utilities.ToastUtil;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class FormAdmissionFragment extends ACBaseFragment<FormAdmissionContract.Presenter> implements FormAdmissionContract.View {

private FragmentFormAdmissionBinding formAdmissionBinding;

private String providerUUID = "";
private String locationUUID = "";
private String encounterRoleUUID = "";

public static FormAdmissionFragment newInstance() {
return new FormAdmissionFragment();
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

formAdmissionBinding = FragmentFormAdmissionBinding.inflate(inflater, container, false);
View root = formAdmissionBinding.getRoot();

initFragmentFields();
mPresenter.getEncounterRoles();
mPresenter.getProviders(this);
mPresenter.getLocation(OpenMRS.getInstance().getServerUrl());

return root;
}

private void initFragmentFields() {

Date currentDate = Calendar.getInstance().getTime();

@SuppressLint("SimpleDateFormat")
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
formAdmissionBinding.admissionDateHeader.setText(df.format(currentDate));
formAdmissionBinding.submitButton.setOnClickListener(v -> createEncounter());
}

private void createEncounter() {
if (providerUUID.isEmpty() || locationUUID.isEmpty() || encounterRoleUUID.isEmpty())
ToastUtil.showShortToast(getContext(), ToastUtil.ToastType.ERROR, getString(R.string.admission_fields_required));
else
mPresenter.createEncounter(providerUUID, locationUUID, encounterRoleUUID);
}

@Override
public void updateProviderAdapter(List<Provider> providerList) {
String[] providers = new String[providerList.size()];
for (int i = 0; i < providerList.size(); i++) {
providers[i] = providerList.get(i).getDisplay();
}

ArrayAdapter<String> adapterAdmittedBy = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, providers);
formAdmissionBinding.admittedBySpinner.setAdapter(adapterAdmittedBy);
formAdmissionBinding.admittedBySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String providerDisplay = formAdmissionBinding.admittedBySpinner.getSelectedItem().toString();

for (int i = 0; i < providerList.size(); i++) {
if (providerDisplay.equals(providerList.get(i).getDisplay())) {
providerUUID = providerList.get(i).getUuid();
}
}
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
}

@Override
public void updateLocationAdapter(List<Location> locationList) {
String[] locations = new String[locationList.size()];
for (int i = 0; i < locationList.size(); i++) {
locations[i] = locationList.get(i).getDisplay();
}
ArrayAdapter<String> adapterAdmittedTo = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, locations);
formAdmissionBinding.admittedToSpinner.setAdapter(adapterAdmittedTo);
formAdmissionBinding.admittedToSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String locationDisplay = formAdmissionBinding.admittedToSpinner.getSelectedItem().toString();

for (int i = 0; i < locationList.size(); i++) {
if (locationDisplay.equals(locationList.get(i).getDisplay())) {
locationUUID = locationList.get(i).getUuid();
}
}
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
}

@Override
public void updateEncounterRoleList(List<Resource> encounterRoleList) {
String[] encounterRole = new String[encounterRoleList.size()];
for (int i = 0; i < encounterRoleList.size(); i++) {
encounterRole[i] = encounterRoleList.get(i).getDisplay();
}
ArrayAdapter<String> adapterEncounterRole = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, encounterRole);
formAdmissionBinding.encounterRoleSpinner.setAdapter(adapterEncounterRole);
formAdmissionBinding.encounterRoleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String encounterRoleDisplay = formAdmissionBinding.encounterRoleSpinner.getSelectedItem().toString();

for (int i = 0; i < encounterRoleList.size(); i++) {
if (encounterRoleDisplay.equals(encounterRoleList.get(i).getDisplay())) {
encounterRoleUUID = encounterRoleList.get(i).getUuid();
}
}
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
}

@Override
public void showToast(String errorMessage) {
ToastUtil.error(errorMessage);
}

@Override
public void enableSubmitButton(boolean value) {
formAdmissionBinding.submitButton.setEnabled(value);
}

@Override
public void quitFormEntry() {
getActivity().finish();
}

}
Loading