Attaching Files Programatically

by Mark Luszniak on May 17, 2013 in Technology
Technology Image

Did you know there are four places in which files can be attached to the GenoLogics LIMS?

We probably all know that files can be attached to ResultFile placeholders in the genealogy, and also attached to Projects (Sample Submission Spreadsheets for example), but files can also be attached to Samples and Processes. These latter two cases are not common, but they can be used as ‘work arounds’ in some cases.

For example, you have a process that is a purposed ‘out-of-the-box’ process , and not configurable. You’d like to be able to attach a file to a ResultFile placeholder but you can’t, as you can’t modify the outputs produced by the process. You can still attach a file to the Process though. Since it’s not an output of the process it won’t show up in the genealogy, but you can still browse and search for it, and if you look at the Files attached to the parent Project, you’ll see it there too.

So, how would you go about doing this programmatically? It’s the normal three steps (documented here: Attaching a file to a process placeholder using EPP), but with one minor modification:

1. POST xml to the glsstorage entity

<file:file xmlns:file="http://genologics.com/ri/file">
  <attached-to>HOSTNAME/api/v1/processes/LUID</attached-to>
  <original-location>FILEPATH</original-location></file:file> 

It’s the second line which is the key:

  <attached-to>HOSTNAME/api/v1/processes/LUID</attached-to>

where LUID is the LIMS Unique-Id of the process you want the file attached to.

Incidentally, if you want the file attached to a Project, use:

  <attached-to>HOSTNAME/api/v1/projects/LUID</attached-to>

where LUID is the LIMS Unique-Id of the project you want the file attached to.

Further, if you want the file attached to a Sample, use:

  <attached-to>HOSTNAME/api/v1/samples/LUID</attached-to>

where LUID is the LIMS Unique-Id of the Sample you want the file attached to.

2. Transfer the file to the LIMS filestore

If your POST in Step 1 is successful, the XML returned will tell you exactly where to upload the file to. This is something you need to do in your code, using any of the SSH/FTP libraries that are out in the wild. As an example, if I’m coding in Python I tend to use the excellent Paramiko module.

3. Update the files entity

Assuming that your POST in Step 1 was successful, take the XML that was returned, and POST it to the files entity.

 

 

Share