Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Using Tap Forms › Help parsing ocr to form fields
- This topic has 9 replies, 3 voices, and was last updated 10 months, 3 weeks ago by Daniel Leu.
-
AuthorPosts
-
January 29, 2024 at 5:24 PM #50414
Simon SpiersParticipantI’ve been using Tap Forms for a few years as a digital log book of patients. The primary purpose is to capture billing details. Prompted by watching Sam’s excellent video on OCR Receipt Extraction. I’d like to have a script to auto populate fields with the OCR from a scan of the patient’s ID label..My current workflow is to scan a patient’s hospital label with my iPhone, transfer it to the photo field in a new TF record before manually entering data from the scanned image. It’s the digital equivalent of sticking a label in a book in order to annotate it with other data like start and finish times, items, etc..What I’d like to do is scan the label with my iPhone (I use Scanner Pro which does a pretty reliable OCR), create a new record in TF that contains the image in a photo field and the OCR’d text in a notes field, then use a form script to automatically populate fields in the TF form. Because the data is sensitive I want to keep it encrypted, only on my own devices and synced using near field only..Let me show an example..The same fictional patient on different hospital labels gives OCR text:.HEELER, MR BanditMRN: OT000123456DOB: 04/09/1978 Age: 44 (M)10 CATTLEDOG ROADBETOOTA HEIGHTS 4483Home Ph: 0491 577 426MC: 2123456791S/Net No:DVA:BETOOTA PRIVATEAdm NoCT04589023Adm Date: 12/01/2413:48Att Dr: Fixem, Ayecan SRef Dr: Payne, Ophelia MFund: HFHHF50006000MC Exp: 05/2028 MC Ref: 1Pen No:0038708YAD: 12/01/2024Adm No. 4589023HEELER, MR Bandit10 Cattledog RdBetoota Heights, QLD 4483PH: 0491577426 M: 0491577426MC: 2123456791/1 Exp:05/2028CL: PI HHF/T 50006000PC NILAD: 12/01/2024FIXEM, DR AYECANUR: 123456Adm No. 4589023DOB: 04/09/1978 (44Y)MAR: MGender: MaleBET 0038708Y.The bits of data I need are first name and surname, DOB, MC, MC Ref, fund code and fund number (‘HHF’ and 50006000 in the example)..These would map to TF fields surname (text), first name (text), DOB (DD/MM/yyyy), MC (number), MC ref (number), fund code (link from form) and fund number (text; sometimes contains letters) in a single TF form called ‘Cases’..The stickers are rectangular and in landscape orientation, so they have information in two columns. The lines of OCR text aren’t always in the same order, e.g. sometimes the admission number or MRN appear between the address lines. The identifier snippets are always present and predictable, though. For instance, fund code is always found after ‘Fund:’ or ‘CL: PI’ which will always be on the same line..Sam’s script for his fuel receipts is awesome. I want to do something like it, but I also want to know how it works so I can fix it and build on it. I’m new to scripting and I’m trying to get simple things to work before adding more complexity. Not having much success though. Here’s my attempt:.function mc() {
var mc_id = ‘fld-abbabb14632f41718ffb4a259cebe63a’;
var label_text_id = ‘fld-d80875c6c53048c8bcf97b11e190118d’;
var input = record.getFieldValue(label_text_id);
var mcRegex = /[2-6]{1}[0-9]{9}/;
var found = input.match(mcRegex);
if (record.getFieldValue(mc_id)) {
return;
}
record.setFieldValue(mc_id, found);
console.log(found);
document.saveAllChanges
}
mc();.It finds mc in the notes field text but doesn’t populate the MC field..Can anyone help me with this?.I have a couple of related questions after watching Sam’s video:.1. How can I create a new record in TF on iOS that contains both the scanned image (jpg) and OCR text string of the scan in a notes field? I’m able to get one piece of information in easily using Shortcuts/x-callback, but two?2. How can I create a link from form using scripting? I’d like to extract the fund code (‘HHF’ in the example;Fund:\s?HF?(\D{3})|CL: PI\s?(\D{3})
) then link from the HHF record in the ‘Funds’ form.January 30, 2024 at 10:08 PM #50418
BrendanKeymasterHi Simon,
You’re missing the
()
at the end ofdocument.saveAllChanges;
. It should bedocument.saveAllChanges();
That would prevent the MC field from being saved. Does theif
statement work properly for you? Just thought it would be more clear if you were checking if the value was empty or not instead of just calling the function.For example:
if (record.getFieldValue(mc_id) != undefined) { return; }
I’m assuming that you’re doing that check because you don’t want to populate the
mc_id
field if it already has a value.1. Might have to ask Sam about that as he’s got way more experience than I do with shortcuts.
2. You can create a related record using the
record.addRecordToField(someRecord, field_id);
function.Thanks,
Brendan
January 31, 2024 at 6:03 PM #50421
Simon SpiersParticipantHi Brendan,
Thanks for the reply and suggestions. Yes, the
if
statement is to check if the field already has a value and skip the process if so.I’ve updated the script but it’s still not populating the form fields:
function mc() { var note_id = 'fld-9adb85030f8a42b3aeea043ea5885d05'; var mc_id = 'fld-77a5e9f11f4947caa6135bf312030965'; var input = record.getFieldValue(note_id); var mcRegex = /[2-6]{1}[0-9]{9}/; var found = input.match(mcRegex); if (record.getFieldValue(mc_id) != undefined) { return; } record.setFieldValue(mc_id, found); document.saveAllChanges(); } mc();
It seems that the issue is with the
record.setFieldValue(mc_id, found);
line. I get the correct value if I returnfound
to the console.Thanks for looking at it.
Simon
- This reply was modified 10 months, 3 weeks ago by Simon Spiers.
January 31, 2024 at 9:12 PM #50423
Daniel LeuParticipantMaybe it’s a type issue. Usually Javascript is not very type agnostic. Is MC defined as a
number
? Does atext
field work instead?January 31, 2024 at 9:45 PM #50424
Simon SpiersParticipantNo, doesn’t work with text or number field
February 1, 2024 at 12:21 AM #50426
Daniel LeuParticipantCan you share your document?
February 1, 2024 at 1:17 AM #50427
Simon SpiersParticipantHere it is
Attachments:
You must be logged in to view attached files.February 1, 2024 at 9:38 AM #50429
Daniel LeuParticipantI was on the correct track that there’s a type issue. The
match()
method returns an array. So you can just grab the first element or you might want to additionally check that there’s only one element (found.length ==1
):record.setFieldValue(mc_id, found[0]);
Do you have the link to Sam’s parser script? Thanks!
- This reply was modified 10 months, 3 weeks ago by Daniel Leu.
February 1, 2024 at 4:44 PM #50438
Simon SpiersParticipantThanks Daniel. That makes sense and it now works!
Sam didn’t provide the script, I saw some of it in his video. It seems complex and suited to his own particular use. I’m hoping he’ll weigh in here.
February 1, 2024 at 5:14 PM #50439
Daniel LeuParticipantGreat that you got it working, Simon. Okay, so I was it in his video!
-
AuthorPosts
You must be logged in to reply to this topic.