Creating a New Mysql database on the Command Line…The Easy Way!

The following Python script  can make your life easier if you often need to create new, blank, databases for a Rails,  Django, or for any other reason.  The script makes use of ‘sed’, the Unix stream editor utility.  It should work on Linux, Max OS X, and almost all flavors or Unix.

The utility also attempts to download and install mysql server using ‘apt-get’.  If MySQL server is already installed, then you can comment out that line.  You will also need to comment out that line if you are not using Ubuntu or a Debian derivative.  You”ll also need to execute the script as root (‘sudo’) if you want to install MySQL server.

You’ll need to set the MySQL root name and password to your local values.  The script takes exactly 3 command line arguments: database name, database user, and database password.  When you run the script the database and the user you specify get created.  The script works by writing an sql script, then executing it as mysql root.

To execute the command:

>python mydbname myusername mypassword

Here is the source code:

# setup a mysql server and install a blank db
# Written in Python by Alan C. Viars
# (c) Videntity Systems Inc.
# Freely redistributable under the BSD open source license.

import os
import sys

#set these to your local values

def setup_mysql(db_name, db_user, db_pass):

        print "setup_mysql-------------------------------------------------------"
        SED_mssg= "# Autogen file w/ SED"

        #install mysql and prereqs -comment out the next 2 lines if mysql server
        # or if you are not running Ubuntu/Debian
        os.system("sudo apt-get update")
        os.system("sudo apt-get -y install mysql-server")

        #write the stub_dmysql_dbcreate.sql file
        SED_mssg= "# Autogen file w/ SED"

        prepare = "sudo sed -e 's|_SED_|%s|' <stub_mysql_dbcreate.sql >stub_temp" % (SED_mssg)
        print prepare

        prepare = "sudo sed -i 's|_db_name_|%s|' stub_temp " % (db_name)
        print prepare

        prepare = "sudo sed -i 's|_db_user_|%s|' stub_temp" % (db_user)
        print prepare

        prepare = "sudo sed -i 's|_db_pass_|%s|' stub_temp" % (db_pass)
        print prepare
        os.system("sudo mv stub_temp mysql_dbcreate.sql")

        #create thep database
        prepare = ("sudo mysqladmin --user=%s --pass=%s create %s") % (db_root_user,
        print prepare

        #execute user.permission create script
        prepare = ("sudo mysql --user=%s --pass=%s < %s ") % (db_root_user,
        print prepare

        print "Error in setup_mysql."
        print sys.exc_info()
        return 1

if __name__ == "__main__":


        python [dbname] [dbuser] [dbpass]

        db_name =   sys.argv[1]
        db_user =   sys.argv[2]
        db_pass =   sys.argv[3]
        setup_mysql(db_name, db_user, db_pass)

            print "There was an error with your input.  Here are the instructions."
            print instructions
            print "Error."
            print sys.exc_info()

Here is the “stub file” that sed needs as input.  Make sure you havge both the script and this file in the same folder. Make sure the file is named ‘stub_mysql_dbcreat.sql’.
File – stub_mysql_dbcreate.sql:

use _db_name_;
GRANT ALL PRIVILEGES ON *.* TO '_db_user_'@'localhost' IDENTIFIED BY '_db_pass_' WITH GRANT OPTION;

Enjoy. I hope this helps someone.  It saves me time. -Alan


Should Health Care Standards be Open Source?

Recently there has been some chatter on Twitter about health standards and open source, so I thought I would write a little commentary on the topic.

Anyone who knows me well, knows that I am huge fan of Linux and open source.  This is perhaps why I get so frustrated with the US health care industry and its general lack of interoperability.  I could use many standards as an example, however, for this discussion I’m using the ASTM Continuity of Care Record (CCR) as an example.  Now I’m not picking on the CCR. The format is XML (good), and while there is always room for improvement, I think the general structure is reasonable and workable.  I’d also point out that David Kibbie and Steven Waldren, two keep champions for the CCR, have always been nice and helpful any time I’ve asked a question on the list serve. I’m using the CCR as example just because the barrier to access is so low ($100).  Much of the following is summarized from an inquiry I made to the CCR list serve about a year ago.

Why isn’t the CCR Open-Source? Why is there a $100 Fee to Access the Format?

Well those questions can be answered in with a single answer.  CCR is a product of the standards development organization (SDO) ASTM.  It is ASTM’s model to charge for access fees to the standards they create.  I always get the same response every time I ask this question.  I always hear something similar to, “If we don’t charge for membership/access, the how else can we pay for the standard to be developed? …This is the model of the SDO.  Besides, a $100 is such low barrier”.  Agreed.  $100 is a low barrier, but if you look at some of the other SDO generated formats, namely HL7, you will find that the cost is much greater.

My argument is that the $100 really isn’t the point, but it is the lack of access, the lack of “eyeballs” that this situation causes acts as an impediment to health care transformation.  The fact that Jack, the computer science undergraduate, can’t just go download a copy and start building the next big Health 2.0 company should be a real source of concern.  I’d argue that the total openness of protocols such as HTTP, and TCP/IP is one of the key reasons why the Internet itself works and is generally interoperable.  In the words of Linus Trorvalds, “Given enough eyeballs, all bugs are shallow”. More formally “Given a large enough beta-test and co-developer base, almost every problem will be characterized quickly and the fix will be obvious to someone.”  Health care standards need to take the same approach.  It is my belief that a truly open, easy to access format would act as fertilizer in the garden of health transformation.  I’ve been following a thread  by @SusannahFox on talking about Open Access to Publicly funded works. Someone posted a TED talk there of, HTML inventor, Tim Berners Lee talking about the importance of openness in computer systems.  I thought I’d share because he shares my sentiments.

A Schema without a Home (URL)?

Not to get too geeky on my readers, but let us consider the relationship between an XML document at its schema definition (XSD).  A schema definition is used to validate the adherence to the format of an XML document.  As many of you already know it is normal XML/Web Service practice to give the schema itself, the XSD, a URL (web address).  This way all applications and services that rely on the format can have a central place to point to for correctness.

So the CCR standard schema (XSD) would have a URL (e.g.

If the XSD is published on the web, then CCR validation is open to all applications, developers, doctors and patients on the Internet.  This would allow to be the true, formal, point or reference for the standard…warding off one-offs and increasing its overall use and acceptance.  Wouldn’t this make it drop dead simple for anyone to determine if the output of HealthVault, Google Health, or other personal health record (PHR) is indeed compliant with the standard?  My friends this is the way XML and XSD was meant to be used.  Because of the lack of access, fees. we cripple the full power of the technology.  Even if we charged only $1, we still have the same access issues.

For illustration purposes, I’ve created a sample of what the CCR URL header (first few lines of XML in the XSD) would look like:


<?xml version=”1.0″ encoding=”UTF-8″?>
<xs:schema xmlns=”urn:astm-org:CCR
xmlns:xs=”” xmlns:ccr=”urn:astm-org:CCR
targetNamespace=”urn:astm-org:CCR” elementFormDefault=”qualified”
<!–E2369-05, Standard Specification for the Continuity of Care (CCR)
– Final Version 1.0 (V1.0) November 7, 2005,  ASTM E31.28 CCR
<!–Copyright 2004-2005 ASTM, 100 Barr Harbor Drive, West
Conshohocken, PA 19428-2959. All rights reserved.–>
<xs:element name=”ContinuityOfCareRecord”>


<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs=""
<!--E2369-05, Standard Specification for the Continuity of Care (CCR)
- Final Version 1.0 (V1.0) November 7, 2005,  ASTM E31.28 CCR
<!--Copyright 2004-2005 ASTM, 100 Barr Harbor Drive, West
Conshohocken, PA 19428-2959. All rights reserved.-->
<xs:element name="ContinuityOfCareRecord">

Should we Consider Fundamental Changes to the Role of the Standards Development Organizations?

Now there is nothing wrong with Standards Development Organizations.  Certainly they need a revenue source just like any other business. Membership fees and fees to access formats are one way to achieve this goal. The real question is, should the health care industry and the US government consider revising the role or at least the accessibility resulting standards?  There are a lot of taxpayer dollars going into the development of many of health care standards.  If it is information about me and my tax payer dollars are paying for the development, if only in part, then shouldn’t I have access to the format?  Sure most people don’t care.  But shouldn’t  someone who does care have the right to access the formats? Even if I wasn’t a computer scientist, I would still like the idea of the formats being open even if I never used it.  Just the fact of knowing it is open gives me, the consumer, a warm and fuzzy feeling.

Could the US government, namely HHS, the newly formed HIT Standards Committee, HITSP, and NIST find another way to support the SDO while ensuring all the resulting work product be open access for everyone?  I truly believe that standards development will accelerate with total openness.  We will only get to a state of interoperability when the standards themselves are in the public domain subject to the scrutiny of the collective open source community.  In the long run, this may bring down the cost of health IT systems and open up the market by bringing in even more vendors.  Depending on who you are, or who you work for, this could be a good or bad thing.  As American citizens however, we need to demand access to the formats and standards that your tax dollars help create.  Its your health.  Its your data.  Its your right.  Write your senators and congressmen!

So world, what do you think?  – Alan


How Videntity Addresses the New HIPAA Security Privacy Provisions in the ARRA (a.k.a. the Stimulus)

Videntity is an enterprise-level solution for HIPAA Compliance after the American Recovery and Reinvestment Act (ARRA) of 2009 (a.k.a. “The Stimulus”).

Videntity, an Internet-based application framework for building healthcare related communication applications, is a highly secure service based on a patent-pending identity verification and federation mechanism.  Videntity can automatically sequester information in a variety of ways; including phone, mobile phone, computer, or other devices.  The service includes an anti-vishing technology which performs a two-way challenge response over the telephone that enables Videntity to be easily accessible to everyone.

Videntity can be used to power many types of identity communication applications.  For example, the service can be used to build and power a home health monitoring application, thus reducing the need for in-home care visits.  In this case it “checks-in” on individuals with chronic conditions and obtains health information on an ongoing, real-time basis.  Similarly, Videntity can be used to obtain explicit patient authorization for a transaction.  Videntity is a tool that was designed from the ground up to help solve many common security, privacy, and communication healthcare conundrums.  Videntity also eloquently addresses many of the new security provisions spelled out in the American Recovery and Reinvestment Act (ARRA) of 2009 (a.k.a. “The Stimulus”).

The American Recovery and Reinvestment Act of 2009 (ARRA), sometimes referred to as “the stimulus,” includes provisions which make significant improvements in the privacy and security standards for health information.  The provisions concerning privacy and security are primarily found in ARRA’s Title XIII, Subtitle D and some parts of Subtitle A. Many of the changes, which go into effect Feb 17, 2010, can be grouped into four broad categories 1:

  • Substantive changes to HIPAA statute and privacy and security regulations
  • Changes in HIPAA enforcement
  • Provisions to address health information held by entities not covered by HIPAA (as either covered entities or business associates)
  • Miscellaneous:  Administration/Studies/Reports/Educational Initiatives

In the following sections, we briefly describe some of the new ARRA regulations and how Videntity addresss these new requirements.

Changes in HIPAA Enforcement – ARRA causes HIPAA to “grow teeth” and shift from guidance to enforcement.  ARRA states that a covered entity’s “Business Associates” are directly accountable for HIPAA.  Sections 13401 and 13404 of ARRA state that business associates can be held accountable by federal and state authorities for failure to comply with any applicable provisions of the HIPAA Privacy and Security Rules 2.

Under current regulations, government authorities cannot hold business associates accountable for failing to comply with their business associate agreements. Covered entities can only be held liable for the actions of their business associates in limited circumstances.

Section 13409 of ARRA clarifies that HIPAA’s criminal penalties can be enforced against individuals, including (but not limited to) employees of a covered entity.  This overrules a Department of Justice Office of Legal Counsel memo issued during the Bush Administration that states that only covered entities can be criminally prosecuted for violations of HIPAA.  In addition, the wording of the provision may broaden the scope of activities for which criminal penalties can be attached because authorities can prosecute an individual who obtains or discloses individually identifiable health information without authorization. 3

Section 13410(a) of ARRA clarifies that HHS and state attorneys-general can pursue a civil HIPAA violation in cases where criminal penalties could attach but the Department of Justice declines to pursue the case.  Section 13407 of ARRA establishes breach notification requirements for vendors of personal health records and other non-HIPAA covered entities. 4

– Currently, healthcare providers have to create a log of exchange between physicians, payers, ect.  Prevoiusly, disclosures between these entities were exempt from reporting but ARRA creates a legal mandate for all entities covered by HIPAA to keep accurate audit trails of personal health information.  Providers, payers, and other HIPAA covered entities are required to provide patients with a list of all of their personal health information disclosures made within the previous three years.  Section 13405(a) of ARRA requires covered entities (and their business associates) to honor an individual’s request to restrict disclosure of protected health information to a health plan for purposes of payment or healthcare operations if the information pertains solely to a healthcare item or service that the individual has paid for in full out-of-pocket. 5

Videntity creates a framework for secure exchange between:

  • Provider to Provider
  • Provider to Payer
  • Provider to Patient
  • Provider to Patient’s Guardian (spouse, parent, caregiver, etc)
  • Patient to Guardian (spouse, parent, caregiver, etc)

Videntity not only provides multiple means for verifying an individual’s identity, but also automates transaction authorization over the phone.  This is especially important for users unaccustomed to using the web and/ or mobile device technology.  Each transaction requires the sender’s authorization (digital signature), the subject signoff (transaction authorization) and/or the receiver’s signoff (deliverary signature).

Within Videntity, after a relationship is established between two or more parties, subsequent ID verification and authorization isn’t required.  The social graph acts as an access control list and transactions can occur implicitly as long as both parties agree.  In all cases, transactions are recorded with a complete audit trail.  Files containing personal health information can also be attached to each transaction.  Additionally, paper-based personal health information can be verified, authorized, sent, and delivered via Videntity using the Videntity Fax Service.


Individual Right of Electronic Access – Under the existing HIPAA Privacy Rule individuals have always had a right to access and obtain a copy of their health records (in the form or format requested)  if it is readily producible in such form or format, within 30 days of the request in most circumstances.  The covered entity may impose a reasonable fee for such access or copy.  Any limits on such charges are usually governed by state law. 6

Under Section 13405(e) of ARRA, covered entities using electronic health records must provide individuals with an electronic copy of their record, which must be transmitted directly to an entity or person specified by the individual, as long as that directive is clear, conspicuous and specific.  Any fee charged for the record cannot be greater than the entity’s labor costs in responding to the request.  The ARRA provisions do not change the timeframe for responding to requests for copies of records. 7

Videntity streamlines communication and information exchange between the patient, their doctor, and all those involved in the patient’s health portrait.  As a development platform, Videntity supports many communication modes including telephone, mobile phone, Internet appliance, desktop, kiosk, fax, and web applications.

Breach Notification – ARRA Section 13402 requires that covered entities provide notification to individuals if their health information has been breached (business associates are required to notify covered entities of any breaches; the covered entity must then notify the individual per the requirements).

Videntity can not only be used as a framework for breach notification, but can also help prevent information breaches from occuring.  By employing multiple verification modes, strong encryption, and providing a social access control list, Videntity provides a secure framework for information exchange.  Regardless of the source of the breach, Videntity can be used to automatically notify an individual, or individuals, and immediate corrective action can then be taken.

Summary – Videntity provides systematic cost-saving measures across the enterprise.  Videntity also streamlines communication and increases information flow while decreasing liability exposure related to HIPAA and ARRA.

1-7 Center for Democracy and Technology. “Summary of Health Privacy Provisions in the 2009 Stimulus Provisions.” Center for Democracy and Technology. 24 March 2009.  <>

Download the pdf here: Videntity_4_HIPAA_ARRA_Stimulus


Simple Python Class Library and Command Line Utility for S3 Storage and Retrieval

Hello.  This is based on the Python Boto library.  I created a class with a couple functions for storing and retrieving information (either publicly or privately) on Amazon S3.  I added sufficient error handling to allow this code to be used in a production environment. Improvements and suggestions are always welcome.  It also doubles as a command line utility for simply upload and and download files.  I love that feature about Python.  I wrote this so I could be DRY.  I hope it helps you get your head in the cloud. Enjoy!

#!/usr/bin/env python
# By: Alan Viars
# Copyright Videntity Systems, Inc. 2009
# All rights Reseved.
# License: New BSD
# Last Updated: May 9, 2009
# This was tested using Python 2.5 and Ubuntu Linux, but
# it should run fine w/ other configurations.
# You will need to install boto to get this library running
# and of  course you need an S3 account from Amazon.
# See
# 1.7.a is latestversion of boto at the time of writing.
# Execute the following from a command line prompt
# > wget
# > tar zxvf boto-1.7a.tar.gz
# > cd boto-1.7a
# Run this as root or w/ admin privileges
# > python install
# > if on Ubuntu or Debian deravitive, use sudo like so:
# > sudo python install


import sys
from boto.s3.connection import S3Connection
from boto.s3.key import Key
import mimetypes

#Set these to match your Amazon S3 Account

class SimpleS3:
    A very simple class library to simple store
    and  retieve files in Amazon S3
    Works with HTTPS/port 443 only (no HTTP/port 80)

    #Store a file in s3
    def store_in_s3 (bucket, filename,

            """Store a file in s3"""
                conn= S3Connection(AWS_ACCESS_KEY,
                b = conn.create_bucket(bucket)

                mime = mimetypes.guess_type(filename)[0]

                if mime==None:
                    print "I couldn't guess MIME because"
                    print "I couldn't detect a file ext."
                    print "Using 'application/octet-stream'"
                    print "as the default MIME instead."
                    mime = "application/octet-stream"

                print "MIME Type = %s" % (mime)
                k.set_metadata("Content-Type", mime)
                if public==True:
                url = "" % (bucket,
                print "Error in store_in_s3."
                print sys.exc_info()
                return url
                return url

    #Get a file from s3
    def get_from_s3 (bucket, filename, local_filepath ):
            """Get a file from s3"""
            retval = False
                conn= S3Connection(AWS_ACCESS_KEY,

                b = conn.create_bucket(bucket)
                k = Key(b)
                k.key = filename
                retval = True
                print "Error in get_from_s3"
                print sys.exc_info()
                return retval
                return retval

    # Our MAIN application which takes 3 command line arguments
    # Take in a mode, bucketname, filename, and public T/F.
    # if mode=PUT, then store the file in S3
    # If mode=GET, then read the file from S3,
    # and write it to local disk

    if __name__ == "__main__":


            if sys.argv[1]=='PUT':
            elif sys.argv[1]=='GET':

            if sys.argv[5] in ('t', 'T','True','true','TRUE',):

            if mode=='PUT':
                print """Saving %s file to S3 bucket %s.
                Public = %s""" % (sys.argv[3],sys.argv[2],public )

                url = store_in_s3 (sys.argv[2],

                if url != "":
                    print "File saved in S3.  URL is %s" % (url)
                    print "Error in store_in_s3.  No URL returned."

            elif mode=='GET':
                print "Reading %s from S3 and saving it to to %s" 
                    %(sys.argv[3], sys.argv[4])

                #get the file from S3
                retval = get_from_s3 (sys.argv[2],
                                      sys.argv[4] )

                if retval==True:
                    print "File %s saved locally." % (sys.argv[3])
                    print "Error getting file from S3 and saving 
                print "Invalid mode.  Pleas specify PUT or GET."

        except IndexError:
            print "Please supply all parameters in the form:"
            print " <GET/PUT> <bucketname> <key> 
            <local_filename> <Public? T/F>"
            print "Example:"
            print " PUT mybucket my_key my_local_filename T"
            exit (1)

            print "Misc. Error. See below."
            print sys.exc_info()
            exit (1)

Download it here :


A Few Handy Resources for Entrepreneurs

Here are several links we discussed at the Canton ETC event. I hope these may be useful to fellow entrepreneurs going through “the struggle”, “the fire”, “the dip” or other term.

Thank you Fulya for organizing.


Removing Asterisk on Ubuntu 6,8

This little recipe works for me if you’re not using any special hardware.

Run these commands as root or use sudo. This will work for Asterisk 1.4 and 1.6.

sudo killall -9 safe_asterisk
sudo killall -9 asterisk
sudo rm -rf /var/log/asterisk
sudo rm -rf /var/lib/asterisk
sudo rm -rf /var/spool/asterisk
sudo rm -rf /usr/lib/asterisk
sudo rm -rf /etc/asterisk
sudo rm /usr/sbin/asterisk
sudo rm /usr/sbin/safe_asterisk

Now you should be clean and ready to reinstall if needed.


Installing MySQL for Python on Mac OS X (MySQLdb)

I was having issues setting up MySQL Python when I was setting up a Django development environment on Mac OS X. This works fine on Ubuntu and Windows Machines, but it appears installing Python’s MySQL (MySQLdb) can be difficult on Mac OS.  See this post,175059,179979

It tried the following compilation but it ran with some errors:

Anyhow a bunch of people have had problems with this.  Here is what I did to get it to work nice and easy:

Download this file. mysql_python-122-py25-macosx-105-i386.egg Install this egg file to file: to /Library/Python/2.5/site-packages/. So open up a terminal shell and do something like:

sudo cp mysql_python-122-py25-macosx-105-i386.egg /Library/Python/2.5/site-packages/

Now create and edit a text file here /Library/Python/2.5/site-packages/myeggs.pth:

sudo nano /Library/Python/2.5/site-packages/myeggs.pth

Now put the full path to the egg in the file:


Save the file:

Save changes? Y

That’s it. All should be working. Compiling Python_MySql from scratch should not be necessary. If you are using Django, you can test this with:

python syncdb

You can also test it just using Python by:

>>> import MySQLdb

If you see no error, then the library is present. If you see “ImportError: No module named MySQLdb”, then something has gone wrong.

Change the above based on your local settings. Happy coding.



How to create a MySQL database and users from the command line

Create the database with the mysqladmin tool.
Don’t forget sure and add the bin folder to your path if you are on Windows or Mac!  Not necessary on Linux.
For example, on my Windows box it is C:Program FilesMySQLMySQL Server 5.1bin

mysqladmin --user=root --pass=some_pass create local_db

(replace “some_pass” with your mysql root password.)

now login to my sql as root..
mysql --user=root --pass=some_pass

now change to the new db…

mysql>use  local_db;
Database changed.

create the user(s) and grant rights ….this allows the user monty to access the database locally and remotely.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
    ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
    ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;