#!/usr/bin/mumps

      s i=$zsqlite("pragma","journal_mode=off")
      s i=$zsqlite("pragma","synchronous=off")

      w "pragma journal_mode=off;",!
      w "pragma synchronous=off;",!

      set date=^date
      set time=^time

      open 1:"city,old"
      use 1
      set city=1
      for  do
      . read a
      . i '$t break
      . s ^city(city)=a
      . set city=city+1
      set city=city-1
      close 1
      set ^city=city

      set names=^names

      open 1:"streets,old"
      use 1
      set streets=1
      for  do
      . read a
      . i '$t break
      . s ^streets(streets)=a
      . s streets=streets+1
      set streets=streets-1
      close 1
      s ^streets=streets

      if '$d(%1) set ptcount=1000
      else  set ptcount=+%1

      set ^ptcount(0)=ptcount

      use 5
      write "drop table if exists patientId;",!
      write "create table patientId (ptid char(10), entry_date date, entry_time time, name varchar(100), "
      write "prefix char(3), suffix char(3), street varchar (100), city_state varchar(100), zip char(5), "
      write "tel char(20), insurer_code char(10) );",!
      write "begin transaction;",!
      set ptid=100000
      for i=1:1:ptcount do
      . set ptid=ptid+1000
      . write "insert into patientId values ( '",ptid,"', "
      . write " '",^dates($r(date)+1),"', "
      . write " '",^time($r(time)+1),"', "
      . write " '",^names($r(names)+1),"', "
      . set pre=$r(2)
      . if pre=1 write "'Mr.', "
      . else write "'Ms.', "
      . set pre=$r(3)+1
      . if pre=1 write "'Jr.', "
      . if pre=2 write "'Sr.', "
      . if pre>2 write "' ', "
      . write !
      . write "'",$r(999)+1," ",^streets($r(streets)+1)," "
      . s x=$r(3)
      . if x=0 write "Rd. "
      . if x=1 write "Lane "
      . if x=2 write "Ave. "
      . s x=$r(3)
      . if x=0 write "Apt ",$r(99)+1,"', "
      . else write "', "
      . write "'",^city($r(city)+1),"', "
      . for  set x=$r(99999) if x>999 quit
      . write "'",x,"', "
      . for  set a=$r(999) if a>99 quit
      . for  set b=$r(999) if b>99 quit
      . for  set c=$r(9999) if c>999 quit
      . write "'(",a,") ",b,"-",c,"' , "
      . set k=$r(^insurance)+1
      . set icode=$o(^insurance(k,""))
      . write "'",icode,"' );",!
      write "end transaction;",!
