Genrating letters which include data

LabKey Support Forum
Genrating letters which include data anders kielland  2015-01-27 08:49
Status: Closed
 
hi
I am low on understanding when it comes to Labkey and databases in general.

I am trying out Labkey for a clinical study. One task is: the patients after being to a visit want to have some of the measurement on them. We give them a letter with some key parameters. It becomes a lot of copy and paste.

Wonder if a letter like this can be automatically generated in Labkey, fex from the Customize Participant View (https://www.labkey.org/wiki/home/Documentation/page.view?name=participantViews)?

or in other ways?

Anders
 
 
Jon (LabKey DevOps) responded:  2015-01-27 15:24
Hi Anders,

Can you give us some more details as to what you're needing here?

You could use our Javascript API to extract values from the Participant table and then populate that into the UI under the Customize Participant View, but are you looking for the platform to have pre-populated text with the values you want to have displayed to where you can then copy/paste the information or were you looking to have it do something else? What specific information are you trying to pass onto your patients via a letter?

Regards,

Jon
 
anders kielland responded:  2015-01-28 00:06
Hi Jon
Thank you for the answer. I can see that my question was not well phrased. I am sorry about that.

When a particular patient have been to the clinic he often wants date with him home. Like blood values, weight, blood pressure... etc.

I could generate a standard "participant report" with relevant measures, but if I print out that the cohort and group (treatment group) is also included which are information they should not have. It would also be nice to add an standard extra text to the print out (presumably what you mean by "pre-populated text").

Basically some thing that is easy and fast to use for the clinician.

Hope this was more understandable, Anders
 
Jon (LabKey DevOps) responded:  2015-01-28 17:27
Anders,

Thanks for the clarification. There's a few different ways to approach this, but it is possible to do what you want via Javascript.

I'm tinkering around with some javascript code at the moment, but my personal idea is where you would setup wiki page where you have your standard extra text and have that page embed the participant report information within it using the selectRows query (https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.Query.html#.selectRows) and from the Customize Participant View, have a link that will point to that wiki page and pass along the participant ID.

The Participant ID number would get passed into the wiki page and the selectRows query would extract only specific values you want from the participant and populate the letter for your clinician to use.

Does that make sense?

Regards,

Jon
 
anders kielland responded:  2015-01-29 12:42
Yes that sounds good.

I cannot do that my self, but s long as there exists and sensible solution I am satisfied.

Regards, Anders
 
Jon (LabKey DevOps) responded:  2015-02-02 17:43
Anders,

Just an FYI, I am in the final phase of my custom solution and I'm just working out the final pieces. I'll give you an update tomorrow with full instructions.

Regards,

Jon
 
anders kielland responded:  2015-02-02 22:14
Seriously
That was very exiting to hear:D

Thank you very much, Anders
 
Jon (LabKey DevOps) responded:  2015-02-03 16:51
Anders,

I understand that Elizabeth and Kevin were discussing the option of having you use knitr for the letter, which is a good idea. But here is my solution via Javascript. Although I'm sure there are other more optimal ways of coding this, the idea is still pretty good to use.

The structure is setup in two parts:

1. The customize participant view that will have javascript code to obtain the participantId from the URL.
2. The wiki page that will then take that participantId, perform a query using the Javascript API against that participantId, then populate the values in the wiki as a letter.

To use the code, the following needs to be done before you begin:

1. You will need to know what dataset you want to pull information from. In my example, I added additional fields to my Demographics dataset (First Name, Last Name, etc) and updated a few of my records to have actual values there.
2. You will need to create a wiki page for the letter.

Once you have taken care of those two pre-requisites, you can use the attached javascript code examples and customize them as you need to.

In my example, this is what the code does:

1. I access my participant record and the javascript code within the Customized Participant View adds a link that points to a wiki I made earlier and pushes that participant ID into it:

Screenshot - http://awesomescreenshot.com/0a64bz3x45

The URL that the link points to looks like this: http://localhost:8080/labkey/wiki/home/Demo%20Study/page.view?name=Letter&participantId=125478&_print=1

2. The wiki page then obtains the participant ID and uses it in the Javascript API as a filter for its query.

3. I allowed the wiki page to first show me the results of the query (the instructions on how to do this is explained in the code), which looked like this:

125478 ARV urn:lsid:labkey.com:Study.Data-25:5001.125478 2008/04/28 00:00:00 74 123 Main St 98125 WA John Seattle m Smith

4. So the query provided extra data that I didn't need, so I then made the wiki page show me the results again using another format (also explained in the code), which renders like this:

This is 125478
This is ARV
This is urn:lsid:labkey.com:Study.Data-25:5001.125478
This is 2008/04/28
This is 00:00:00
This is 74
This is 123
This is Main
This is St
This is 98125
This is WA
This is John
This is Seattle
This is m
This is Smith

This then lets me see what values I have to use for my actual letter.

5. I then format the HTML code for the letter and then let the wiki page render one final time, which gives me a printable screen:

Screenshot - http://awesomescreenshot.com/0144bz4t30

---------

Definitely give this a consideration along with the knitr one as well to determine what will work best for your internal workflows.

Let me know if you have any further questions.

Regards,

Jon
 
anders kielland responded:  2015-02-04 11:42
Thank you very much Jon

I believe I managed to create the wiki with the javascript query (very good explanation - I haven't done any coding before).

But I don't think I manage to set up the right URL in the Customized Participant View

The Wiki letter seems to have this URL:
https://labkey01.usit.uio.no/labkey/wiki/TNS%20%28date%29/page.view?name=Letter

I use this in Customized Participant View:
aTag.setAttribute('href',"labkey01.usit.uio.no/labkey/wiki/TNS%20%28date%29/page.view?name=Letter&participantId=" + participantId + "&_print=1");

And got and 404: Error page (see attached)

It might be something else I haven't understood; however, I wonder if you can make some sense out of it?

kind regards, Anders
 
Jon (LabKey DevOps) responded:  2015-02-04 13:04
Anders,

I was shown a better way to use that specific line of code.

Can you replace what you have there with this instead?

aTag.setAttribute('href', LABKEY.ActionURL.buildURL('wiki', 'page', null, { name: 'Letter', participantId: participantId, '_print': 1 }) );

This builds a URL and specifically focuses on the wiki module and the name of the wiki (called "Letter") and inserts the Participant ID number along with it.

Regards,

Jon