#!/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

      s i=$zsrand(7777)

      set icd=^icd
      set names=^names

      use 5

      if '$d(%1) s %1=5

      write "drop table if exists problems;",!
      write "create table problems (ptid char(10), icd_code char(10), onset date, "
      write "resolved date, physician_code int);",!
      write "begin transaction;",!

      for k=1:1:%1 do
      . set ptid=100000
      . for i=1:1:^ptcount(0) do
      .. set ptid=ptid+1000
      .. write "insert into problems values ( '",ptid,"', "
      .. set icdx=$p(^icd($r(icd)+1)," ",1)
      .. write "'",icdx,"', "
      .. write "'",^dates($r(date)+1),"', "
      .. write "'",^dates($r(date)+1),"', "
      .. set dx=$r(names)+1
      .. write dx," );",!
      .. set ^pdx(ptid,dx)=""
      .. set ^picd(ptid,icdx)=""
      write "end transaction;",!
