Converting Numbers to Words

April 16th, 2012

I wrote this function many years ago for a check-printing program.  It originally was in 360 Assembly Language, but here it is in Java:

/**
* Convert a long integer to words.
*
* @author Glen F. Marshall
* @version 3.0
*/
public class NumWord {

private final static NumWordString Units[] = {NumWordString.NULL, NumWordString.ONE, NumWordString.TWO,
NumWordString.THREE, NumWordString.FOUR, NumWordString.FIVE, NumWordString.SIX, NumWordString.SEVEN,
NumWordString.EIGHT, NumWordString.NINE, NumWordString.TEN, NumWordString.ELEVEN,
NumWordString.TWELVE, NumWordString.THIRTEEN, NumWordString.FOURTEEN, NumWordString.FIFTEEN,
NumWordString.SIXTEEN, NumWordString.SEVENTEEN, NumWordString.EIGHTEEN, NumWordString.NINETEEN};

private final static NumWordString Tens[] = {NumWordString.NULL, NumWordString.NULL,
NumWordString.TWENTY, NumWordString.THIRTY, NumWordString.FORTY, NumWordString.FIFTY,
NumWordString.SIXTY, NumWordString.SEVENTY, NumWordString.EIGHTY, NumWordString.NINETY};

/**
* Convert input number to its word-string equivalent
*
* @param n
*            Input number (long integer)
* @return Word-string for number
*/
public static String toString(long n) {
StringBuilder R = new StringBuilder();
R.setLength(0);
int i;

/**
* Depending of the input value, construct an output string in R
*/
if (n < 0) {
R.append(NumWordString.MINUS.toString() + ” ” + NumWord.toString(-n));
} else if (n < 20) {
return (Units[(int) n].toString());
} else if (n < 100) {
R.append(Tens[(int) n / 10].toString()
+ ” ” + NumWord.toString(n % 10));
} else if (n < 1000) {
R.append(NumWord.toString(n / 100)
+ ” ” + NumWordString.HUNDRED.toString()
+ ” ” + NumWord.toString(n % 100));
} else if (n < 1000000) {
R.append(NumWord.toString(n / 1000)
+ ” ” + NumWordString.THOUSAND.toString()
+ ” ” + NumWord.toString(n % 1000));
} else if (n < 1000000000) {
R.append(NumWord.toString(n / 1000000)
+ ” ” + NumWordString.MILLION.toString()
+ ” ” + NumWord.toString(n % 1000000));
} else if (n < 1000000000000L) {
R.append(NumWord.toString(n / 1000000000)
+ ” ” + NumWordString.BILLION.toString()
+ ” ” + NumWord.toString(n % 1000000000));
} else if (n < 1000000000000000L) {
R.append(NumWord.toString(n / 1000000000000L)
+ ” ” + NumWordString.TRILLION.toString()
+ ” ” + NumWord.toString(n % 1000000000000L));
} else if (n < 1000000000000000000L) {
R.append(NumWord.toString(n / 1000000000000000L)
+ ” ” + NumWordString.QUADRILLION.toString()
+ ” ” + NumWord.toString(n % 1000000000000000L));
} else {
R.append(NumWord.toString(n / 1000000000000000000L)
+ ” ” + NumWordString.QUINTILLION.toString()
+ ” ” + NumWord.toString(n % 1000000000000000000L));
}

/**
* Strip any embedded double spaces
*/
while ((i = R.indexOf(“  “)) >= 0) {
R.deleteCharAt(i);
}

/**
* Strip any trailing space
*/
if (R.charAt(i = R.length() – 1) == ‘ ‘) {
R.deleteCharAt(i);
}

return R.toString();
}

And the enumeration…

public enum NumWordString {
MINUS(“minus”),
NULL(“”),
ONE(“One”),
TWO(“Two”),
THREE(“Three”),
FOUR(“Four”),
FIVE(“Five”),
SIX(“Six”),
SEVEN(“Seven”),
EIGHT(“Eight”),
NINE(“Nine”),
TEN(“Ten”),
ELEVEN(“Eleven”),
TWELVE(“Twelve”),
THIRTEEN(“Thirteen”),
FOURTEEN(“Fourteen”),
FIFTEEN(“Fifteen”),
SIXTEEN(“Sixteen”),
SEVENTEEN(“Seventeen”),
EIGHTEEN(“Eighteen”),
NINETEEN(“Nineteen”),
TWENTY(“Twenty”),
THIRTY(“Thirty”),
FORTY(“Forty”),
FIFTY(“Fifty”),
SIXTY(“Sixty”),
SEVENTY(“Seventy”),
EIGHTY(“Eighty”),
NINETY(“Ninety”),
HUNDRED(“Hundred”),
THOUSAND(“Thousand”),
MILLION(“Million”),
BILLION(“Billion”),
TRILLION(“Trillion”),
QUADRILLION(“Quadrillion”),
QUINTILLION(“Quintillion”);

private String word;

/**
* @param algorithmName
*/
NumWordString(String word){
this.word = word;
}

/* (non-Javadoc)
* @see java.lang.Enum#toString()
*/
public String toString(){
return word;
}

}

Pondering Health Care Data Availability

April 10th, 2012

In the past few days I’ve noticed a spike in the number of blog posts, announcements, and commentary on health care data security.  The focus is on identity management, data access controls, and accountability.

This is disturbing.  I’ll make an educated guess that more harm is done to health care consumers due to lack of data, delays in getting data, failure to heed available data, and incorrect data.  In some cases it is a failure to communicate — in a timely manner, or at all — among health care providers.  In other cases it is a failure to communicate with the health care consumers, who then lack the information necessary to make good decisions about their own health and how to maintain or improve it.

The issue of communication among providers is well-trodden ground.  Interoperability among health information systems is an urgent need that, in my opinion, has been delayed due to re-thinking and re-invention more than a lack of mutual will or delays in needed standards.  Patients’ well-being is being sacrificed on the altar of perfection, when “good enough” is in-hand.

Lets personalize this: You and your family are being harmed.

There is a solution, though.  Get your own data, understand it, and make sure it is communicated among all of your health care providers.  Do the same for your family.  If a health care provider will not readily provide your data in a form that you can use, get in their face and demand it.  Read it.  Make sure you understand it.  Note corrections where you find errors, as you will probably find some.  Ask questions.  Look on-line, as there is plenty of information.  I urge caution, though, because there are plenty of mis-informed people who provide their mis-information on-line.  Above all, do not let those who are standing in the way of good enough health data sharing do you any more harm.

My Journey To Being An Engaged Patient

March 25th, 2012

When I was young and curious about my own body, I was blessed by having a grandfather who was a physician.   All of my questions were answered, and there was nothing that was off-limits.  He hauled-out Grays Anatomy and helped me understand the drawings.  I also avidly browsed it then came to read, as I got older, his copies of the New England Journal of Medicine.

I particularly remember a time when he was doing some post-retirement consulting on occupational trauma.  He had x-rays of the injuries and, because I was curious, he taught me how to read them.  (Nowadays I get a lot of enjoyment out of AuntMinnie.com.)

By my teens, I had a fairly accurate understanding of what human bodies contained, what the various parts did and where they were, and what “normal” and “abnormal” was.  My vocabulary included medical terminology.  Reading news and science magazine articles, as life science and medicine advanced, was easy.

While I never had much interest in becoming a physician, my career naturally gravitated to health care.  In particular, my burgeoning interest in information technology found it to be fertile ground.

At first my focus was on computers, programming, and computer science.  Gradually, though, I become intensely committed to end-results: improving the business of health care and the delivery of care to patients.  For a long time it was in that order: business first, care second.

An epiphany came when I finally realized that the business of health care was actually in the way of delivering care.  We can only improve the business if we first improve the outcomes and efficiency of care.  And outcomes are driven by each patients’ personal commitment — responsibility, accountability, and actions for one’s own wellness plus enrolling one’s care providers in that commitment.  That starts with my own commitment.

Another epiphany came when family members had illnesses.  They lacked a base of knowledge about their bodies and what was wrong.  Their experience of disease was remarkably different than mine, especially more fearful.  They tended to avoid doctors, rely on old wives tales and unproven folk remedies, and seek the comforts that alternative medicine practitioners were eager to provide.  The results were unfortunate, over time.  It was when I realized that all this was enabled by a lack of understanding, and that available information was hard to understand, that I “got it”.  My own upbringing, experiences, and understandings were fairly unusual.

I am now at a point in my life where I may be able to help close the commitment and the knowledge gap.  It’s something about which I can be passionate and engaged.  That’s the start of a journey, not the end of it.

Definition: Engaged Patient

March 22nd, 2012

posted for my future reference

A Gallup Poll article states “Gallup’s extensive research has identified the crucial characteristics of the emotional connections between healthcare providers and their best patients. These patients are not just ‘satisfied’ or ‘loyal,’ they are emotionally attached to the provider’s brands or services. They are engaged.”

I find that definition profoundly dissatisfying. It presumes a one-way emotional attachment that is somehow a product of a provider’s behaviors that consistently meet or exceed customer expectations. That’s like a Pavlovian response.

My own definition may leave others cold, but here it is: An engaged patient takes fully committed responsibility, and accepts accountability, for his own wellness and acts consistently with that commitment. On the other hand, an engaged care provider is fully enrolled in the patient’s commitment and willingly shares responsibility and accountability, acting consistently with it. Commitment is evidenced by clearly communicated and understood expectations, roles, deliverables, methods, and timeframes.

This is congruent with a more lengthy definition on the Society for Participatory Medicine web page.

Coffee

March 16th, 2012

When I want a cup of coffee, that’s all I want. Coffee, with a touch of milk or cream. That’s it.

This is not to say that others’ tastes are wrong or inferior. Mine are just simple. I am easy to please, and I am easy to displease.

Now, there are some of my opinions to share. The first is about flavored coffees. For example, there are nut, spice, or fruit flavored coffees. In my opinion the added flavors mask what are otherwise undistinguished beans. You will never see amaretto-flavored Jamaica Blue Mountain. But add the same flavor to mediocre beans and you can charge about the same per pound as Seattle’s finest.

I also have a low opinion of any brewing that adds a ton of dairy products, and unjustifiable cost, to a few ounces of good coffee. Let’s make an exception for cappuccino which, when properly made, adds a modest amount of milk foam to a cup of strong espresso. But don’t ruin it with a dusting of cocoa or cinnamon, OK?

Then there are adjuncts. People will add just about anything to coffee. It started-out with chicory and chocolate, neither of which improve coffee while adding their own flavor-note. I have seen herbs, mushrooms, vitamins and minerals, even bacon. No, thank you.

Another no-no is what happens when you remove the caffeine, which also removes the flavor. So decaffeinated coffee needs to have coffee flavor added back. It is an artificially-flavored product. And it is NOT as good as coffee in which the flavor is intact.

That’s the bottom-line: flavor. I’d like coffee, please

The Most Important Health IT Meta-Trend

March 7th, 2012

With the advent of Meaningful Use 2, Health IT pundits are now saying what future electronic health records (EHR) systems must, should, might, or would be well-advised to have. It’s all very repetitive and not very innovative. US Federal government proposed regulations are not known for disruptive proposals. This is especially true in a heated election year. There’s no excitement there, except for the few fringe issue advocates who are looking to be offended by whatever the government proposes.

But, taking a step back and looking at the Health IT trade press, blogs, and tweets, I’m seeing an essential meta-trend. Technology and user interfaces that are ubiquitous and highly-desired in general consumer computing are now a part of the required Health IT fabric. People want their Health IT to be as intuitively easy to use as iPhone and iPad apps, social media, and e-commerce. This is not just for health consumers, but also providers. The various electronic assists that we now use for other aspects of our daily lives need to be the same for health care. And there must be no unsettling boundaries to cross between what is Health IT and what is not.

Similarly, the privacy we desire in our financial transactions should be mirrored in health applications. This is what makes consumer privacy protecting laws and regulations so important: they need to apply across all aspects of our lives. And it parallels the business privacy laws and regulations that protect intellectual property and proprietary data.

What amazes me is how Health IT folks keep thinking they are so special, and keep treating health care as if it is distinct from all other aspects of our lives with some sort of bright line between them. That is simply wrong. For example, healthcare considerations pervade my exercise regime, grocery shopping, alcoholic beverage choices, vacation plans, some clothing, entertainment, driving habits, insurance, finances, etc. Why should I have to accommodate others’ views of what belongs in which categories? And who is to say that my perceptions and the way I conduct my affairs should be the same as my neighbors?

This is not new. But now that some 50% of people have smart phones and other Internet-connected capabilities, it is something that cannot be ignored any longer.

Drama

March 2nd, 2012

Drama is often like junk mail addressed to “occupant”. You can choose to open it or discard it unopened.

The same is true of other forms of human negativity. It is often not meant personally. Taking it personally is an avoidable mistake.

I avoid opening the junk mail. Sometimes I get careless, and that’s when drama comes into my life.

Humor and humility are great tools for getting rid of it.

That Misogynistic Birth Control Debate

February 10th, 2012

Notice that the debate centers on women having control of their reproductive life. It does not mention vasectomies, ED drugs, male hormone treatments, or condoms. It also does not mention non-contraceptive use of birth-control pills to ease dysmenorrhea.

Basically, it’s a bunch of political ass-hats trying to please a bunch of old men who are under a vow of celibacy. Fuck ‘em all.

Thoughts on Sports

January 29th, 2012

When I was a kid my grandfather took me to baseball and football games. Those experiences color my current thoughts on sports.

Baseball was at Fenway Park, a classic stadium. Football was at Harvard University stadium, also classic. Baseball was hot in the summer. Football was damn cold, since the stadium’s U-shape seemed to funnel-in the November wind. So we had paper fans to provide some breeze in the summer, and we always sat in the shade of 3rd base line side stands rather than the outfield bleachers. And for football we had blankets — actually old car blankets from the pre-heater Model-T era — to keep warm. In both venues, box seats were simply closer to the field. Today’s sports palaces coddle the audience. And, yes, “audience” seems more appropriate than “fans” for today’s sports.

As I recall, the cost to go to the games was reasonable. Nowadays its costs well over $200 to take a family to a game, with food, and season tickets are more an investment than an out-of-pocket expense. You cannot afford to be a fan any more – except maybe in a bar or your living room.

Basically, the sports I remember no longer exist. And I’m not a fan.

My Occasional Annual Rant

January 16th, 2012

I hate Federal-only holidays — ones where just about everyone, except government employees, has to work anyhow while not getting the normal array of mail, banking services, and the opportunity to buy wine or liquor in my home state.  What I resent even more is that government employees get paid for this time off.  I would resent it less if, for example, they donated their time to an activity that is appropriate for the holiday.

The holidays and my proposed activities include:

  • Martin Luther King’s Birthday – Help register voters.  Get at least one person a permanent full-time job, with benefits.  Purposely violate some unjust laws, risking your own comfort.
  • President’s Day – Go to elementary schools and teach the kids something important and useful about American History or current events. 
  • Columbus Day – The Bureau of Indian Affairs and the Indian Health Service need to organize some meaningful day-of-service activities for all government employees.
  • Veterans Day – Get on the phone and individually thank a whole lot of veterans for their service.