medic / cht-core

The CHT Core Framework makes it faster to build responsive, offline-first digital health apps that equip health workers to provide better care in their communities. It is a central resource of the Community Health Toolkit.
https://communityhealthtoolkit.org
GNU Affero General Public License v3.0
438 stars 205 forks source link

Barcode scanning using device camera #6669

Open MaxDiz opened 3 years ago

MaxDiz commented 3 years ago

Is your feature request related to a problem? Please describe. As a nurse/CHW, I do home visits to follow-up with patients who are in treatment for disease management, but did not show for clinic appointments. Patients are often taking multiple medications (or using other health products), which are hard to keep track of. Having an accurate list of these products is critical to creating and managing up-to-date health record for patients. The process for collecting this information is currently manual, making it difficult to capture it in a timely and accurate way.

Describe the solution you'd like As a nurse, I would like the ability to scan barcodes for patient IDs or barcodes on medications (or other health products) to quickly and accurately acquire patient health information.

Describe alternatives you've considered

Additional context bar code scanner is supported by XLSForm and ODK Collect

Worth noting that ZXing is in maintenance mode, and ODK Collect had to build in the scanner as opposed to an intent since 1.7. There is more investigation needed to know if this is a relatively simple task (handle the XLSForm type and make/handle a new intent) or a big lift.

MaxDiz commented 3 years ago

@isaacholeman please add any additional context specific to the project (or correct anything I misunderstood)

isaacholeman commented 3 years ago

Looks great @MaxDiz. I added that it's also a requirement to be able to scan barcodes to get patient ID. Thanks!

garethbowen commented 3 years ago

Also investigate supporting QR codes.

MaxDiz commented 3 years ago

Relevant CHT Forum conversation

latin-panda commented 2 years ago

Update:

i-tech-malawi project is also interested in scanning a barcode to save the patient's ID, this barcode is generated by the EMR system. They also see very valuable being able to scan a barcode to search for a patient. From this we can highlight two requirements:

1 - Registration of a new patient and getting the patient's ID: Currently achievable by using the Android App Launcher where a form can be configured to open an android app that can scan barcodes, the information in the barcode will be saved in this form.

2- Searching for a patient in contact tab by scanning the barcode: This one needs implementation in CHT-Core to open an android app to scan the barcode and search the patient.

CC: @garethbowen @craig-landry for prioritisation. @mmureithi @katanu @antonykhaemba please add any relevant information. Useful links: feature request doc, forum post

latin-panda commented 9 months ago

@michaelkohn @lorerod @n-orlowski FYI

Nb. This will be delivered in 4 different PRs:

This work uses the native Barcode Detector API from the browser by using a hidden input type file to natively open the camera in Android devices. This avoids custom code in the CHT Android and allows more accessibility since the feature can be used in CHT Android, PWA, and Android browsers.

It works the following way:

More considerations:

Telemetry:

Snackbar messages:

Videos

latin-panda commented 9 months ago

Read the previous comments for more details.

Knowns

Troubleshooting

How it works technically

As mentioned in the previous comment, this approach uses a hidden input type, file to make Android open the camera and take the picture. This picture is uploaded into the app, and then we use the new native API called Barcode Detector API [experimental feature - it has full support in Chrome and Webview for Android, but it's not supported by Firefox for Android].

When the browser uses this API, it utilises the OS tooling to be able to interpret barcodes from image elements. There are many types of barcode, and the support for these type of barcodes are built into the OS (MacOS, ChromeOS, and Android OS).

The browsers are using Android's ML Kit (previously known as GMS Vision) to read and interpret barcodes, this is usually available in the phone with the Google Play services app (see release notes). This is one reason why it's recommended that users keep their Android OS (and services) and Chrome Browser updated. Worth mentioning for completeness that when it comes to MacOS, the browsers are using CIQRCodeFeature.

garethbowen commented 9 months ago

@latin-panda Thanks for the update! Did you have a look at this barcode-detector library? It looks well supported (12k weekly downloads, recent updates, etc) and works as a polyfill for the experimental API you're using so it may be easy to drop in. I haven't tested it or checked bundle size, etc but it might be worth a look.

This is one reason why it's recommended that users keep their Android OS (and services) and Chrome Browser updated.

We know that this doesn't usually happen (despite our recommendations). In fact, last time I was in Kenya, safaricom txted me and recommended disabling app auto-updates to save data. Is there an easy way to figure out what is available in the MLKit that's available in Google Play services that shipped with Android 5 (minimum supported android version)?

latin-panda commented 9 months ago

Thanks @garethbowen the barcode-detector polyfill looks nice, and I like that it follows the same specification as the native API. To make it work for offline users, my guess is that we need to make their C++ library available on the client side using the service worker. This is based on Zxing work, which is quite famous, and many have forked his work to make it available on different platforms. I'm going to give it a try as a polyfill when the native API isn't supported. I think this isn't blocking the Feature Release and can go in parallel.

These are other libraries I looked at before:

latin-panda commented 9 months ago

Is there an easy way to figure out what is available in the MLKit that's available in Google Play services that shipped with Android 5 (minimum supported android version)?

@garethbowen The release notes are published online since these are toolings that Android developers need:

I haven't analyzed the release notes in detail, but a quick search on those pages shows mentions of the Barcode feature in Mobile Vision package of Google Play services v9.2 (June 2016)

latin-panda commented 2 months ago

Removing from milestone as it wasn't completed on that iteration