jherskovic / MedRec

Medication Reconciliation algorithm
27 stars 19 forks source link

do med lists require instructions to be included? #5

Open scheid opened 10 years ago

scheid commented 10 years ago

I have been attempting to run the reconciliation with a test list that I created myself (using med name strings from RxTerms).

I noticed that if I omit the instructions part of a med, the script throws an error. Is this by design, or should the algorithm be able to function if supplied only with a med name?

Here is the stack trace of the error thrown:

Traceback (most recent call last): File "C:\inetpub\wwwroot\medrec-master\reconcile-service.py", line 417, in main() File "C:\inetpub\wwwroot\medrec-master\reconcile-service.py", line 364, in main print output_json(demo_list_1, demo_list_2, l1, l2, rec) File "C:\inetpub\wwwroot\medrec-master\json_output.py", line 20, in output_json 'new_list_1': [x.as_dictionary() for x in l1], AttributeError: 'Medication' object has no attribute 'as_dictionary'

And, here is an example of a list that the reconcile.py script failed on:

  topiramate 200 MG Oral Tablet [Topamax]
  lamotrigine 150 MG Oral Tablet [Lamictal]
  Cyclobenzaprine hydrochloride 5 MG Oral Tablet [Flexeril]
  ******
  topiramate 25 MG Oral Capsule [Topamax]
  lamotrigine 150 MG Oral Tablet [Lamictal]
  Cyclobenzaprine hydrochloride 10 MG Oral Tablet [Flexeril]
  24 HR Metformin hydrochloride 1000 MG / saxagliptin 2.5 MG Extended Release Tablet
  ******

However, when I simply append on instructions, the algorithm succeeds:

  topiramate 200 MG Oral Tablet [Topamax];TAKE AS DIRECTED.; Rx
  lamotrigine 150 MG Oral Tablet [Lamictal];TAKE AS DIRECTED.; Rx
  Cyclobenzaprine hydrochloride 5 MG Oral Tablet [Flexeril];TAKE AS DIRECTED.; Rx
  ******
  topiramate 25 MG Oral Capsule [Topamax];TAKE AS DIRECTED.; Rx
  lamotrigine 150 MG Oral Tablet [Lamictal];TAKE AS DIRECTED.; Rx
  Cyclobenzaprine hydrochloride 10 MG Oral Tablet [Flexeril];TAKE AS DIRECTED.; Rx
  24 HR Metformin hydrochloride 1000 MG / saxagliptin 2.5 MG Extended Release Tablet;TAKE AS DIRECTED.; Rx
  ******
jherskovic commented 10 years ago

This is as much a philosophical as a technical issue. Can we match just on the drug? Yes, we could. The modifications are pretty easy. If this is something you need, we can do it for you.

Technically, the algorithm expects an instructions field. It can be empty. The idea always was to feed structured, or semi-structured, data into this program. The text parser on this program is fairly minimal, not much more than a demo that knows how to handle some of our own in-house text, which happened to be in that format. There should be much better medication parsers out there.

scheid commented 10 years ago

Thanks for the reply. I certainly think you have done an excellent job on this algorithm, I was just wondering if you had guidance on the best way to format the med strings. I read your Silva et al. (2011) article ( http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3243161/ ), which helps tremendously.

I was hoping to see the raw med lists that were submitted to the algorithm in an appendix; that could help to glean a generally successful formatting. I suppose I can look in the constants.py file to generally see what will be picked up by the algorithm outside of rxnorm.

Part of the problem I'm seeing I'm sure is that for your experiment, you extracted the meds from a clinical note sample, whereas I'm using med strings from RxTerms (http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2655997/; using the 'full name' field value for the reconciliation algorithm), and I'm sure there are differences in formatting, abbreviations, etc..

On another note, if you are interested, I have modified the reconcile.py script so that it will accept a json payload as opposed to the current text format, and have also created a PHP script to interface with the reconcile script and expose the data as a web service. The PHP script accepts a json payload of the lists from a web client and passes that over to the reconcile.py script for processing. The reconcile.py file returns its json result data back to the PHP script, which passes the results back down to the web client. This allows the reconciliation algorithm to be exposed as a dynamic web service, which I've plugged into the Twinlist UI. Nothing terribly groundbreaking, I know, but I'd be happy to share this (once I get it a bit more cleaned up). I also might incporporate a list ID and descriptive name for each of the lists to be passed through from the input to the output by the algorithm; that would help in apps like the twin list to have custom named lists. And now that the modified reconcile.py can accept json, it should be easy to add data fields to the incoming lists.

Thanks again.

On Tue, Oct 8, 2013 at 9:22 AM, jherskovic notifications@github.com wrote:

This is as much a philosophical as a technical issue. Can we match just on the drug? Yes, we could. The modifications are pretty easy. If this is something you need, we can do it for you.

Technically, the algorithm expects an instructions field. It can be empty. The idea always was to feed structured, or semi-structured, data into this program. The text parser on this program is fairly minimal, not much more than a demo that knows how to handle some of our own in-house text, which happened to be in that format. There should be much better medication parsers out there.

— Reply to this email directly or view it on GitHubhttps://github.com/jherskovic/MedRec/issues/5#issuecomment-25888894 .

jherskovic commented 10 years ago

The demo_list_1 and _2 variables in constants.py were taken straight from our clinical notes, and show the most popular format. It was pretty simple. I've highlighted the parser in this Gist: https://gist.github.com/jherskovic/6991929#file-medication_parser-py

The translation is something like [NAME] [DOSE] [UNITS] [mg/mcg/ml/etc] [FORMULATION]; [INSTRUCTIONS]

However, if you have a structured feed, you could create ParsedMedication objects directly (see medication.py). The easiest way is to use the make_medication factory function in medication.py. Pass it a dictionary with following keys:

and you'll have the correct object format. The reconciliation functions expect Python lists of ParsedMedications. Once you build the lists, you can use reconcile_parsed_lists (in reconcile.py) to perform the bulk of the reconciliation work.

reconcile_parsed_lists expects two lists of ParsedMedication objects and a MappingContext. MappingContext describes the "environment" in which the reconciliation happens: a specific version of RxNorm and, if available, the "treatment sets", i.e. the treatment->condition mappings used to make educated guesses about drug uses.