Skip to content

Commit

Permalink
Codacy fixes (#56)
Browse files Browse the repository at this point in the history
* Fixed codacy issues 1

* Fixed codacy issues 2

* Empty test commit

* Trigger CI

* Trigger CI

* Fixed codacy issues 3

* Fixed codacy issues 4

* Fixed codacy issues 5

* Fixed refactor issue

* Trigger CI
  • Loading branch information
hamza-vd authored Feb 16, 2021
1 parent 54b4e7e commit 3f4959c
Show file tree
Hide file tree
Showing 53 changed files with 837 additions and 702 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).


and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,4 @@ Email: <mailto:[email protected]>
Slack workspace: <opensrp.slack.com>

## License
This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details

This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.smartregister.child.presenter.BaseChildDetailsPresenter.CardStatus;
import org.smartregister.child.task.LoadAsyncTask;
import org.smartregister.child.util.ChildDbUtils;
import org.smartregister.child.util.ChildJsonFormUtils;
import org.smartregister.child.util.Constants;
import org.smartregister.client.utils.domain.Form;
import org.smartregister.pathzeir.R;
Expand Down Expand Up @@ -153,6 +152,7 @@ protected void navigateToRegisterActivity() {

@Override
public void startFormActivity(String formData) {
String formDataString = formData;
if(StringUtils.isNotBlank(formData)) {
try {
Intent intent;
Expand All @@ -170,7 +170,7 @@ public void startFormActivity(String formData) {
form.setActionBarBackground(R.color.actionbar);
form.setNavigationBackground(R.color.primary_dark);
intent = new Intent(this, JsonWizardFormActivity.class);
formData = obtainUpdatedForm(formJson);
formDataString = obtainUpdatedForm(formJson);
} else {
form.setWizard(false);
form.setHideSaveLabel(true);
Expand All @@ -179,7 +179,7 @@ public void startFormActivity(String formData) {
}

intent.putExtra(JsonFormConstants.JSON_FORM_KEY.FORM, form);
intent.putExtra(JsonFormConstants.JSON_FORM_KEY.JSON, formData);
intent.putExtra(JsonFormConstants.JSON_FORM_KEY.JSON, formDataString);
intent.putExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION, true);
startActivityForResult(intent, REQUEST_CODE_GET_JSON);
} catch (JSONException e) {
Expand All @@ -193,10 +193,10 @@ private String obtainUpdatedForm(JSONObject formJson) throws JSONException {
for (int i = 0; i < fields.length(); i++) {
JSONObject field = fields.getJSONObject(i);
if (field != null && field.getString(JsonFormConstants.TYPE).equalsIgnoreCase(JsonFormConstants.DATE_PICKER)
&& !childDetails.getDetails().isEmpty() && childDetails.getDetails().containsKey(AppConstants.KEY.DOB)) {
Date date = Utils.dobStringToDate(childDetails.getDetails().get(AppConstants.KEY.DOB));
&& !childDetails.getDetails().isEmpty() && childDetails.getDetails().containsKey(AppConstants.KeyConstants.DOB)) {
Date date = Utils.dobStringToDate(childDetails.getDetails().get(AppConstants.KeyConstants.DOB));
field.put(JsonFormConstants.MIN_DATE, new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(date));
field.put(JsonFormConstants.MAX_DATE, AppConstants.KEY.TODAY);
field.put(JsonFormConstants.MAX_DATE, AppConstants.KeyConstants.TODAY);
}
}
return formJson.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
import java.util.Map;

import static org.smartregister.pathzeir.fragment.AppChildFormFragment.getFormFragment;
import static org.smartregister.pathzeir.util.AppConstants.KEY.FIRST_NAME;
import static org.smartregister.pathzeir.util.AppConstants.KEY.LAST_NAME;
import static org.smartregister.pathzeir.util.AppConstants.KEY.MOTHER_GUARDIAN_NRC;
import static org.smartregister.pathzeir.util.AppConstants.KEY.MOTHER_GUARDIAN_NUMBER;
import static org.smartregister.pathzeir.util.AppConstants.KEY.MOTHER_NRC_NUMBER;
import static org.smartregister.pathzeir.util.AppConstants.KeyConstants.FIRST_NAME;
import static org.smartregister.pathzeir.util.AppConstants.KeyConstants.LAST_NAME;
import static org.smartregister.pathzeir.util.AppConstants.KeyConstants.MOTHER_GUARDIAN_NRC;
import static org.smartregister.pathzeir.util.AppConstants.KeyConstants.MOTHER_GUARDIAN_NUMBER;
import static org.smartregister.pathzeir.util.TableUtil.getMotherDetailsColumn;

public class ChildFormActivity extends BaseChildFormActivity {
Expand Down Expand Up @@ -58,10 +57,10 @@ protected static String getMainConditionString(Map<String, String> entityMap) {
if (!isDate(value)) {
continue;
}
key = AppConstants.KEY.DOB;
key = AppConstants.KeyConstants.DOB;
}

if (!key.equals(AppConstants.KEY.DOB)) {
if (!key.equals(AppConstants.KeyConstants.DOB)) {
if (StringUtils.isBlank(mainConditionString)) {
mainConditionString += " " + key + " Like '%" + value + "%'";
} else {
Expand All @@ -83,7 +82,7 @@ protected static String getMainConditionString(Map<String, String> entityMap) {
public String lookUpQuery(Map<String, String> entityMap, String tableName) {
RegisterQueryProvider queryProvider = Utils.metadata().getRegisterQueryProvider();

String[] lookupColumns = new String[]{queryProvider.getDemographicTable() + "." + MotherLookUpUtils.RELATIONALID, queryProvider.getDemographicTable() + "." + MotherLookUpUtils.DETAILS, Constants.KEY.ZEIR_ID, Constants.KEY.FIRST_NAME, Constants.KEY.LAST_NAME,
String[] lookupColumns = new String[]{queryProvider.getDemographicTable() + "." + MotherLookUpUtils.RELATIONALID, queryProvider.getDemographicTable() + "." + MotherLookUpUtils.DETAILS, Constants.KEY.ZEIR_ID, FIRST_NAME, LAST_NAME,
queryProvider.getDemographicTable() + "." + AllConstants.ChildRegistrationFields.GENDER,
queryProvider.getDemographicTable() + "." + Constants.KEY.DOB,
queryProvider.getDemographicTable() + "." + Constants.KEY.BASE_ENTITY_ID,
Expand All @@ -93,7 +92,7 @@ public String lookUpQuery(Map<String, String> entityMap, String tableName) {
SmartRegisterQueryBuilder queryBuilder = new SmartRegisterQueryBuilder();
queryBuilder.selectInitiateMainTable(tableName, lookupColumns);
queryBuilder.customJoin(
" join " + queryProvider.getMotherDetailsTable() + " on " + queryProvider.getMotherDetailsTable() + "." + AppConstants.KEY.BASE_ENTITY_ID + "=" + queryProvider.getDemographicTable() + "." + Constants.KEY.BASE_ENTITY_ID +
" join " + queryProvider.getMotherDetailsTable() + " on " + queryProvider.getMotherDetailsTable() + "." + AppConstants.KeyConstants.BASE_ENTITY_ID + "=" + queryProvider.getDemographicTable() + "." + Constants.KEY.BASE_ENTITY_ID +
" join " + queryProvider.getChildDetailsTable() + " on " + queryProvider.getChildDetailsTable() + "." + Constants.KEY.RELATIONAL_ID + " = " + queryProvider.getMotherDetailsTable() + "." + Constants.KEY.BASE_ENTITY_ID);
String query = queryBuilder.mainCondition(getMainConditionString(entityMap));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void startFormActivity(JSONObject jsonForm) {

@Override
protected void updateSearchItems(String barcodeSearchTerm) {
advancedSearchFormData.put(AppConstants.KEY.ZEIR_ID, barcodeSearchTerm);
advancedSearchFormData.put(AppConstants.KeyConstants.ZEIR_ID, barcodeSearchTerm);
Fragment fragment = fragments[ADVANCED_SEARCH_POSITION - 1];
if (fragment instanceof AdvancedSearchFragment) {
AdvancedSearchFragment advancedSearchFragment = (AdvancedSearchFragment) fragment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public class ZeirApplication extends DrishtiApplication implements TimeChangedBr
private ECSyncHelper ecSyncHelper;
private ClientRegisterTypeRepository registerTypeRepository;
private ChildAlertUpdatedRepository childAlertUpdatedRepository;
private RecurringServiceTypeRepository recurringServiceRepository;
private CohortRepository cohortRepository;
private CohortPatientRepository cohortPatientRepository;
private CohortIndicatorRepository cohortIndicatorRepository;
Expand Down Expand Up @@ -135,23 +134,23 @@ private static String[] getFtsSearchFields(String tableName) {
case DBConstants.RegisterTable.CHILD_DETAILS:
return new String[]{DBConstants.KEY.LOST_TO_FOLLOW_UP, DBConstants.KEY.INACTIVE};
case DBConstants.RegisterTable.MOTHER_DETAILS:
return new String[]{AppConstants.KEY.MOTHER_GUARDIAN_NUMBER,};
return new String[]{AppConstants.KeyConstants.MOTHER_GUARDIAN_NUMBER,};
default:
return null;
}
}

private static String[] getFtsSortFields(String tableName, android.content.Context context) {
switch (tableName) {
case AppConstants.TABLE_NAME.ALL_CLIENTS:
return Arrays.asList(AppConstants.KEY.FIRST_NAME, AppConstants.KEY.LAST_NAME,
AppConstants.KEY.DOB, AppConstants.KEY.ZEIR_ID, AppConstants.KEY.LAST_INTERACTED_WITH,
AppConstants.KEY.DOD, AppConstants.KEY.DATE_REMOVED).toArray(new String[0]);
case AppConstants.TableNameConstants.ALL_CLIENTS:
return Arrays.asList(AppConstants.KeyConstants.FIRST_NAME, AppConstants.KeyConstants.LAST_NAME,
AppConstants.KeyConstants.DOB, AppConstants.KeyConstants.ZEIR_ID, AppConstants.KeyConstants.LAST_INTERACTED_WITH,
AppConstants.KeyConstants.DOD, AppConstants.KeyConstants.DATE_REMOVED).toArray(new String[0]);
case DBConstants.RegisterTable.CHILD_DETAILS:
List<VaccineGroup> vaccineList = VaccinatorUtils.getVaccineGroupsFromVaccineConfigFile(context, VaccinatorUtils.vaccines_file);
List<String> names = new ArrayList<>();
names.add(DBConstants.KEY.INACTIVE);
names.add(AppConstants.KEY.RELATIONAL_ID);
names.add(AppConstants.KeyConstants.RELATIONAL_ID);
names.add(DBConstants.KEY.LOST_TO_FOLLOW_UP);

for (VaccineGroup vaccineGroup : vaccineList) {
Expand Down Expand Up @@ -281,10 +280,10 @@ public void onCreate() {
private ChildMetadata getMetadata() {
ChildMetadata metadata = new ChildMetadata(ChildFormActivity.class, ChildProfileActivity.class,
ChildImmunizationActivity.class, ChildRegisterActivity.class, true, new AppChildRegisterQueryProvider());
metadata.updateChildRegister(AppConstants.JsonForm.CHILD_ENROLLMENT, AppConstants.TABLE_NAME.ALL_CLIENTS,
AppConstants.TABLE_NAME.ALL_CLIENTS, AppConstants.EventType.CHILD_REGISTRATION,
AppConstants.EventType.UPDATE_CHILD_REGISTRATION, AppConstants.EventType.OUT_OF_CATCHMENT, AppConstants.CONFIGURATION.CHILD_REGISTER,
AppConstants.RELATIONSHIP.MOTHER, AppConstants.JsonForm.OUT_OF_CATCHMENT_SERVICE);
metadata.updateChildRegister(AppConstants.JsonForm.CHILD_ENROLLMENT, AppConstants.TableNameConstants.ALL_CLIENTS,
AppConstants.TableNameConstants.ALL_CLIENTS, AppConstants.EventTypeConstants.CHILD_REGISTRATION,
AppConstants.EventTypeConstants.UPDATE_CHILD_REGISTRATION, AppConstants.EventTypeConstants.OUT_OF_CATCHMENT, AppConstants.ConfigurationConstants.CHILD_REGISTER,
AppConstants.RelationshipConstants.MOTHER, AppConstants.JsonForm.OUT_OF_CATCHMENT_SERVICE);
metadata.setFieldsWithLocationHierarchy(new HashSet<>(Arrays.asList("home_facility", "birth_facility_name")));
metadata.setLocationLevels(AppUtils.getLocationLevels());
metadata.setHealthFacilityLevels(AppUtils.getHealthFacilityLevels());
Expand All @@ -303,7 +302,7 @@ private void initOfflineSchedules() {
try {
List<VaccineGroup> childVaccines = VaccinatorUtils.getSupportedVaccines(this);
List<Vaccine> specialVaccines = VaccinatorUtils.getSpecialVaccines(this);
VaccineSchedule.init(childVaccines, specialVaccines, AppConstants.KEY.CHILD);
VaccineSchedule.init(childVaccines, specialVaccines, AppConstants.KeyConstants.CHILD);
} catch (Exception e) {
Timber.e(e, "ZeirApplication --> initOfflineSchedules");
}
Expand Down Expand Up @@ -423,10 +422,10 @@ public ECSyncHelper getEcSyncHelper() {

@VisibleForTesting
protected void fixHardcodedVaccineConfiguration() {
VaccineRepo.Vaccine[] vaccines = ImmunizationLibrary.getInstance().getVaccines(AppConstants.KEY.CHILD);
VaccineRepo.Vaccine[] vaccines = ImmunizationLibrary.getInstance().getVaccines(AppConstants.KeyConstants.CHILD);

HashMap<String, VaccineDuplicate> replacementVaccines = new HashMap<>();
replacementVaccines.put("BCG 2", new VaccineDuplicate("BCG 2", VaccineRepo.Vaccine.bcg, 1825, 0, 15, AppConstants.KEY.CHILD));
replacementVaccines.put("BCG 2", new VaccineDuplicate("BCG 2", VaccineRepo.Vaccine.bcg, 1825, 0, 15, AppConstants.KeyConstants.CHILD));

for (VaccineRepo.Vaccine vaccine : vaccines) {
if (replacementVaccines.containsKey(vaccine.display())) {
Expand All @@ -439,7 +438,7 @@ protected void fixHardcodedVaccineConfiguration() {
}
}

ImmunizationLibrary.getInstance().setVaccines(vaccines, AppConstants.KEY.CHILD);
ImmunizationLibrary.getInstance().setVaccines(vaccines, AppConstants.KeyConstants.CHILD);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public RemoteLocalCursor(Cursor cursor) {
try {
id = cursor.getString(cursor.getColumnIndex(DBConstants.KEY.ID_LOWER_CASE));
relationalId = cursor.getString(cursor.getColumnIndex(DBConstants.KEY.RELATIONALID));
motherBaseEntityId = cursor.getString(cursor.getColumnIndex(AppConstants.KEY.RELATIONAL_ID));
motherBaseEntityId = cursor.getString(cursor.getColumnIndex(AppConstants.KeyConstants.RELATIONAL_ID));
firstName = cursor.getString(cursor.getColumnIndex(DBConstants.KEY.FIRST_NAME));
lastName = cursor.getString(cursor.getColumnIndex(DBConstants.KEY.LAST_NAME));
dob = cursor.getString(cursor.getColumnIndex(DBConstants.KEY.DOB));
Expand Down
Loading

0 comments on commit 3f4959c

Please sign in to comment.