Using barcode scanner in the clinic create form with repeat group

CHT version: 4.7.1

I am incorporating barcode scanner app inside the clinic create form. I have added the barcode scanner group under the init section (lines 64-71). I am also adding the same group under the repeat group (lines 96-103).

Upon compiling, it throws an error :

There has been a problem trying to replace ${SCAN_RESULT} with the XPath to the survey element named ‘SCAN_RESULT’. There are multiple survey elements with this name.

The issue is that changing the variable name SCAN_RESULT to something else results in the scan results not showing up. Happy to get any feedback on this.

Hey @iesmail - sorry to hear you’re having issues!

Two quesitons:

  • Is this the complete spreadsheet? If yes, it’s missing “survey”, “choices” and “settings” worksheets. If no - are you able to share the full version?
  • What version of CHT Conf are you running?

Hi @mrjones,

Sorry about that. I have added the missing worksheets. Please use this.

I am running 4.7.1.

Thanks! I got a copy of the form (though maybe make it readable by anyone with the link if you haven’t already?)

As well, I’ve reproduced your error. Indeed, lines 69 and 101 are not allowed to have the same name.

@Jennifer_Quesada is going to know the most about this, but let me dig into this a bit and see what I can find!

1 Like

@iesmail - I didn’t make as much progress as I’d like today - sorry!

However, one issue is that the form is a bit complex to trigger the barcode. Can you make a copy of the form with as few fields and as little logic as possible that still has the problem? This would greatly ease debugging and reproducing.

Thanks!

@iesmail - OK! With some help from @jkuester - we figured out that there were two issues:

  1. you were missing a calculate at the top of the form. This allowed the parent contact to get a SCAN_RESULT field set for the document.
  2. you need to use relative paths like ../../init/barcode/android-app-outputs/SCAN_RESULT instead of ${SCAN_RESULT} for the value of the calculate column. This avoids the There are multiple survey elements with this name error you were getting.

Here’s a form that has a working repeat and a working parent contact, each getting their own value for SCAN_RESULT. Note that this form is hacked up quite a bit as I tried to remove as much required=true and whole fields to make it easier to debug. However, you should see the fixes and be able to test locally!

2 Likes

@mrjones , this worked, however, when I look at the couch doc for the primary contact, I don’t see the kadi_ya_matibabu field. The barcode value is rather stored in the SCAN_RESULT. Please see below:

  "_id": "22d3929b-2712-4a30-a665-9225e6bf06ef",
  "_rev": "2-3541e12aa1f9e9209f0bc98eb9b9b6ec",
  "SCAN_RESULT": "159002110013",
  "first_name": "Samiha",
  "middle_name": "Faki",
  "last_name": "Haji",
  "name": "Samiha Faki Haji",
  "sex": "female",
  "exact_dob_known": "no",
  "date_of_birth": "2001-01-01",
  "phone": "0714567890",
  "phone_owner": "mine",
  "phone_owner_other": "",
  "alternate_phone": "",
  "is_head_of_household": "yes",
  "meta": {
    "created_by": "chv",
    "created_by_person_uuid": "4f84b499-64e1-4347-b1ff-6220cf62069f",
    "created_by_place_uuid": "f1b94c7d-e10b-46b8-ba54-49b3a1a5bb23"
  },
  "reported_date": 1723528179590,
  "type": "person",
  "parent": {
    "_id": "5cd33368-25c2-45b0-8f32-1c6d77233163",
    "parent": {
      "_id": "f1b94c7d-e10b-46b8-ba54-49b3a1a5bb23",
      "parent": {
        "_id": "ea307363-38c4-439e-a7da-1bddf6dcab9a"
      }
    }
  },
  "form_version": {
    "time": 1723527892892,
    "sha256": "15898d1e5a6c661b6b8431edf62cf98af895f8fc033d5154545764f8bd50dc89"
  },
  "patient_id": "07213"
}

Whereas the couch doc of the contact in the repeat group contains the kadi_ya_matibabu variable as well as the whole barcode_repeat group.

