Unit 24 – Subscripting 1

Although data fields whose subscripts are not defined will not return a value when referenced within the report as standard data fields, we can create a MAGIC expression to return a value for these fields. In order to create the MAGIC expression, make note of the subscripts associated with the field you

want to access and create an expression using the field name and the subscripts. The subscripts you define will either be data fields (value changes with every record) or free text constants (value is the same for every record).

Examples

The above is an example of how to subscript to get the ins.balance from BAR.PAT when writing in the BAR.PAT.bar.acct.transactions segment. The ins.balance field is located in the BAR.PAT.bar.acct.insurance.ledger segment:

In order to have access to any fields in this segment, you must define the two subscripts of the segment, account and ins. In the example above, the field account will define the account and the free text of “SP” will define the ins. This will now return the ins.balance value, for the account’s self pay insurance. The code above will work correctly, however it can be revised to you less coding as shown below:

Workshop
  • Get the charges of a patient’s first bill in report that uses the detail segment BAR.PAT.bar.acct.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

  • Get the transaction insurance’s policy number in report that uses the detail segment BAR.PAT.bar.acct.transactions.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

* We will go over these examples together as a class *

Note: For additional information on subscripting as well as information on how to subscript to virtual fields visit the MIX Magazine articles we have at the links below:

Subscripting

Subscripting Virtual Fields

Subscripting Written Exercises

  1. Writing a report out of PP.PAY.pp.time.card.file, find the earning amount for the overtime earnings. Note: The overtime earning code is 02.

Target DPM PP.PAY

Target Field earning.amount

Missing Subscripts earning

Value(s) to Define Subscripts

VAL=

  1. Writing a report out of ADM.PAT.adm.patient.file, print the first line of the scheduling notes.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

  1. Report in ADM.PAT.adm.patient.file, print the first event code for the patient’s admit date.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

  1. Report in OE.ORD.oe.order, print the price of the order procedure.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

  1. Report is in LAB.L.SPEC.lab.l.spec.ordered.tests, print the result of each ordered test.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

  1. Report in ABS.PAT.abs.pat, print the first full name of the patient’s first condition.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

  1. Writing a report in ADM.PAT.adm.patient.file, print the patient’s first diagnosis code.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

  1. Writing a report in RADRW.EXAM.radiology.exam, print the primary care doctor of the patient.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

  1. Writing a report in SCH.APPT.sch.appointment, print the mnemonic of the first order set of the patient’s appointment type.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

  1. Writing a report in SCH.APPT.sch.appointment, print the name of the first order set of the patient’s appointment type.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

  1. Writing a report in LAB.L.SPEC.lab.l.specimen.file, print the address of the admitting doctor of the patient associated to the specimen.

Target DPM

Target Field

Missing Subscripts

Value(s) to Define Subscripts

VAL=

Subscripting into an Index

Report in BAR.PAT.bar.acct.transactions, print the journal of the batch that a transaction is on. Note: You will need to subscript into an index in order to do this.

Target DPM BAR.BCH

Target Field journal

Missing Subscripts urn (of the batch)

Index bar.batch.number.x

Value(s) to Define Subscripts txn.bch.date, txn.bch

VAL=

Subscripts of the BAR.BCH.bar.batch.number.x index:

[date,number] = urn

When you see an equal sign after the subscript of an index it means that if you provide values of t he subscripts of that index it will return the value after the equal sign. In this case, if we provide this index the date and number of the batch and it will provide the value of the urn for the batch. We can then use that urn to subscript to get the BAR.BCH.journal field.

For more information on the example in the challenge see KB article# 21097:

@First, @Last

Objectives

  • Define the syntax for using the @First and @Last macros
  • Provide examples of using @First and @Last in subscripting

There are two standard macros allowing you to access the first or last subscript value of a segment. The syntax of these macros is illustrated in the diagram below. The @First macro will generate code to obtain the first value of a subscript. The @Last macro will generate the code to obtain the last value of a subscript. The key is that the value in parentheses must be a subscript.

The @First and @Last macros identify the segment which contains the subscript and generates the MAGIC code to return the first or last value of the subscript.

In the example above, the code will return the number of the last bill of the patient from the BAR.PAT.bar.acct.bills segment. Since the bills segment uses the bill.no as a subscript, the code will return the last bill number stored in the segment for the patient.

In the example above, the code will return the charges of the last bill of the patient from the BAR.PAT.bar.acct.bills segment. @Last(bill.no) will find the last bill number of the patient, which will be used to subscript the field bill.charges.

The example above assumes we are writing in BAR.PAT.bar.acct and subscripts to the BAR.PAT.bar.acct.transactions segment to get the service date of the last charge transaction. This first sets the txn.class to “C” for charges using the following code:

“C”^txn.class

Since txn.class is a subscript and translates to a local variable, we can send a value to it. This is needed, since txn.class is the second subscript of the segment. Then the @Last(txn.urn) will get the last txn.urn value for that account and txn class(“C”).

* Note: Sending a value to a subscript can only be used when the subscript is not in your detail segment, index file, or part of a multiple being used on the report. Overwriting a subscript that is currently in use can cause the report to run into an infinite loop.

MEDITECH

Level One - NPR Report Writer Workshop