Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Background

Opal has a python client that lets you query various things, and even import some data (see http://wiki.obiba.org/display/OPALDOC/Opal+Python+User+Guide). It doesn't let you create projects and tables from scratch though. Given the web interface does this via the REST API we should be able to do it from the command line. This is how.

...

The following is loosely based on the AMASED work getting the BL books into opal - https://github.com/OllyButters/flatten-bl-xml

Test the python client

A good place to start is getting some info from the opal with the client:

...

where the URL is changed to your install location and the 'administrator/password' bits are changed accordingly. Assuming you get something sensible back you have installed the opal client correctly and know all your credentials!

Adding a project

Lets call this project 'my_project', and lets assume I am looking at books. You can do this with the API, but I haven't yet - I made the project via the web interface.

Adding a table

Once you have a project you want to add a table to it. The first step is to make a JSON file and save it as e.g. my_table.json. The entityType seems to be entirely arbitrary, so call it something relevant to you.

...

Now there should be a table called Hamlet in the my_project project - have a look in the web interface.

Adding some variables

The table will not have any variables associated with it at this stage. We can add them in a similar way to above, first off build a JSON file and save it as e.g. my_variables.json

...

Code Block
[
    {
        "name": "VAR1",
        "entityType": "Participant",
        "valueType": "text",
        "unit": "",
        "isRepeatable": false,
        "referencedEntityType": "",
        "mimeType": "",
        "occurrenceGroup": "",
        "index": 1,
        "attributes": [
            {
                "name": "label",
                "value": "Which language do you speak?",
                "locale": "en"
            },
            {
                "name": "label",
                "value": "Quelles langues parlez-vous?",
                "locale": "fr"
            }
        ]
    },
    {
        "name": "VAR2",
        "entityType": "Participant",
        "valueType": "integer",
        "mimeType": "",
        "isRepeatable": false,
        "occurrenceGroup": "",
        "unit": "",
        "referencedEntityType": "",
        "index": 2,
        "attributes": [
            {
                "name": "label",
                "value": "Do you like that?"
            }
        ],
        "categories": [
            {
                "name": "1",
                "isMissing": false,
                "attributes": [
                    {
                        "name": "label",
                        "value": "yes"
                    }
                ]
            },
            {
                "name": "2",
                "isMissing": false,
                "attributes": [
                    {
                        "name": "label",
                        "value": "no"
                    }
                ]
            },
            {
                "name": "9",
                "isMissing": true,
                "attributes": [
                    {
                        "name": "label",
                        "value": "do not know"
                    }
                ]
            }
        ]
    }
]

 

Adding some data

Now to import some data. The general work flow here is to make a CSV file elsewhere, upload it to opal, then tell opal to use the uploaded file.

...