{
  "_id": "38e7b186-9b7c-4911-a9ae-4cae2f793de1",
  "_rev": "2-28d53ad8076d3564d59c5e300faa8794",
  "hh_member_note": "",
  "type": "person",
  "parent": {
    "_id": "5cd33368-25c2-45b0-8f32-1c6d77233163",
    "parent": {
      "_id": "f1b94c7d-e10b-46b8-ba54-49b3a1a5bb23",
      "parent": {
        "_id": "ea307363-38c4-439e-a7da-1bddf6dcab9a"
      }
    }
  },
  "first_name": "Daudi",
  "middle_name": "Faki",
  "last_name": "Haji",
  "first_name_c": "Daudi",
  "middle_name_c": "Faki",
  "last_name_c": "Haji",
  "name": "Daudi Faki Haji",
  "sex_note": "",
  "sex": "female",
  "sex_c": "female",
  "exact_dob_known": "no",
  "exact_dob_known_c": "no",
  "age_estimate": "23",
  "yob": "2001",
  "temp_hh_member": "temporary",
  "barcode_repeat": {
    "action": "com.google.zxing.client.android.SCAN",
    "android-app-inputs": "",
    "android-app-outputs": {
      "SCAN_RESULT": "159002110013"
    }
  },
  "kadi_ya_matibabu_id": "159002110013",
  "date_of_birth": "2001-01-01",
  "date_of_birth_c": "2001-01-01",
  "is_exact_dob_in_range": "1",
  "reproductive_age": "1",
  "is_under_5_binary": "0",
  "age_days": "8625",
  "return_women_note": "",
  "debug_note": "",
  "meta": {
    "created_by": "chv",
    "created_by_person_uuid": "4f84b499-64e1-4347-b1ff-6220cf62069f",
    "created_by_place_uuid": "f1b94c7d-e10b-46b8-ba54-49b3a1a5bb23"
  },
  "reported_date": 1723528179616,
  "form_version": {
    "time": 1723527892892,
    "sha256": "15898d1e5a6c661b6b8431edf62cf98af895f8fc033d5154545764f8bd50dc89"
  },
  "patient_id": "02008"
}

Another issue with the scanner is that if I scan a QR code and then manually delete the ID, when I try to re-scan the same QR code, the ID does not reappear in the text field. However, if I navigate back to the previous screen and return, the ID becomes visible again. The ID also appears correctly if I re-scan with a different QR code. The issue only occurs when re-scanning the same QR code.

Ah - gotcha - we can get both parent and repeat contacts to both have the same top level (not nested) kadi_ya_matibabu_id field - I’ve mocked this up in the existing shared form.

We do this by making two changes:

  1. rename the parent most calculate field from SCAN_RESULTS to kadi_ya_matibabu_id
  2. change the string to calculate for the kadi_ya_matibabu_id field within the repeat section. For the repeat contact you’ll have both a nested SCAN_RESULTS fields and a top level kadi_ya_matibabu_id field

and here’s what the parent contact will look like:

{
  "_id": "e1ced9f1-1011-4be1-a5ee-8235e52dbf35",
  "_rev": "2-f2f89b35d584c745a073034727b660a3",
  "kadi_ya_matibabu_id": "sample",
  "first_name": "valid 10",
  "middle_name": "",
  "last_name": "",
}

And here’s what a repeat contact will look like:

{
  "_id": "a26f9924-3880-496b-a73d-e3509ed3fddf",
  "_rev": "2-0735719219809dc4c9fa71bbc203e048",
  "first_name": "sub1",
  "middle_name": "",
  "last_name": "",
  "barcode_repeat": {
    "action": "com.google.zxing.client.android.SCAN",
    "android-app-inputs": "",
    "android-app-outputs": {
      "SCAN_RESULT": "sample"
    }
  },
  "kadi_ya_matibabu_id": "sample",
1 Like

Can you be more specific? How do you delete the ID? When I get to the section of the form to scan a barcode, I just see the button and it’s the same before and after I scan an ID. I don’t see a way to delete the ID:

image

@mrjones , thanks for the prompt responses.

1. rename the parent most calculate field from SCAN_RESULTS to kadi_ya_matibabu_id

This worked and it was the only change needed.

2. change the string to calculate for the kadi_ya_matibabu_id field within the repeat section. For the repeat contact you’ll have both a nested SCAN_RESULTS fields and a top level kadi_ya_matibabu_id field

What this does is hide the text fields that’s supposed to show the scanned result. So I think it’s better to leave it as string

Here’s step by step on how you can reproduce the second issue.

  1. Open the scanner app and scan the QR code.
    Capture1

  2. Clear the scanned result from the text field.

  3. Re-scan the same QR code. The text field will not show the scanned result.
    image

  4. Open the scanner and scan with a different QR code. The scanned results will appear in the text field.
    image

So I would like to see the scanned results if you scan with the same QR code after clearing the text field.

@iesmail - ah yes - I see what you mean - thanks for the clear explanation.

I’m able to reproduce your results and agree this is an odd behavior. If your workflow will allow only barcode as input, you could make this a note field so you can see what was entered, but not edit it.

Otherwise, this feels like a bug. I was going to open a new issue on CHT Core, but GitHub is down right now. I post the issue link later when it’s back up!

cc @Jennifer_Quesada

1 Like

@iesmail - I’ve created the issue to track this bug. Feel free to add any details!

1 Like

@iesmail - so - @jkuester and I made some progress!

The trick was to not involve a 2nd field with a calculate. Per this comment on the now closed ticket, use just the one SCAN_RESULT which the user can interact with. As this is what gets populated by the barcode, it will be always up to date.

Further down in your form, in a hidden calculate field, you can optional set the calculated value to another field not so deeply nested in the field groups.

Have a look at the ticket, the sample form there and the demo videos and let us know if you have any questions!

@mrjones, thanks! This makes sense.

Also, how do I change the label of the barcode scanner button? Currently it read Launch app. I want to change the English and respective Swahili translation.

Hi @iesmail

There is a translation key already in Swahili android_app_launcher.button.launch