Skip to content

Commit

Permalink
QA release
Browse files Browse the repository at this point in the history
  • Loading branch information
SebaMutuku committed Aug 7, 2022
1 parent d45693e commit db51cfe
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public static class BARCODE_CONSTANTS {
public static final int RC_HANDLE_GMS = 9001;
}

public static class OPTIBPCONSTANTS {
public static class OptibpConstants {
public static final String OPTIBP_WIDGET = "optibp";
public static final int OPTIBP_REQUEST_CODE = 301;
public static final int OPTIBP_REPEAT_REQUEST_CODE = 302;
Expand All @@ -337,7 +337,6 @@ public static class OPTIBPCONSTANTS {
public static final String MODEL = "model";
public static final String HEIGHT = "height";
public static final String WEIGHT = "weight";
public static final String COMPERATIVES = "comperatives";
public static final String CURRENTWEIGHT = "current_weight";

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected void registerWidgets() {
map.put(JsonFormConstants.EXTENDED_RADIO_BUTTON, new ExtendedRadioButtonWidgetFactory());
map.put(JsonFormConstants.EXPANSION_PANEL, new ExpansionPanelFactory());
map.put(JsonFormConstants.MULTI_SELECT_LIST, new MultiSelectListFactory());
map.put(JsonFormConstants.OPTIBPCONSTANTS.OPTIBP_WIDGET, new OptiBPWidgetFactory());
map.put(JsonFormConstants.OptibpConstants.OPTIBP_WIDGET, new OptiBPWidgetFactory());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ public static void updateEndProperties(PropertyManager propertyManager, JSONObje

public static JSONObject createOptiBPDataObject(String clientId, String clientOpenSRPId, String calibration) throws JSONException {
JSONObject jsonObject = new JSONObject();
jsonObject.put(JsonFormConstants.OPTIBPCONSTANTS.OPTIBP_KEY_CLIENT_ID, clientId);
jsonObject.put(JsonFormConstants.OPTIBPCONSTANTS.OPTIBP_KEY_CLIENT_OPENSRP_ID, clientOpenSRPId);
jsonObject.put(JsonFormConstants.OPTIBPCONSTANTS.CALIBRATION, calibration);
jsonObject.put(JsonFormConstants.OptibpConstants.OPTIBP_KEY_CLIENT_ID, clientId);
jsonObject.put(JsonFormConstants.OptibpConstants.OPTIBP_KEY_CLIENT_OPENSRP_ID, clientOpenSRPId);
jsonObject.put(JsonFormConstants.OptibpConstants.CALIBRATION, calibration);
return jsonObject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.rey.material.util.ViewUtil;
import com.rey.material.widget.Button;
import com.vijay.jsonwizard.R;
import com.vijay.jsonwizard.constants.JsonFormConstants.OPTIBPCONSTANTS;
import com.vijay.jsonwizard.constants.JsonFormConstants.OptibpConstants;
import com.vijay.jsonwizard.domain.WidgetArgs;
import com.vijay.jsonwizard.fragments.JsonFormFragment;
import com.vijay.jsonwizard.interfaces.CommonListener;
Expand Down Expand Up @@ -144,9 +144,8 @@ private Button initLaunchButton(LinearLayout rootLayout, final WidgetArgs widget
launchButton.setOnClickListener(view -> {
try {
Timber.w(" ONCLICK WITH JSON %s", jsonObject);
Intent intent = new Intent(OPTIBPCONSTANTS.OPTIBP_LAUNCH_INTENT);
Intent intent = new Intent(OptibpConstants.OPTIBP_LAUNCH_INTENT);
intent.setType("text/json");
Timber.e("OptiBP Calibration Request: %s ", getInputJsonString(context, jsonObject, widgetArgs));
intent.putExtra(Intent.EXTRA_TEXT, getInputJsonString(context, jsonObject, widgetArgs));
((Activity) context).startActivityForResult(Intent.createChooser(intent, ""), requestCode);
} catch (Exception e) {
Expand All @@ -166,16 +165,16 @@ private Button initLaunchButton(LinearLayout rootLayout, final WidgetArgs widget
}

private void formatButtonWidget(Button button, JSONObject jsonObject) throws JSONException {
if (jsonObject.has(OPTIBPCONSTANTS.OPTIBP_KEY_BUTTON_BG_COLOR)) {
String colorString = jsonObject.getString(OPTIBPCONSTANTS.OPTIBP_KEY_BUTTON_BG_COLOR);
if (jsonObject.has(OptibpConstants.OPTIBP_KEY_BUTTON_BG_COLOR)) {
String colorString = jsonObject.getString(OptibpConstants.OPTIBP_KEY_BUTTON_BG_COLOR);
setButtonBgColor(button, colorString);
}
if (jsonObject.has(OPTIBPCONSTANTS.OPTIBP_KEY_BUTTON_TEXT_COLOR)) {
String colorString = jsonObject.getString(OPTIBPCONSTANTS.OPTIBP_KEY_BUTTON_TEXT_COLOR);
if (jsonObject.has(OptibpConstants.OPTIBP_KEY_BUTTON_TEXT_COLOR)) {
String colorString = jsonObject.getString(OptibpConstants.OPTIBP_KEY_BUTTON_TEXT_COLOR);
button.setTextColor(Color.parseColor(colorString));
}
if (jsonObject.has(OPTIBPCONSTANTS.OPTIBP_KEY_BUTTON_TEXT)) {
String buttonText = jsonObject.getString(OPTIBPCONSTANTS.OPTIBP_KEY_BUTTON_TEXT);
if (jsonObject.has(OptibpConstants.OPTIBP_KEY_BUTTON_TEXT)) {
String buttonText = jsonObject.getString(OptibpConstants.OPTIBP_KEY_BUTTON_TEXT);
button.setText(buttonText);
}

Expand All @@ -187,14 +186,14 @@ public void setUpOptiBpActivityResultListener(final WidgetArgs widgetArgs, int r
final JsonApi jsonApi = (JsonApi) context;
jsonApi.addOnActivityResultListener(requestCode, (finalRequestCode, resultCode, data) -> {
if (resultCode == Activity.RESULT_OK) {
if (finalRequestCode == OPTIBPCONSTANTS.OPTIBP_REQUEST_CODE ||
finalRequestCode == OPTIBPCONSTANTS.OPTIBP_REPEAT_REQUEST_CODE) {
if (finalRequestCode == OptibpConstants.OPTIBP_REQUEST_CODE ||
finalRequestCode == OptibpConstants.OPTIBP_REPEAT_REQUEST_CODE) {
try {
if (data != null) {
String resultJson = data.getStringExtra(Intent.EXTRA_TEXT);
Timber.d("Resultant OptiBP JSON: %s ", resultJson);
populateBPEditTextValues(resultJson, systolicEditText, diastolicEditText, widgetArgs);
String resultString = getComparatives(resultJson);
String resultString = getValueString(resultJson);
if (StringUtils.isNotBlank(resultString)) {
writeResult(jsonApi, rootLayout, resultString, widgetArgs);
} else {
Expand Down Expand Up @@ -271,29 +270,27 @@ private void toggleEditTextEnabled(EditText editText, boolean enabled) {
protected String getBPValue(String resultJsonString, BPFieldType field) throws JSONException {
if (resultJsonString != null) {
JSONObject jsonObject = new JSONObject(resultJsonString);
JSONArray result = jsonObject.getJSONArray(OPTIBPCONSTANTS.OPTIBP_REPORT_RESULT);
JSONArray result = jsonObject.getJSONArray(OptibpConstants.OPTIBP_REPORT_RESULT);
JSONObject resultObject = result.getJSONObject(0);
JSONArray component = resultObject.getJSONArray(OPTIBPCONSTANTS.OPTIBP_REPORT_COMPONENT);
JSONArray component = resultObject.getJSONArray(OptibpConstants.OPTIBP_REPORT_COMPONENT);
JSONObject bpComponent = ((JSONObject) component.get(BPFieldType.SYSTOLIC_BP.equals(field) ? 1 : 0));
JSONObject valueQuantity = bpComponent.getJSONObject(OPTIBPCONSTANTS.OPTIBP_REPORT_VALUE_QUANTITY);
JSONObject valueQuantity = bpComponent.getJSONObject(OptibpConstants.OPTIBP_REPORT_VALUE_QUANTITY);
int value = valueQuantity.getInt(VALUE);
return String.valueOf(value);
}
return null;
}

protected String getComparatives(String resultJsonString) throws JSONException {
protected String getValueString(String resultJsonString) throws JSONException {
if (resultJsonString != null) {
JSONObject jsonObject = new JSONObject(resultJsonString);
JSONArray result = jsonObject.getJSONArray(OPTIBPCONSTANTS.OPTIBP_REPORT_RESULT);
JSONArray result = jsonObject.getJSONArray(OptibpConstants.OPTIBP_REPORT_RESULT);
JSONObject resultObject = result.getJSONObject(0);
JSONArray component = resultObject.getJSONArray(OPTIBPCONSTANTS.OPTIBP_REPORT_COMPONENT);
JSONArray component = resultObject.getJSONArray(OptibpConstants.OPTIBP_REPORT_COMPONENT);
JSONObject secondIndex = component.optJSONObject(2);
String valueString = secondIndex.optString(OPTIBPCONSTANTS.OPTIBP_VALUE_STRING);
JSONObject valueObject = new JSONObject(valueString);
JSONArray returnArray = valueObject.optJSONArray(OPTIBPCONSTANTS.COMPERATIVES);
Timber.d("Comparative Array from OPtibp: %s", returnArray.toString());
return returnArray.toString();
String valueString = secondIndex.optString(OptibpConstants.OPTIBP_VALUE_STRING);
Timber.d("Comparative Array from OPtibp: %s", valueString);
return valueString;
}
return null;

Expand All @@ -311,7 +308,7 @@ protected EditText getBPEditTextField(WidgetArgs widgetArgs, BPFieldType field)
}

private int getRequestCode(boolean isRepeat) {
return isRepeat ? OPTIBPCONSTANTS.OPTIBP_REPEAT_REQUEST_CODE : OPTIBPCONSTANTS.OPTIBP_REQUEST_CODE;
return isRepeat ? OptibpConstants.OPTIBP_REPEAT_REQUEST_CODE : OptibpConstants.OPTIBP_REQUEST_CODE;
}

@SuppressWarnings("SameParameterValue")
Expand All @@ -320,60 +317,46 @@ private boolean isRepeatMeasurement(BPFieldType systolicField, BPFieldType diast
}

protected String getInputJsonString(Context context, JSONObject jsonObject, WidgetArgs widgetArgs) throws JSONException {
if (!jsonObject.has(OPTIBPCONSTANTS.OPTIBP_KEY_DATA)) {
if (!jsonObject.has(OptibpConstants.OPTIBP_KEY_DATA)) {
throw new JSONException(context.getString(R.string.missing_client_info));
}
JSONObject optiBPData = jsonObject.getJSONObject(OPTIBPCONSTANTS.OPTIBP_KEY_DATA);
if (!optiBPData.has(OPTIBPCONSTANTS.OPTIBP_KEY_CLIENT_ID)
|| !optiBPData.has(OPTIBPCONSTANTS.OPTIBP_KEY_CLIENT_OPENSRP_ID)) {
JSONObject optiBPData = jsonObject.getJSONObject(OptibpConstants.OPTIBP_KEY_DATA);
if (!optiBPData.has(OptibpConstants.OPTIBP_KEY_CLIENT_ID)
|| !optiBPData.has(OptibpConstants.OPTIBP_KEY_CLIENT_OPENSRP_ID)) {
throw new JSONException(context.getString(R.string.missing_client_info));
}
if (!optiBPData.has(OPTIBPCONSTANTS.CALIBRATION)) {
throw new JSONException(context.getString(R.string.calibration_data));
}
if (TextUtils.isEmpty(optiBPData.getString(OPTIBPCONSTANTS.OPTIBP_KEY_CLIENT_ID))
|| TextUtils.isEmpty(optiBPData.getString(OPTIBPCONSTANTS.OPTIBP_KEY_CLIENT_OPENSRP_ID))) {
if (TextUtils.isEmpty(optiBPData.getString(OptibpConstants.OPTIBP_KEY_CLIENT_ID))
|| TextUtils.isEmpty(optiBPData.getString(OptibpConstants.OPTIBP_KEY_CLIENT_OPENSRP_ID))) {
throw new JSONException(context.getString(R.string.missing_client_info));
}

/***
* Removing the key and value to add add extra data
*/
optiBPData.remove(OPTIBPCONSTANTS.CALIBRATION);
/***
* Adding new calibration data here
*/
appendHealthData(optiBPData, widgetArgs);
optiBPData.put(OPTIBPCONSTANTS.CALIBRATION, getCalibrationData(optiBPData.optString(OPTIBPCONSTANTS.CALIBRATION)));
optiBPData.put(OptibpConstants.CALIBRATION, getCalibrationData(optiBPData.optString(OptibpConstants.CALIBRATION)));
return optiBPData.toString();
}

private JSONArray getCalibrationData(String calibration) {
try {
if (StringUtils.isBlank(calibration)) {
return null;
}
JSONArray calibrationArray = new JSONArray();
JSONObject calibrationJson = new JSONObject();
if (Utils.checkIfValidJsonArray(calibration)) {
calibrationJson.put(OPTIBPCONSTANTS.COMPERATIVES, new JSONArray(calibration));
} else {
calibrationJson.put(OPTIBPCONSTANTS.COMPERATIVES, new JSONArray());
return new JSONArray(calibration);
}
return calibrationArray.put(calibrationJson);
} catch (JSONException e) {
return StringUtils.isBlank(calibration) ? null : new JSONArray().put(new JSONObject(calibration));
} catch (Exception e) {
Timber.e(e);
return null;
}

}

private void appendHealthData(JSONObject returnObject, WidgetArgs widgetArgs) {
try {
JSONObject currentHeight = getSingleStepJsonObject(widgetArgs, STEP1, OPTIBPCONSTANTS.HEIGHT);
JSONObject currentWeight = getSingleStepJsonObject(widgetArgs, STEP1, OPTIBPCONSTANTS.CURRENTWEIGHT);
JSONObject currentHeight = getSingleStepJsonObject(widgetArgs, STEP1, OptibpConstants.HEIGHT);
JSONObject currentWeight = getSingleStepJsonObject(widgetArgs, STEP1, OptibpConstants.CURRENTWEIGHT);
if (currentHeight != null && currentWeight != null) {
returnObject.put(OPTIBPCONSTANTS.HEIGHT, Integer.parseInt(currentHeight.optString(VALUE)));
returnObject.put(OPTIBPCONSTANTS.WEIGHT, Integer.parseInt(currentWeight.optString(VALUE)));
returnObject.put(OptibpConstants.HEIGHT, Integer.parseInt(currentHeight.optString(VALUE)));
returnObject.put(OptibpConstants.WEIGHT, Integer.parseInt(currentWeight.optString(VALUE)));
}
} catch (JSONException e) {
Timber.e(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.rey.material.widget.Button;
import com.vijay.jsonwizard.R;
import com.vijay.jsonwizard.activities.JsonFormActivity;
import com.vijay.jsonwizard.constants.JsonFormConstants;
import com.vijay.jsonwizard.domain.WidgetArgs;
import com.vijay.jsonwizard.fragments.JsonFormFragment;
import com.vijay.jsonwizard.interfaces.CommonListener;
Expand All @@ -21,6 +22,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.robolectric.RuntimeEnvironment;
Expand Down Expand Up @@ -230,7 +232,7 @@ public class OptiBpWidgetFactoryTest extends FactoryTest {
" ]," +
" \"optibp_data\": {\n" +
" \"clientId\": \"sampleClientId\",\n" +
" \"clientOpenSRPId\": \"sampleClientOpenSRPId\"\n" +
" \"clientOpenSRPId\": \"sampleClientOpenSRPId\",\"calibration\":\"\"\n" +
" }\n" +
" },\n" +
" {\n" +
Expand Down Expand Up @@ -376,9 +378,7 @@ public void testInputJson() throws JSONException {
Mockito.doReturn(formFragment).when(widgetArgs).getFormFragment();
Mockito.doReturn(jsonApi).when(formFragment).getJsonApi();
Mockito.doReturn(new JSONObject(formString)).when(jsonApi).getmJSONObject();

String inputJson = factorySpy.getInputJsonString(RuntimeEnvironment.application.getApplicationContext(), new JSONObject(optiBPWidgetString), widgetArgs);

String inputJson = factorySpy.getInputJsonString(jsonFormActivity, new JSONObject(optiBPWidgetString), widgetArgs);
Assert.assertEquals(inputJson, "{\"clientId\":\"sampleClientId\",\"clientOpenSRPId\":\"sampleClientOpenSRPId\",\"calibration\":[{\"date\":\"2019-03-26T11:20:33+0800\",\"model\":\"device model\",\"height\":70,\"weight\":180,\"comperatives\":[{\"systolic\":120,\"diastolic\":80,\"cuffSystolic\":120,\"cuffDiastolic\":80,\"features\":{\"$key\":\"0.2f\"}}]}]}");
}

Expand All @@ -402,6 +402,8 @@ public void testPopulateETValues() throws JSONException {
Assert.assertNotNull(factorySpy);
EditText sbp = Mockito.mock(EditText.class);
EditText dbp = Mockito.mock(EditText.class);
widgetArgs=Mockito.mock(WidgetArgs.class);
Mockito.doReturn(new JSONObject(formString)).when(widgetArgs).getFormFragment().getJsonApi().getStep(ArgumentMatchers.anyString()).optString(JsonFormConstants.FIELDS);
factorySpy.populateBPEditTextValues(resultJson, sbp, dbp,widgetArgs);
Mockito.verify(sbp).setEnabled(false);
Mockito.verify(dbp).setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ public void startForm(int jsonFormActivityRequestCode, String formName, String e
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
if (jsonObject.getString(KEY).equalsIgnoreCase("optipb_widget1")) {
if (jsonObject.has(JsonFormConstants.OPTIBPCONSTANTS.OPTIBP_KEY_DATA)) {
jsonObject.remove(JsonFormConstants.OPTIBPCONSTANTS.OPTIBP_KEY_DATA);
if (jsonObject.has(JsonFormConstants.OptibpConstants.OPTIBP_KEY_DATA)) {
jsonObject.remove(JsonFormConstants.OptibpConstants.OPTIBP_KEY_DATA);
}
JSONObject optiBPData = FormUtils.createOptiBPDataObject("46ccd2e0-bbec-4e4a-8f73-972a2f1f95ea",
"1272326657","");
jsonObject.put(JsonFormConstants.OPTIBPCONSTANTS.OPTIBP_KEY_DATA, optiBPData);
jsonObject.put(JsonFormConstants.OptibpConstants.OPTIBP_KEY_DATA, optiBPData);
break;
}
}
Expand Down

0 comments on commit db51cfe

Please sign in to comment.