Skip to content

Commit

Permalink
Merge branch 'merge/general-app-updates' of https://github.com/opensr…
Browse files Browse the repository at this point in the history
…p/opensrp-client-anc into merge/general-app-updates
  • Loading branch information
junaidwarsivd committed Apr 19, 2022
2 parents de7bac4 + ec47a0b commit ee41246
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 44 deletions.
2 changes: 1 addition & 1 deletion opensrp-anc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ tasks.withType(Test) {

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation('org.smartregister:opensrp-client-native-form:2.1.16-SNAPSHOT@aar') {
implementation('org.smartregister:opensrp-client-native-form:2.1.17-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'recyclerview-v7'
exclude group: 'com.android.support', module: 'appcompat-v7'
Expand Down
8 changes: 4 additions & 4 deletions opensrp-anc/src/main/assets/config/profile-overview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ fields:
relevance: "severe_preeclampsia == 1"
isRedFont: "true"

- template: "Rh factor negative: {date}: {date}"
- template: "Rh factor negative: {rh_factor}"
relevance: "rh_factor == 'negative'"
isRedFont: "true"

- template: "HIV positive: {date}"
- template: "HIV Status: {hiv_test_result}"
relevance: "hiv_positive == 1"
isRedFont: "true"

Expand Down Expand Up @@ -321,7 +321,7 @@ fields:
---
group: immunisation_status
fields:
- template: "{{profile_overview.immunisation_status.tt_immunisation_status}}: {tt_immun_status_value}"
- template: "{{profile_overview.immunisation_status.tt_immunisation_status}}: {tt_immun_status}"
relevance: "tt_immun_status != ''"
isRedFont: "tt_immun_status == 'ttcv_not_received' || tt_immun_status == 'unknown'"

Expand All @@ -331,7 +331,7 @@ fields:
- template: "{{profile_overview.immunisation_status.tt_dose_2}}: {tt2_date_value}"
relevance: "tt2_date == 'done_today' || tt2_date == 'done_earlier'"

- template: "{{profile_overview.immunisation_status.flu_immunisation_status}}: {flu_immun_status_value}"
- template: "{{profile_overview.immunisation_status.flu_immunisation_status}}: {flu_immun_status}"
relevance: "flu_immun_status != ''"
isRedFont: "flu_immun_status == 'seasonal_flu_dose_missing' || flu_immun_status == 'unknown'"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void init(String json) {
}.getType());
if (globalValues.containsKey(ConstantsUtils.DANGER_SIGNS + ConstantsUtils.SuffixUtils.VALUE) && StringUtils.isNotBlank(globalValues.get(ConstantsUtils.DANGER_SIGNS + ConstantsUtils.SuffixUtils.VALUE))) {
String danger_signs_value = globalValues.get(ConstantsUtils.DANGER_SIGNS + ConstantsUtils.SuffixUtils.VALUE);
if (danger_signs_value.contains(",") && danger_signs_value.contains(".")) {
if (danger_signs_value.contains(",") || (danger_signs_value.contains(".") && danger_signs_value.contains(JsonFormConstants.TEXT))) {
List<String> list = Arrays.asList(danger_signs_value.split(",")), finalList = new LinkedList<>();
for (int i = 0; i < list.size(); i++) {
String text = list.get(i).trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
/**
* Created by ndegwamartin on 10/07/2018.
*/


public class ContactSummaryFinishActivity extends BaseProfileActivity implements ProfileContract.View {
public MenuItem saveFinishMenuItem;
private TextView nameView;
Expand Down Expand Up @@ -190,6 +192,7 @@ private void saveFinishForm() {
new FinalizeContactTask(new WeakReference<Context>(this), mProfilePresenter, getIntent()).execute();
}


@Override
public boolean onPrepareOptionsMenu(Menu menu) {
saveFinishMenuItem = menu.findItem(R.id.save_finish_menu_item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void loadPreviousContactsDetails(Map<String, List<Facts>> allContactFacts
while (keys.hasNext()) {
String key = keys.next();
String valueObject = jsonObject.optString(key), value;
value = Utils.returnTranslatedStringJoinedValue(valueObject, key);
value = Utils.returnTranslatedStringJoinedValue(valueObject);
if (StringUtils.isNotBlank(value)) {
factsToUpdate.put(key, value);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/
public class ProfileFragmentInteractor implements ProfileFragmentContract.Interactor {
private ProfileFragmentContract.Presenter mProfileFrgamentPresenter;
private ANCFormUtils ANCFormUtils = new ANCFormUtils();
private Utils utils = new Utils();
private final ANCFormUtils ANCFormUtils = new ANCFormUtils();
private final Utils utils = new Utils();

public ProfileFragmentInteractor(ProfileFragmentContract.Presenter presenter) {
this.mProfileFrgamentPresenter = presenter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Facts getImmediatePreviousContact(Map<String, String> clientDetails, Stri
while (keys.hasNext()) {
String key = keys.next();
String valueObject = jsonObject.optString(key), value;
value = Utils.returnTranslatedStringJoinedValue(valueObject, key);
value = Utils.returnTranslatedStringJoinedValue(valueObject);
if (StringUtils.isNotBlank(value)) {
facts.put(key, value);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ public List<PreviousContactsSummaryModel> getPreviousContactsFacts(String baseEn
previousContactsSummary.setContactNumber(factsCursor.getString(factsCursor.getColumnIndex(CONTACT_NO)));
previousContactsSummary.setCreatedAt(factsCursor.getString(factsCursor.getColumnIndex(CREATED_AT)));
previousContactsSummary.setVisitFacts(contactFacts);

previousContactFacts.add(previousContactsSummary);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected Void doInBackground(Void... voids) {
while (keys.hasNext()) {
String key = keys.next();
String ValueObject = jsonObject.optString(key);
String value = Utils.returnTranslatedStringJoinedValue(ValueObject, key);
String value = Utils.returnTranslatedStringJoinedValue(ValueObject);
if (StringUtils.isNotBlank(value)) {
facts.put(key, value);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.IBlockElement;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.TextAlignment;
Expand Down Expand Up @@ -76,7 +75,6 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -359,7 +357,6 @@ private static String processValue(String key, Facts facts) {
}
return ANCFormUtils.keyToValueConverter("");
}

if (value != null && value.endsWith(OTHER_SUFFIX)) {
Object otherValue = value.endsWith(OTHER_SUFFIX) ? facts.get(key + ConstantsUtils.SuffixUtils.OTHER) : "";
value = otherValue != null ?
Expand All @@ -384,19 +381,20 @@ private static String cleanValueResult(String result) {
if (!nonEmptyItems.isEmpty() && nonEmptyItems.get(0).contains(":")) {
String[] separatedLabel = nonEmptyItems.get(0).split(":");
itemLabel = separatedLabel[0];
if (separatedLabel.length > 1 ) {
if (separatedLabel.length > 1) {
nonEmptyItems.set(0, nonEmptyItems.get(0).split(":")[1]);
if (StringUtils.isBlank(nonEmptyItems.get(0)))
nonEmptyItems.remove(0);
}//replace with extracted value
}
if(!itemLabel.equals(StringUtils.join(nonEmptyItems.toArray(),",").replace(":","")))
return itemLabel + (!TextUtils.isEmpty(itemLabel) ? ": " : "") + StringUtils.join(nonEmptyItems.toArray(), ",");
if (!itemLabel.equals(StringUtils.join(nonEmptyItems.toArray(), ",").replace(":", "")))
return itemLabel + (!TextUtils.isEmpty(itemLabel) ? ": " : "") + StringUtils.join(nonEmptyItems.toArray(), ",");
else
return itemLabel+":";
return itemLabel + ":";
}

public static void navigateToHomeRegister(Context context, boolean isRemote, Class<? extends BaseHomeRegisterActivity> homeRegisterActivityClass) {
public static void navigateToHomeRegister(Context context, boolean isRemote, Class<? extends
BaseHomeRegisterActivity> homeRegisterActivityClass) {
Intent intent = new Intent(context, homeRegisterActivityClass);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(ConstantsUtils.IntentKeyUtils.IS_REMOTE_LOGIN, isRemote);
Expand All @@ -418,7 +416,8 @@ public static String getDBDateToday() {
return (new LocalDate()).toString(SQLITE_DATE_DF);
}

public static ButtonAlertStatus getButtonAlertStatus(Map<String, String> details, Context context, boolean isProfile) {
public static ButtonAlertStatus getButtonAlertStatus
(Map<String, String> details, Context context, boolean isProfile) {
String contactStatus = details.get(DBConstantsUtils.KeyUtils.CONTACT_STATUS);

String nextContactDate = details.get(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE);
Expand Down Expand Up @@ -486,7 +485,8 @@ public static String reverseHyphenSeperatedValues(String rawString, String outpu
return "";
}

private static String getDisplayTemplate(Context context, String alertStatus, boolean isProfile) {
private static String getDisplayTemplate(Context context, String alertStatus,
boolean isProfile) {
String displayTemplate;
if (StringUtils.isNotBlank(alertStatus) && !isProfile) {
switch (alertStatus) {
Expand Down Expand Up @@ -530,11 +530,13 @@ public static String processContactDoneToday(String lastContactDate, String aler
return result;
}

public static void processButtonAlertStatus(Context context, Button dueButton, ButtonAlertStatus buttonAlertStatus) {
public static void processButtonAlertStatus(Context context, Button
dueButton, ButtonAlertStatus buttonAlertStatus) {
Utils.processButtonAlertStatus(context, dueButton, null, buttonAlertStatus);
}

public static void processButtonAlertStatus(Context context, Button dueButton, TextView contactTextView,
public static void processButtonAlertStatus(Context context, Button dueButton, TextView
contactTextView,
ButtonAlertStatus buttonAlertStatus) {
if (dueButton != null) {
dueButton.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -645,7 +647,8 @@ public static String readFromSharedPreference(String sharedPref, String key) {
* @param tableName
* @return
*/
public static boolean isTableExists(@NonNull SQLiteDatabase sqliteDatabase, @NonNull String tableName) {
public static boolean isTableExists(@NonNull SQLiteDatabase sqliteDatabase, @NonNull String
tableName) {
Cursor cursor = sqliteDatabase.rawQuery(
"SELECT name FROM sqlite_master WHERE type='table' AND name='" + tableName + "'",
null
Expand Down Expand Up @@ -835,7 +838,8 @@ public static Event createContactVisitEvent(@NonNull List<String> formSubmission
* @param baseEntityId {@link String}
* @throws JSONException
*/
public static void createPreviousVisitFromGroup(@NonNull String strGroup, @NonNull String baseEntityId) throws JSONException {
public static void createPreviousVisitFromGroup(@NonNull String strGroup, @NonNull String
baseEntityId) throws JSONException {
JSONObject jsonObject = new JSONObject(strGroup);
Iterator<String> repeatingGroupKeys = jsonObject.keys();
List<String> currentFormSubmissionIds = new ArrayList<>();
Expand Down Expand Up @@ -881,7 +885,6 @@ public static void createPreviousVisitFromGroup(@NonNull String strGroup, @NonNu
}
}


public static Event addContactVisitDetails(String attentionFlagsString, Event event,
String referral, String currentContactState) {
event.addDetails(ConstantsUtils.DetailsKeyUtils.ATTENTION_FLAG_FACTS, attentionFlagsString);
Expand Down Expand Up @@ -924,13 +927,12 @@ public static boolean checkJsonArrayString(String input) {
/**
* @param receives iterated keys and values and passes them through translation in nativeform
* to return a string. It checks whether the value is an array, a json object or a normal string separated by ,
* @param key
* @return
*/
@SuppressLint({"NewApi"})
public static String returnTranslatedStringJoinedValue(String value, String key) {
public static String returnTranslatedStringJoinedValue(String value) {
try {
if (value.startsWith("[")) {
if (StringUtils.isNotBlank(value) && value.charAt(0) == '[') {
if (Utils.checkJsonArrayString(value)) {
JSONArray jsonArray = new JSONArray(value);
List<String> translatedList = new ArrayList<>();
Expand All @@ -941,27 +943,30 @@ public static String returnTranslatedStringJoinedValue(String value, String key)
translatedText = StringUtils.isNotBlank(text) ? NativeFormLangUtils.translateDatabaseString(text, AncLibrary.getInstance().getApplicationContext()) : "";
translatedList.add(translatedText);
}
return translatedList.size() > 1 ? String.join(",", translatedList) : translatedList.get(0);
return translatedList.size() > 1 ? String.join(",", translatedList) : translatedList.size() == 1 ? translatedList.get(0) : "";
} else {
return value;
return value.substring(1, value.length() - 1);
}
}
if (value.startsWith("{")) {
if (StringUtils.isNotBlank(value) && value.charAt(0) == '{') {
JSONObject attentionFlagObject = new JSONObject(value);
String translated_text, text;
text = attentionFlagObject.optString(JsonFormConstants.TEXT).trim();
translated_text = StringUtils.isNotBlank(text) ? NativeFormLangUtils.translateDatabaseString(text, AncLibrary.getInstance().getApplicationContext()) : "";
return translated_text;
}
if (key.endsWith(ConstantsUtils.KeyUtils.VALUE) && value.contains(",") && value.contains(JsonFormConstants.TEXT)) {
if (StringUtils.isNotBlank(value) && value.contains(",") && value.contains(".") && value.contains(JsonFormConstants.TEXT)) {
List<String> attentionFlagValueArray = Arrays.asList(value.trim().split(","));
List<String> translatedList = new ArrayList<>();
for (int i = 0; i < attentionFlagValueArray.size(); i++) {
String textToTranslate = attentionFlagValueArray.get(i).trim(), translatedText;
translatedText = StringUtils.isNotBlank(textToTranslate) ? NativeFormLangUtils.translateDatabaseString(textToTranslate, AncLibrary.getInstance().getApplicationContext()) : "";
translatedList.add(translatedText);
}
return translatedList.size() > 1 ? String.join(",", translatedList) : translatedList.get(0);
return translatedList.size() > 1 ? String.join(",", translatedList) : translatedList.size() == 1 ? translatedList.get(0) : "";
}
if (StringUtils.isNotBlank(value) && value.contains(".") && !value.contains(",") && value.charAt(0) != '[' && !value.contains("{") && value.contains(JsonFormConstants.TEXT)) {
return NativeFormLangUtils.translateDatabaseString(value.trim(), AncLibrary.getInstance().getApplicationContext());
}
return value;

Expand All @@ -973,6 +978,9 @@ public static String returnTranslatedStringJoinedValue(String value, String key)

}




@Nullable
public String getManifestVersion(Context context) {
if (StringUtils.isNotBlank(CoreLibrary.getInstance().context().allSharedPreferences().fetchManifestVersion())) {
Expand All @@ -991,7 +999,7 @@ public void createSavePdf(Context context, List<YamlConfig> yamlConfigList, Fact
(new File(filePath)).delete();
}
FileOutputStream fOut = new FileOutputStream(filePath);
PdfWriter pdfWriter = new PdfWriter((OutputStream) fOut);
PdfWriter pdfWriter = new PdfWriter(fOut);
PdfDocument pdfDocument = new PdfDocument(pdfWriter);
Document layoutDocument = new Document(pdfDocument);

Expand Down Expand Up @@ -1020,7 +1028,7 @@ public void createSavePdf(Context context, List<YamlConfig> yamlConfigList, Fact


layoutDocument.close();
Toast.makeText(context, (CharSequence) (context.getResources().getString(R.string.pdf_saved_successfully) + filePath), Toast.LENGTH_SHORT).show();
Toast.makeText(context, context.getResources().getString(R.string.pdf_saved_successfully) + filePath, Toast.LENGTH_SHORT).show();
}

private String processUnderscores(String string) {
Expand All @@ -1041,7 +1049,7 @@ private void prefillInjectableFacts(Facts facts, String template) {
}

private void addParagraph(Document layoutDocument, HorizontalAlignment horizontalAlignment, String headerDetails) {
layoutDocument.add((IBlockElement) (new Paragraph(headerDetails).setHorizontalAlignment(horizontalAlignment)));
layoutDocument.add(new Paragraph(headerDetails).setHorizontalAlignment(horizontalAlignment));
}

private final String getAppPath(Context context) {
Expand All @@ -1054,20 +1062,20 @@ private final String getAppPath(Context context) {
}

private final void addTitle(Document layoutDocument, String text) {
layoutDocument.add((IBlockElement) ((Paragraph) ((Paragraph) (new Paragraph(text)).setBold()).setUnderline()).setTextAlignment(TextAlignment.CENTER));
layoutDocument.add((new Paragraph(text)).setBold().setUnderline().setTextAlignment(TextAlignment.CENTER));
}

private final void addEmptyLine(Document layoutDocument, int number) {
int i = 0;

for (int j = number; i < j; ++i) {
layoutDocument.add((IBlockElement) (new Paragraph(" ")));
layoutDocument.add(new Paragraph(" "));
}

}

private final void addSubHeading(Document layoutDocument, String text) {
layoutDocument.add((IBlockElement) ((Paragraph) (new Paragraph(text)).setBold()).setHorizontalAlignment(HorizontalAlignment.LEFT));
layoutDocument.add((new Paragraph(text)).setBold().setHorizontalAlignment(HorizontalAlignment.LEFT));
}

public static List<LocationTag> getLocationTagsByTagName(String tagName) {
Expand Down Expand Up @@ -1157,4 +1165,4 @@ public static String getLocationLocalizedName(Location location, JsonFormActivit
}
return locationName;
}
}
}
Loading

0 comments on commit ee41246

Please sign in to comment.