+
+(declaim (inline srl-to-srlus))
+(defun srl-to-srlus (srl)
+ "Convert the standard SRL category to one oriented for use in the ~
+United States. Specifically, SRL 4 in the USA has license restrictions ~
+between SRL 1 and 2 when used in the United States. As of 2009AA, the
+SNOMED SRL changed from 4 to 9. So we create a new scale ~
+(SRLUS) where SRL to SRLUS mapping is: ~
+(0->0, 1->1, 4->2, 9->2, 2->3, 3->4)."
+ (declare (type (integer 0 100) srl))
+ (cond
+ ((<= srl 1) srl)
+ ((= srl 4) 2)
+ ((= srl 9) 2)
+ ((= srl 2) 3)
+ ((= srl 3) 4)
+ (t srl)))
+
+(defvar *vff-position-hash* (make-hash-table :size 100 :test 'eq))
+
+(defmacro vff (filename fieldname record)
+ (let ((pos (gensym "POS-"))
+ (found (gensym "FOUND-"))
+ (key (kmrcl:ensure-keyword (concatenate 'string filename "^" fieldname))))
+ `(locally (declare (optimize (speed 3) (safety 0)))
+ (multiple-value-bind (,pos ,found) (gethash ,key *vff-position-hash*)
+ (declare (ignore ,found))
+ (if ,pos
+ (locally (declare (type (integer 0 100000) ,pos))
+ (nth ,pos ,record))
+ (let ((,pos (position-field-file ,filename ,fieldname)))
+ (unless ,pos
+ (error "Did not find fieldname ~A in filename ~A." ,fieldname ,filename))
+ (locally (declare (type (integer 0 100000) ,pos))
+ (setf (gethash ,key *vff-position-hash*) ,pos)
+ (nth ,pos ,record))))))))
+