development

Integrating with Harmony

Please select all the ways you would like to hear from Harmony project:

Integrating with Harmony

Sending data from another website to Harmony using Javascript

We have exposed functionality for external websites to integrate with Harmony and add an “import to Harmony” button, either generated in Javascript or in Python.

  1. Create an Instrument object with at least an instrument_name and questions property in JSON - the questions must have a question_no and question_text properties eg:
{
    "instrument_name": "Smoking behaviour",
    "questions": [
        {
            "question_no": "1",
            "question_text": "Do you currently smoke or have you ever smoked?"
        },
        {
            "question_no": "2",
            "question_text": "[Do you currently use] nicotine replacement therapy?"
        }
    ]
}

Encode it to URL safe base64 string - js-base64 is a good library for this.

Send it to the import URL - to maintain a single instance of the harmony tab / page the target must be set to the harmony URL

<a href="https://harmonydata.ac.uk/app/import/eyJpbnN0cnVtZW50X25hbWUiOiJUcmVhdG1lbnQgLSBtZWRpY2F0aW9uIiwicXVlc3Rpb25zIjpbeyJxdWVzdGlvbl9ubyI6IjEiLCJxdWVzdGlvbl90ZXh0IjoiSGF2ZSB5b3UgZXZlciB0YWtlbiBhbnRpLWRlcHJlc3NhbnRzPyJ9XX0" >Harmonise this scale with harmonydata.ac.uk</a>
from harmony import create_instrument_from_list, import_instrument_into_harmony_web

instrument = load_instrument_from_list(["Do you currently smoke or have you ever smoked?", "[Do you currently use] nicotine replacement therapy?"])
web_url = import_instrument_into_harmony_web(instrument)

print (web_url)
import base64, json

instrument_serialised_as_json = json.dumps({
    "instrument_name": "Smoking behaviour",
    "questions": [
        {
            "question_no": "1",
            "question_text": "Do you currently smoke or have you ever smoked?"
        },
        {
            "question_no": "2",
            "question_text": "[Do you currently use] nicotine replacement therapy?"
        }
    ]
})
instrument_json_b64_encoded_bytes = base64.urlsafe_b64encode(instrument_serialised_as_json.encode('utf-8'))
instrument_json_b64_encoded_str = instrument_json_b64_encoded_bytes.decode("utf-8")

url = f"https://harmonydata.ac.uk/app/#/import/{instrument_json_b64_encoded_str}"

print (url)

Importing multiple instruments

You can even import more than one instrument via the URL:

import base64, json

instrument_serialised_as_json = json.dumps([{
    "instrument_name": "Smoking behaviour",
    "questions": [
        {
            "question_no": "1",
            "question_text": "Do you currently smoke or have you ever smoked?"
        },
        {
            "question_no": "2",
            "question_text": "[Do you currently use] nicotine replacement therapy?"
        }
    ]
}, {
    "instrument_name": "Smoking Review",
    "questions": [
        {
            "question_no": "1",
            "question_text": "Do you currently smoke?"
        },
        {
            "question_no": "2",
            "question_text": "Have you smoked in the past?"
        }
    ]
}])
instrument_json_b64_encoded_bytes = base64.urlsafe_b64encode(instrument_serialised_as_json.encode('utf-8'))
instrument_json_b64_encoded_str = instrument_json_b64_encoded_bytes.decode("utf-8")

url = f"https://harmonydata.ac.uk/app/#/import/{instrument_json_b64_encoded_str}"

print (url)

this makes the following URL:

Related Posts

Help Design Harmony - UX Design Challenge

Help Design Harmony - UX Design Challenge

Help us design the next phase of Harmony and win up to £300 in vouchers! Search and Results UX/UI Challenge Harmony is a platform for researchers to help them discover and compare complex meta-data across different academic studies. The project is a collaboration between University College London (UCL), The University of Ulster, and Fast Data Science and has been funded by the Economic and Social Research Council (ESRC) and by Wellcome as part of the Wellcome Data Prize in Mental Health.

Winners of the Doxa AI Matching Challenge

Winners of the Doxa AI Matching Challenge

It’s all over! The Matching Challenge is now officially closed. Thank you to everyone who took part. The wait is over! We have now closed the Matching Challenge which was hosted on DOXA AI. Over the course of the competition we saw a total of 26 participants with 14 finalists making it onto the scoreboard. The final days were tense with many participants improving on their scores, submitting different methods and swapping places at the top of the scoreboard.

Signup to our newsletter

The latest news on data harmonisation project.

Please select all the ways you would like to hear from Harmony project:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website. We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices.