Next / Previous / Contents / Shipman's homepage

7. scanFieldItems(): Parse a sequence of FieldItem objects

This utility function is used to parse a fixed sequence of fixed-size fields within an encounter record. For the design rationale, see Section 26, “class FieldItem: Base class for encounter record fields”.

Here is the interface:

baseclasses.py
# - - -   s c a n F i e l d I t e m s   - - -

def scanFieldItems(encounter, fieldList, scan):
    '''Scan a sequence of fields described by FieldItem objects.

      [ (encounter is a BaseEncounter object) and
        (fieldList is a list of tuples (fClass, fName) where
        each fClass is a class derived from FieldItem and
        each fName is the name of an attribute in a BaseEncounter
        item) and
        (scan is a Scan object) ->
          if scan starts with a sequence of fields described by
          fieldList in order ->
            scan  :=  scan advanced past all those fields
            encounter  :=  encounter with objects representing
                those fields stored in attributes having the
                corresponding field names
          else ->
            scan  :=  scan advanced no further than end of line
            encounter  :=  encounter with some attributes possibly
                           added
            Log()  +:=  error message(s)
            raise SyntaxError ]
    '''

The logic is straightforward. We iterate over the tuples in fieldList. For each one, we call the static method .scanField() of that class, which handles advancing the scan pointer and storing of the resulting value in the encounter record.

baseclasses.py
    #-- 1 --
    for  fClass, fName in fieldList:
        #-- 1 body --
        # [ if scan starts with a valid field for class=fClass ->
        #     scan  :=  scan advanced past that field
        #     encounter.(fName)  :=  an object representing that
        #                            field
        #   else ->
        #     scan   :=   scan advanced no further than end of line
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        fClass.scanField(encounter, scan, fName)