ebi-ait / morphic-website

A generic data catalogue web app to serve the AIT team projects.
0 stars 0 forks source link

Examine REDCAP API and investigate whether it conforms to HAL API format #93

Closed Wkt8 closed 8 months ago

Wkt8 commented 9 months ago

I have exported a json file from queries to the REDCAP eLwazi Catalogue MetaData Management Project.

This contains the json output of the metadata for one field.

I also have an API key for querying the API directly. Reach out to me for it.

[
  {
    "field_name": "record_id",
    "form_name": "project_metadata",
    "section_header": "",
    "field_type": "text",
    "field_label": "Record ID",
    "select_choices_or_calculations": "",
    "field_note": "",
    "text_validation_type_or_show_slider_number": "",
    "text_validation_min": "",
    "text_validation_max": "",
    "identifier": "",
    "branching_logic": "",
    "required_field": "",
    "custom_alignment": "",
    "question_number": "",
    "matrix_group_name": "",
    "matrix_ranking": "",
    "field_annotation": ""
  }
]

Editing the json schema from REDCAP to make it look like the json schema example here from data-catalogue-backend:


{
  "$id": "a research project",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "title": {
      "type": "string",
      "minLength": 1
    },
    "acronym": {
      "type": "string",
      "minLength": 1
    },
    "dsIAfricaAffiliation": {
      "type": "string",
      "minLength": 1
    },
    "description": {
      "type": "string",
      "minLength": 1
    },
    "keywords": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "required": [
    "title",
    "acronym",
    "dsIAfricaAffiliation",
    "description"
  ]
}
Wkt8 commented 9 months ago

Amnon has a temporary login account to the REDCAP API

Wkt8 commented 9 months ago

json_format.json REDCAP Data Dictionary in the form of a JSON schema in the attached file

amnonkhen commented 8 months ago

Possible access methods to the catalogue data: Catalogue Data Access_Page 1.pdf

Wkt8 commented 8 months ago

This is now complete as we have the json schema of the REDCAP Data Dictionary.

import requests as rq
import json

data = {
    'token': '-',
    'content': 'metadata',
    'format': 'json',
    'returnFormat': 'json',
}
r = rq.post('https://redcap.h3abionet.org/redcap/api/',data=data)
print('HTTP Status: ' + str(r.status_code))
# print(r.json())
redcap_data = r.json()

# Convert REDCap data to HAL format
hal_data = {
    "_links": {
        "self": {"href": "/redcap"}
    },
    "_embedded": {
        "properties": []
    }
}

for record in redcap_data:
    record_data = {record["field_name"]:
    {
        "form_name":record["form_name"],
        "type": record["field_type"],
        "select_choices_or_calculations": record["select_choices_or_calculations"],
        "required_field": record["required_field"],
        "text_validation_type_or_show_slider_number": record["text_validation_type_or_show_slider_number"],
        "text_validation_min": record["text_validation_min"],
        "text_validation_max": record["text_validation_max"]
    }}

    hal_data["_embedded"]["properties"].append(record_data)

# Print the HAL data
with open('json_format.json', 'w') as f:
    json.dump(hal_data, f, indent=4, separators=(',', ': '))