Blog
Sorry, your browser does not support inline SVG.

Access VistA Lab Chemistry Data from Octo

Sam Habiel

We recently received a feature request for Octo to natively support “Piece of Piece”; e.g., to declare a column in Octo corresponding to a construct like $PIECE($PIECE(^A,"|",3),"^",2). Although Octo could previously represent such a use case with a computed column, a computed column cannot be indexed; so a query will be expensive. Octo now allows such a column to be defined and indexed.

As part of this work, I took the opportunity to implement the extraction of Lab Chemistry Data in VistA. What’s the connection? VistA data is almost always stored as ^ delimited pieces (e.g., A^B^C) or as Extract ranges (ABCXYZ range 1-3 = ABC). Only in the storage of Chemistry Data in the Lab Package do we get a sub-piece: A^B^C1!C2!C3. To make it concrete, here is some made-up Chemistry Data from VistA:

^LR(314452,"CH",6879595.9,0)="3120403.1^1^3120403.110048^111346^73^CH 0403 350^^CBS A^^184920^6D^^1738;SC(^648"
            41)="66^H^82550.0000!82550.0000!2157!4151!!!197^111346^73!28!181!!!!IU/L^^^^648^1"
        "NPC")=3
        "ORU")=1120940350

Notice how under the 41 node, the third ^ separated piece has ! delimited data within it.

Fileman to this day cannot read this data except using computed fields because it cannot represent “piece of piece”. But if you have the latest Octo, you can grab lab_chem_result.sql from YDBOctoVistA to unlock your Lab Data. Here’s how some of the data (the third ^ delimited piece above) is represented in Octo:

 -- Piece 3 (workload) -- "!"-sub-delimited:
  NATIONAL_LAB_CODE`      VARCHAR DELIMS ("^","!") PIECES (3,1), -- 3.1 National Lab Code
  RESULT_NLT_CODE`        VARCHAR DELIMS ("^","!") PIECES (3,2), -- 3.2 Result National Lab Code (+suffix)
  LOINC_CODE`             VARCHAR DELIMS ("^","!") PIECES (3,3), -- 3.3 LOINC (no checksum char)
  WORKLOAD_SUFFIX`        VARCHAR DELIMS ("^","!") PIECES (3,4), -- 3.4 Workload Suffix
  TEST_IEN_FILE_60`       INTEGER DELIMS ("^","!") PIECES (3,7), -- 3.7 IEN pointer to file 60 ^LAB(60,

Here is a sample query and results from fictitious data:

OCTO> select * from LAB_CHEM_RESULT WHERE LRDFN=27 AND RESULT_FLAG='H*';
lrdfn|invdt|test|result_value|result_flag|national_lab_code|result_nlt_code|loinc_code|workload_suffix|test_ien_file_60|verifying_tech|site_specimen|reference_low|reference_high|critical_low|critical_high|units|delta_check_type|delta_value|default_value|therapeutic_low|therapeutic_high|institution|equipment_id
27|6949291.8968|2|350|H*|84330.0000|||3096|175|11743|72|60|110|50|300|mg/dL||||||500|
27|6949681.984076|2|310|H*|84330.0000|||3096|175|11748|72|60|110|50|300|mg/dL||||||500|
27|6949681.984076|132|17.5|H*|81323.0000|||3096|440|11748|72|0|8.9||15|U/L||||||500|
27|6969570.894999|2|321|H*||||3096||20364|72|60|123|50|300|mg/dL||||||500|
27|6999477.92|2|400|H*|84330.0000|||||11748|72|60|123|50|300|mg/dL||||||500|
(5 rows)
OCTO>

Credits

Published on August 21, 2026