Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load instrument from list #47

Merged
merged 3 commits into from
Jun 21, 2024
Merged

Load instrument from list #47

merged 3 commits into from
Jun 21, 2024

Conversation

woodthom2
Copy link
Contributor

@woodthom2 woodthom2 commented Jun 21, 2024

Description

We have new methods:

harmony.create_instrument_from_list(["a", "b"])
harmony.import_instrument_into_harmony_web(instrument)

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/#/import/eyJpbnN0cnVtZW50X25hbWUiOiJUcmVhdG1lbnQgLSBtZWRpY2F0aW9uIiwicXVlc3Rpb25zIjpbeyJxdWVzdGlvbl9ubyI6IjEiLCJxdWVzdGlvbl90ZXh0IjoiSGF2ZSB5b3UgZXZlciB0YWtlbiBhbnRpLWRlcHJlc3NhbnRzPyJ9XX0" >Harmonise this scale with harmonydata.ac.uk</a>

Creating a link to Harmony web UI from the Harmony Python library

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)

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • [X ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Requires a documentation revision

Testing

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [X ] test_create_instrument_from_list.py

Test Configuration

  • Library version: 0.5.2
  • OS: Ubuntu
  • Toolchain: Pycharm + Pytest

Checklist

  • [X ] My code follows the style guidelines of this project
  • [ X] I have performed a self-review of my own code
  • [ X] I have commented my code, particularly in hard-to-understand areas
  • [X ] I have made corresponding changes to the documentation
  • [ X] My changes generate no new warnings
  • [ X] I have added tests that prove my fix is effective or that my feature works
  • [ X] New and existing unit tests pass locally with my changes
  • [X ] Any dependent changes have been merged and published in downstream modules
  • [X ] I have checked my code and corrected any misspellings

@woodthom2 woodthom2 merged commit e8e7f3c into main Jun 21, 2024
1 check passed
@woodthom2 woodthom2 deleted the load_instrument_from_list branch June 21, 2024 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant