diff --git a/min_csos.ipynb b/min_csos.ipynb new file mode 100644 index 0000000..f613909 --- /dev/null +++ b/min_csos.ipynb @@ -0,0 +1,1046 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "63e52f8c", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:37.156297Z", + "start_time": "2021-11-18T19:42:37.153391Z" + } + }, + "outputs": [], + "source": [ + "import sys" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "d2f1c191", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:39.496128Z", + "start_time": "2021-11-18T19:42:37.158690Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: crdch_model in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (1.1.1)\n", + "Requirement already satisfied: linkml in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (1.1.7)\n", + "Requirement already satisfied: black in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (21.11b1)\n", + "Requirement already satisfied: requests>=2.22 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (2.26.0)\n", + "Requirement already satisfied: sphinx-rtd-theme in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (1.0.0)\n", + "Requirement already satisfied: linkml-runtime>=1.1.2 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (1.1.2)\n", + "Requirement already satisfied: rdflib~=5.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (5.0.0)\n", + "Requirement already satisfied: prefixcommons>=0.1.7 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.1.9)\n", + "Requirement already satisfied: sphinx-click in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (3.0.1)\n", + "Requirement already satisfied: openpyxl in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (3.0.9)\n", + "Requirement already satisfied: pyjsg>=0.11.6 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.11.6)\n", + "Requirement already satisfied: rdflib-jsonld<=0.6.1,>=0.5.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.6.1)\n", + "Requirement already satisfied: jsonschema>=3.0.1 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (4.0.1)\n", + "Requirement already satisfied: pyshexc>=0.8.3 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.8.3)\n", + "Requirement already satisfied: pyyaml~=5.1 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (5.4.1)\n", + "Requirement already satisfied: prologterms>=0.0.6 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.0.6)\n", + "Requirement already satisfied: rdflib-pyldmod-compat>=0.1.2c in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.1.2)\n", + "Requirement already satisfied: jsonasobj2>=1.0.3,~=1.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (1.0.4)\n", + "Requirement already satisfied: watchdog>=0.9.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (2.1.5)\n", + "Requirement already satisfied: myst-parser in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.15.2)\n", + "Requirement already satisfied: click~=7.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (7.1.2)\n", + "Requirement already satisfied: hbreader in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.9.1)\n", + "Requirement already satisfied: parse in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (1.19.0)\n", + "Requirement already satisfied: linkml-runtime-api in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.0.4)\n", + "Requirement already satisfied: pyldmod>=2.0.5 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (2.0.5)\n", + "Requirement already satisfied: sqlalchemy in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (1.4.25)\n", + "Requirement already satisfied: python-dateutil in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (2.8.2)\n", + "Collecting argparse>=1.4.0\n", + " Using cached argparse-1.4.0-py2.py3-none-any.whl (23 kB)\n", + "Requirement already satisfied: pyshex>=0.7.20 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.7.20)\n", + "Requirement already satisfied: jinja2 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (3.0.1)\n", + "Requirement already satisfied: isodate>=0.6.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.6.0)\n", + "Requirement already satisfied: sphinx in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (4.2.0)\n", + "Requirement already satisfied: graphviz>=0.10.1 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml) (0.17)\n", + "Requirement already satisfied: platformdirs>=2 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from black) (2.4.0)\n", + "Requirement already satisfied: typing-extensions>=3.10.0.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from black) (4.0.0)\n", + "Requirement already satisfied: mypy-extensions>=0.4.3 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from black) (0.4.3)\n", + "Requirement already satisfied: regex>=2021.4.4 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from black) (2021.11.10)\n", + "Requirement already satisfied: pathspec<1,>=0.9.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from black) (0.9.0)\n", + "Requirement already satisfied: tomli<2.0.0,>=0.2.6 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from black) (1.2.2)\n", + "Requirement already satisfied: six in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from isodate>=0.6.0->linkml) (1.16.0)\n", + "Requirement already satisfied: attrs>=17.4.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from jsonschema>=3.0.1->linkml) (21.2.0)\n", + "Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from jsonschema>=3.0.1->linkml) (0.18.0)\n", + "Requirement already satisfied: shexjsg~=0.7 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml-runtime>=1.1.2->linkml) (0.7.1)\n", + "Requirement already satisfied: json-flattener>=0.1.7 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml-runtime>=1.1.2->linkml) (0.1.7)\n", + "Requirement already satisfied: deprecated in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml-runtime>=1.1.2->linkml) (1.2.13)\n", + "Requirement already satisfied: jsonasobj>=1.2.1 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from pyjsg>=0.11.6->linkml) (1.3.1)\n", + "Requirement already satisfied: antlr4-python3-runtime~=4.9 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from pyjsg>=0.11.6->linkml) (4.9.2)\n", + "Requirement already satisfied: cachetools in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from pyldmod>=2.0.5->linkml) (4.2.4)\n", + "Requirement already satisfied: frozendict in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from pyldmod>=2.0.5->linkml) (2.0.6)\n", + "Requirement already satisfied: lxml in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from pyldmod>=2.0.5->linkml) (4.6.3)\n", + "Requirement already satisfied: cfgraph>=0.2.1 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from pyshex>=0.7.20->linkml) (0.2.1)\n", + "Requirement already satisfied: urllib3 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from pyshex>=0.7.20->linkml) (1.26.7)\n", + "Requirement already satisfied: sparqlslurper~=0.4 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from pyshex>=0.7.20->linkml) (0.4.1)\n", + "Requirement already satisfied: sparqlwrapper>=1.8.5 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from pyshex>=0.7.20->linkml) (1.8.5)\n", + "Requirement already satisfied: pyparsing in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from rdflib~=5.0->linkml) (2.4.7)\n", + "Requirement already satisfied: testfixtures in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from rdflib-pyldmod-compat>=0.1.2c->linkml) (6.18.3)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: certifi>=2017.4.17 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from requests>=2.22->linkml) (2021.5.30)\n", + "Requirement already satisfied: charset-normalizer~=2.0.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from requests>=2.22->linkml) (2.0.6)\n", + "Requirement already satisfied: idna<4,>=2.5 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from requests>=2.22->linkml) (3.2)\n", + "Requirement already satisfied: wrapt<2,>=1.10 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from deprecated->linkml-runtime>=1.1.2->linkml) (1.12.1)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from jinja2->linkml) (2.0.1)\n", + "Requirement already satisfied: jsonpath-ng in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml-runtime-api->linkml) (1.5.3)\n", + "Requirement already satisfied: jsonpatch in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml-runtime-api->linkml) (1.32)\n", + "Requirement already satisfied: ruamel.yaml in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from linkml-runtime-api->linkml) (0.17.16)\n", + "Requirement already satisfied: jsonpointer>=1.9 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from jsonpatch->linkml-runtime-api->linkml) (2.1)\n", + "Requirement already satisfied: decorator in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from jsonpath-ng->linkml-runtime-api->linkml) (5.1.0)\n", + "Requirement already satisfied: ply in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from jsonpath-ng->linkml-runtime-api->linkml) (3.11)\n", + "Requirement already satisfied: docutils<0.18,>=0.15 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from myst-parser->linkml) (0.17.1)\n", + "Requirement already satisfied: mdit-py-plugins~=0.2.8 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from myst-parser->linkml) (0.2.8)\n", + "Requirement already satisfied: markdown-it-py<2.0.0,>=1.0.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from myst-parser->linkml) (1.1.0)\n", + "Requirement already satisfied: alabaster<0.8,>=0.7 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (0.7.12)\n", + "Requirement already satisfied: babel>=1.3 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (2.9.1)\n", + "Requirement already satisfied: sphinxcontrib-jsmath in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (1.0.1)\n", + "Requirement already satisfied: imagesize in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (1.2.0)\n", + "Requirement already satisfied: sphinxcontrib-devhelp in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (1.0.2)\n", + "Requirement already satisfied: sphinxcontrib-applehelp in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (1.0.2)\n", + "Requirement already satisfied: snowballstemmer>=1.1 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (2.1.0)\n", + "Requirement already satisfied: sphinxcontrib-qthelp in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (1.0.3)\n", + "Requirement already satisfied: sphinxcontrib-serializinghtml>=1.1.5 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (1.1.5)\n", + "Requirement already satisfied: packaging in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (21.0)\n", + "Requirement already satisfied: sphinxcontrib-htmlhelp>=2.0.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (2.0.0)\n", + "Requirement already satisfied: setuptools in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (58.1.0)\n", + "Requirement already satisfied: Pygments>=2.0 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sphinx->linkml) (2.10.0)\n", + "Requirement already satisfied: pytz>=2015.7 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from babel>=1.3->sphinx->linkml) (2021.1)\n", + "Requirement already satisfied: et-xmlfile in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from openpyxl->linkml) (1.1.0)\n", + "Requirement already satisfied: ruamel.yaml.clib>=0.1.2 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from ruamel.yaml->linkml-runtime-api->linkml) (0.2.6)\n", + "Requirement already satisfied: greenlet!=0.4.17 in /Users/MAM/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages (from sqlalchemy->linkml) (1.1.2)\n", + "Installing collected packages: argparse\n", + "Successfully installed argparse-1.4.0\n" + ] + } + ], + "source": [ + "!{sys.executable} -m pip install crdch_model linkml black" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "a25c5fa8", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:55:15.063821Z", + "start_time": "2021-11-18T19:55:14.799252Z" + } + }, + "outputs": [], + "source": [ + "import crdch_model.crdch_model as ccdh\n", + "from linkml_runtime.utils.schemaview import SchemaView\n", + "from linkml_runtime.dumpers import yaml_dumper\n", + "import requests\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "d6cc3287", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:40.338456Z", + "start_time": "2021-11-18T19:42:40.335559Z" + } + }, + "outputs": [], + "source": [ + "crdch_linkml_file = \"../ccdhmodel/model/schema/crdch_model.yaml\"" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "b3cc6c84", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.289331Z", + "start_time": "2021-11-18T19:42:40.340893Z" + } + }, + "outputs": [], + "source": [ + "crdch_view = SchemaView(crdch_linkml_file)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "af852f83", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.294097Z", + "start_time": "2021-11-18T19:42:41.290883Z" + } + }, + "outputs": [], + "source": [ + "# crdch_schema = crdch_view.schema" + ] + }, + { + "cell_type": "markdown", + "id": "1aba648b", + "metadata": {}, + "source": [ + "----" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "c9f2a262", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.299465Z", + "start_time": "2021-11-18T19:42:41.296385Z" + } + }, + "outputs": [], + "source": [ + "cso1 = ccdh.CancerStageObservation(\n", + " observation_type=ccdh.CodeableConcept(),\n", + " value_codeable_concept=ccdh.CodeableConcept(),\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "7229269e", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.303531Z", + "start_time": "2021-11-18T19:42:41.301376Z" + } + }, + "outputs": [], + "source": [ + "csos = ccdh.CancerStageObservationSet()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "fa567a22", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.309465Z", + "start_time": "2021-11-18T19:42:41.307405Z" + } + }, + "outputs": [], + "source": [ + "csos.observations.append(cso1)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "4600572c", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.313234Z", + "start_time": "2021-11-18T19:42:41.311125Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CancerStageObservationSet(id=None, category=None, focus=[], subject=None, method_type=[], performed_by=None, observations=[CancerStageObservation(observation_type=CodeableConcept(coding=[], text=None), value_codeable_concept=CodeableConcept(coding=[], text=None), id=None, category=None, method_type=None, focus=None, subject=None, performed_by=None, value_entity=None)])\n" + ] + } + ], + "source": [ + "print(csos)" + ] + }, + { + "cell_type": "markdown", + "id": "67f57d77", + "metadata": {}, + "source": [ + "## Time out\n", + "- `CancerStageObservation` requires `CodeableConcept`s for `observation_type` and `value_codeable_concept`, but those `CodeableConcepts` can be empty\n", + "- `id` can be empty!\n", + "- `CancerStageObservation` isn't asserted to be a subclass of `Observation`, nor `CancerStageObservationSet` as `ObservationSet`\n", + "\n", + "_show by opening the model into a schemaview_" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "25bf5221", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.639144Z", + "start_time": "2021-11-18T19:42:41.314489Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Entity\n" + ] + } + ], + "source": [ + "CancerStageObservation_view = crdch_view.get_class(\"CancerStageObservation\")\n", + "print(CancerStageObservation_view.is_a)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "2521a203", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.658811Z", + "start_time": "2021-11-18T19:42:41.640344Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "name: CancerStageObservation\n", + "description: A data structure with key (observation_type) and value (value_codeable_concept)\n", + " attributes that represents a single cancer staging observation, such as the Clinical\n", + " Metastasis (M) component of a clinical TNM staging.\n", + "notes:\n", + "- Derived from [CancerStageObservation in sheet CancerStageObservation](https://docs.google.com/spreadsheets/d/1oWS7cao-fgz2MKWtyr8h2dEL9unX__0bJrWKv6mQmM4/edit#gid=1189722404)\n", + "is_a: Entity\n", + "attributes:\n", + " id:\n", + " name: id\n", + " description: The 'logical' identifier of the entity within the system of record. The\n", + " simple value of this attribute stands for an identifier of this data object\n", + " within the system, it can be used as a reference from other objects within the\n", + " same system (i.e. primary and foreign keys), and it should be unique per type\n", + " of object. The same data object copied to a different system will likely have\n", + " a different \"id\" in the new system since \"id\" values are system specific and\n", + " do not represent persistent business identifiers. Business identifiers are assigned\n", + " outside the information system and are captured in the \"identifier\" field. The\n", + " \"id\" field is more likely to be a serially or randomly generated value that\n", + " is assigned to the data object as it is created in a system.\n", + " notes:\n", + " - 'Cardinality: 0..0'\n", + " comments:\n", + " - 'FHIR naming conventions are followed here, where ''id'' is used for logical\n", + " identifiers, and ''identifier'' for business identifiers. The identified entity\n", + " may have a different ''id'' in a different system, and have many external business\n", + " ''identifiers'' associated with it. If an \"id\" value can also be considered\n", + " to be a business identifier, and should be transmissible to other systems, it\n", + " should be duplicated in the \"identifier\" attribute along with the additional\n", + " metadata needed to give context to the value of \"id\". An entity in this model\n", + " that does not have an \"id\" field is considered to be an embeddable entity that\n", + " can not stand on its own. '\n", + " examples:\n", + " - value: ''\n", + " domain: CancerStageObservation\n", + " range: crdch_string\n", + " multivalued: false\n", + " required: false\n", + " category:\n", + " name: category\n", + " description: The general category of observation described\n", + " notes:\n", + " - 'Cardinality: 0..0'\n", + " examples:\n", + " - value: ''\n", + " values_from:\n", + " - crdch:enum_CRDCH_CancerStageObservation_category\n", + " domain: CancerStageObservation\n", + " range: CodeableConcept\n", + " multivalued: false\n", + " required: false\n", + " observation_type:\n", + " name: observation_type\n", + " description: The type of cancer staging component being represented (e.g. 'Clinical\n", + " Metastasis (M)')\n", + " notes:\n", + " - 'Cardinality: 1..1'\n", + " comments:\n", + " - 'This field holds the ''key'' in the core key-value pair comprised of the observation_type\n", + " field and the relevant value(s) field. ''Overall'' should be used when: the\n", + " source staging value is not definitively ''Clinical'' or ''Pathological'' (e.g.\n", + " a TNM staged cancer without a clear indication of clinical vs pathological),\n", + " or the source staging system does not use T, N, or M components and only has\n", + " a single overall staging value (e.g. FIGO staging)'\n", + " examples:\n", + " - value: Overall\n", + " - value: Tumor (T)\n", + " - value: Node (N)\n", + " - value: Metastasis (M)\n", + " - value: Clinical Overall\n", + " - value: Clinical Tumor (T)\n", + " - value: Clinical Node (N)\n", + " - value: Clinical Metastasis (M)\n", + " - value: Pathological Overall\n", + " - value: Pathological Tumor (T)\n", + " - value: Pathological Node (N)\n", + " - value: Pathological Metastasis (M)\n", + " - value: Ann Arbor Modifier\n", + " values_from:\n", + " - crdch:enum_CRDCH_CancerStageObservation_observation_type\n", + " domain: CancerStageObservation\n", + " range: CodeableConcept\n", + " multivalued: false\n", + " required: true\n", + " method_type:\n", + " name: method_type\n", + " description: A type of method used in generating the Observation result.\n", + " notes:\n", + " - 'Cardinality: 0..0'\n", + " comments:\n", + " - This may be a type of observational, measurement, experimental, or computational\n", + " method specifying how to generate data (e.g. 'manual counting', 'bright field\n", + " microscopy',). Or a Guideline or SOP specifying how to interpret data and/or\n", + " encode the result of an Observation (e.g. a Cancer Staging system such as that\n", + " defined by the AJCC, or variant interpretation guideline such as that provided\n", + " by the ACMG).\n", + " examples:\n", + " - value: ''\n", + " values_from:\n", + " - crdch:enum_CRDCH_CancerStageObservation_method_type\n", + " domain: CancerStageObservation\n", + " range: CodeableConcept\n", + " multivalued: false\n", + " required: false\n", + " focus:\n", + " name: focus\n", + " description: The entity or entities directly observed/measured in generating an\n", + " observation result.\n", + " notes:\n", + " - 'Cardinality: 0..0'\n", + " comments:\n", + " - 'The ''focus'', ''subject'', and ''specimen'' fields are useful when data creators\n", + " want an Observation object to stand on its own, so it can point back to the\n", + " entities it is about. These fields are not needed when an Observation is embedded\n", + " in a Specimen or other entity, where focus, subject, and specimen can be determined\n", + " from context. '\n", + " examples:\n", + " - value: ''\n", + " domain: CancerStageObservation\n", + " range: Entity\n", + " multivalued: false\n", + " required: false\n", + " subject:\n", + " name: subject\n", + " description: The patient that the observation is about (if not the direct focus). e.g.\n", + " observations are often made on specimens derived from a patient, or other entities\n", + " related to a patient, that ultimately tell us something about the patient of\n", + " interest.\n", + " notes:\n", + " - 'Cardinality: 0..0'\n", + " examples:\n", + " - value: ''\n", + " domain: CancerStageObservation\n", + " range: Subject\n", + " multivalued: false\n", + " required: false\n", + " performed_by:\n", + " name: performed_by\n", + " description: The organization or group that performed the observation activity.\n", + " notes:\n", + " - 'Cardinality: 0..0'\n", + " examples:\n", + " - value: ''\n", + " domain: CancerStageObservation\n", + " range: Organization\n", + " multivalued: false\n", + " required: false\n", + " value_codeable_concept:\n", + " name: value_codeable_concept\n", + " exact_mappings:\n", + " - GDC:Diagnosis.ajcc_clinical_m\n", + " - PDC:Diagnosis.ajcc_clinical_m\n", + " - GDC:Diagnosis.ajcc_clinical_n\n", + " - PDC:Diagnosis.ajcc_clinical_n\n", + " - GDC:Diagnosis.ajcc_clinical_t\n", + " - PDC:Diagnosis.ajcc_clinical_t\n", + " - GDC:Diagnosis.ajcc_clinical_stage\n", + " - PDC:Diagnosis.ajcc_clinical_stage\n", + " - HTAN:Diagnosis.AJCCClinicalM\n", + " - HTAN:Diagnosis.AJCCClinicalN\n", + " - HTAN:Diagnosis.AJCCClinicalT\n", + " - HTAN:Diagnosis.AJCCClinicalStage\n", + " - HTAN:Diagnosis.AJCCPathologicM\n", + " - HTAN:Diagnosis.AJCCPathologicN\n", + " - HTAN:Diagnosis.AJCCPathologicT\n", + " - HTAN:Diagnosis.AJCCPathologicStage\n", + " - GDC:Diagnosis.tumor_stage\n", + " - PDC:Diagnosis.tumor_stage\n", + " - ICDC:Diagnosis.stage_of_disease\n", + " - GDC:Diagnosis.ajcc_pathologic_m\n", + " - PDC:Diagnosis.ajcc_pathologic_m\n", + " - GDC:Diagnosis.ajcc_pathologic_n\n", + " - PDC:Diagnosis.ajcc_pathologic_n\n", + " - GDC:Diagnosis.ajcc_pathologic_t\n", + " - PDC:Diagnosis.ajcc_pathologic_t\n", + " - GDC:Diagnosis.ajcc_pathologic_stage\n", + " - PDC:Diagnosis.ajcc_pathologic_stage\n", + " - GDC:Diagnosis.ajcc_staging_system_edition\n", + " - PDC:Diagnosis.ajcc_staging_system_edition\n", + " - GDC:Diagnosis.ann_arbor_clinical_stage\n", + " - PDC:Diagnosis.ann_arbor_clinical_stage\n", + " - GDC:Diagnosis.ann_arbor_pathologic_stage\n", + " - PDC:Diagnosis.ann_arbor_pathologic_stage\n", + " - GDC:Diagnosis.figo_stage\n", + " - PDC:Diagnosis.figo_stage\n", + " - GDC:Diagnosis.igcccg_stage\n", + " - PDC:Diagnosis.igcccg_stage\n", + " - GDC:Diagnosis.inss_stage\n", + " - PDC:Diagnosis.inss_stage\n", + " - GDC:Diagnosis.iss_stage\n", + " - PDC:Diagnosis.iss_stage\n", + " - GDC:Diagnosis.masaoka_stage\n", + " - PDC:Diagnosis.masaoka_stage\n", + " - GDC:Diagnosis.cog_liver_stage\n", + " - PDC:Diagnosis.cog_liver_stage\n", + " - GDC:Diagnosis.cog_renal_stage\n", + " - PDC:Diagnosis.cog_renal_stage\n", + " - GDC:Diagnosis.enneking_msts_metastasis\n", + " - PDC:Diagnosis.enneking_msts_metastasis\n", + " - GDC:Diagnosis.enneking_msts_stage\n", + " - PDC:Diagnosis.enneking_msts_stage\n", + " - GDC:Diagnosis.enneking_msts_tumor_site\n", + " - PDC:Diagnosis.enneking_msts_tumor_site\n", + " - GDC:Diagnosis.inrg_stage\n", + " - PDC:Diagnosis.inrg_stage\n", + " - GDC:Diagnosis.irs_stage\n", + " - PDC:Diagnosis.irs_stage\n", + " - GDC:Diagnosis.ann_arbor_b_symptoms\n", + " - PDC:Diagnosis.ann_arbor_b_symptoms\n", + " - GDC:Diagnosis.ann_arbor_extranodal_involvement\n", + " - PDC:Diagnosis.ann_arbor_extranodal_involvement\n", + " description: The value for a cancer staging component being represented (e.g.\n", + " 'M1'), encoded as a CodeableConcept.\n", + " notes:\n", + " - 'Cardinality: 1..1'\n", + " comments:\n", + " - One and only one of the value(x) fields must be populated.\n", + " examples:\n", + " - value: M0\n", + " - value: M1\n", + " - value: M1a\n", + " - value: N0\n", + " - value: N0 (i+)\n", + " - value: N0 (i-)\n", + " values_from:\n", + " - crdch:enum_CRDCH_CancerStageObservation_value_codeable_concept\n", + " domain: CancerStageObservation\n", + " range: CodeableConcept\n", + " multivalued: false\n", + " required: true\n", + "\n" + ] + } + ], + "source": [ + "print(yaml_dumper.dumps(CancerStageObservation_view))" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "71c345a7", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.664887Z", + "start_time": "2021-11-18T19:42:41.661387Z" + } + }, + "outputs": [], + "source": [ + "dgcc = ccdh.CodeableConcept(text=\"pizza doesn't taste good anymore\")" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "69c6e83d", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.670858Z", + "start_time": "2021-11-18T19:42:41.667679Z" + } + }, + "outputs": [], + "source": [ + "dgc = ccdh.Coding(\n", + " code=\"any text acceptable\", system=\"not even a URL\", label=\"dysgeusia\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "efae638f", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.681916Z", + "start_time": "2021-11-18T19:42:41.673150Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "Coding(code='any text acceptable', system='not even a URL', label='dysgeusia', system_version=None, value_set=None, value_set_version=None, tag=[])" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dgc" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "5b5b9650", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.701286Z", + "start_time": "2021-11-18T19:42:41.688702Z" + } + }, + "outputs": [], + "source": [ + "dgcc.coding.append(dgc)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "b2d4c4f1", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.721998Z", + "start_time": "2021-11-18T19:42:41.712742Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "CodeableConcept(coding=[Coding(code='any text acceptable', system='not even a URL', label='dysgeusia', system_version=None, value_set=None, value_set_version=None, tag=[])], text=\"pizza doesn't taste good anymore\")" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dgcc" + ] + }, + { + "cell_type": "markdown", + "id": "d4959472", + "metadata": {}, + "source": [ + "## TIme out\n", + "\n", + "- if a Coding is assigned to a `CodeableConcept`, it will require a `code` and a `system`, but those can be plain strings\n", + "- `Coding`s should be **appended** to `CodeableConcept`s.\n", + "- `CodeableConcept` doesn have subtypes, like CancerStageObservationTypeCodeableConcept\n" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "34566a8b", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.735030Z", + "start_time": "2021-11-18T19:42:41.730961Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['CodeableConcept']" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "crdch_view.class_descendants(\"CodeableConcept\")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "c7497881", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.738861Z", + "start_time": "2021-11-18T19:42:41.736283Z" + } + }, + "outputs": [], + "source": [ + "cso2 = ccdh.CancerStageObservation(observation_type=dgcc, value_codeable_concept=dgcc)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "e96651da", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.742943Z", + "start_time": "2021-11-18T19:42:41.740281Z" + } + }, + "outputs": [], + "source": [ + "# start over\n", + "csos2 = ccdh.CancerStageObservationSet()\n", + "csos2.observations.append(cso2)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "3a186d39", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.748393Z", + "start_time": "2021-11-18T19:42:41.744643Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "CancerStageObservationSet(id=None, category=None, focus=[], subject=None, method_type=[], performed_by=None, observations=[CancerStageObservation(observation_type=CodeableConcept(coding=[Coding(code='any text acceptable', system='not even a URL', label='dysgeusia', system_version=None, value_set=None, value_set_version=None, tag=[])], text=\"pizza doesn't taste good anymore\"), value_codeable_concept=CodeableConcept(coding=[Coding(code='any text acceptable', system='not even a URL', label='dysgeusia', system_version=None, value_set=None, value_set_version=None, tag=[])], text=\"pizza doesn't taste good anymore\"), id=None, category=None, method_type=None, focus=None, subject=None, performed_by=None, value_entity=None)])" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "csos2" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "9167e684", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.753094Z", + "start_time": "2021-11-18T19:42:41.749927Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{}\n", + "\n" + ] + } + ], + "source": [ + "csos_yaml = yaml_dumper.dumps(csos)\n", + "print(csos_yaml)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "2fad1fd0", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.762437Z", + "start_time": "2021-11-18T19:42:41.755484Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "observations:\n", + "- observation_type:\n", + " coding:\n", + " - code: any text acceptable\n", + " system: not even a URL\n", + " label: dysgeusia\n", + " text: pizza doesn't taste good anymore\n", + " value_codeable_concept:\n", + " coding:\n", + " - code: any text acceptable\n", + " system: not even a URL\n", + " label: dysgeusia\n", + " text: pizza doesn't taste good anymore\n", + "\n" + ] + } + ], + "source": [ + "csos2_yaml = yaml_dumper.dumps(csos2)\n", + "print(csos2_yaml)" + ] + }, + { + "cell_type": "markdown", + "id": "7a937306", + "metadata": {}, + "source": [ + "## Round trip:\n", + "Build a data object, convert to YAML (string or file) and then use that to recreate a new data object" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "c4a2f79d", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.767976Z", + "start_time": "2021-11-18T19:42:41.765124Z" + } + }, + "outputs": [], + "source": [ + "from linkml_runtime.loaders import yaml_loader\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "713556e9", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.774534Z", + "start_time": "2021-11-18T19:42:41.770005Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "CancerGradeObservationSet(id=None, category=None, focus=[], subject=None, method_type=[], performed_by=None, observations=[])" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "yaml_loader.load(csos_yaml, ccdh.CancerGradeObservationSet)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "f9907217", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:42:41.958623Z", + "start_time": "2021-11-18T19:42:41.776392Z" + } + }, + "outputs": [ + { + "ename": "TypeError", + "evalue": "unhashable type: 'CodeableConcept'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/var/folders/vt/f297tpjn6n1b6dwkcwhhnmxm0000gp/T/ipykernel_53165/3028925045.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0myaml_loader\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcsos2_yaml\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mccdh\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCancerGradeObservationSet\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m~/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages/linkml_runtime/loaders/yaml_loader.py\u001b[0m in \u001b[0;36mload\u001b[0;34m(self, source, target_class, base_dir, metadata, **_)\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mbase_dir\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mmetadata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbase_path\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 21\u001b[0m \u001b[0mmetadata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbase_path\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mbase_dir\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 22\u001b[0;31m return self.load_source(source, loader, target_class, accept_header=\"text/yaml, application/yaml;q=0.9\",\n\u001b[0m\u001b[1;32m 23\u001b[0m metadata=metadata)\n", + "\u001b[0;32m~/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages/linkml_runtime/loaders/loader_root.py\u001b[0m in \u001b[0;36mload_source\u001b[0;34m(self, source, loader, target_class, accept_header, metadata)\u001b[0m\n\u001b[1;32m 60\u001b[0m \u001b[0mdata_as_dict\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mloader\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmetadata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 61\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtarget_class\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata_as_dict\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata_as_dict\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\\\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 62\u001b[0;31m \u001b[0mtarget_class\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mas_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata_as_dict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mdata_as_dict\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 63\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 64\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mabstractmethod\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages/crdch_model/crdch_model.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, id, category, focus, subject, method_type, performed_by, observations, **kwargs)\u001b[0m\n", + "\u001b[0;32m~/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages/crdch_model/crdch_model.py\u001b[0m in \u001b[0;36m__post_init__\u001b[0;34m(self, *_, **kwargs)\u001b[0m\n\u001b[1;32m 336\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mperformed_by\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mOrganization\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mas_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mperformed_by\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 337\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 338\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_normalize_inlined_as_list\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mslot_name\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"observations\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslot_type\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mCancerGradeObservation\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey_name\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"observation_type\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeyed\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 339\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 340\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__post_init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages/linkml_runtime/utils/yamlutils.py\u001b[0m in \u001b[0;36m_normalize_inlined_as_list\u001b[0;34m(self, slot_name, slot_type, key_name, keyed)\u001b[0m\n\u001b[1;32m 95\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 96\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_normalize_inlined_as_list\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslot_name\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslot_type\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mType\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey_name\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeyed\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbool\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 97\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_normalize_inlined\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mslot_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslot_type\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeyed\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 98\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 99\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_normalize_inlined_as_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslot_name\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslot_type\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mType\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey_name\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeyed\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbool\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages/linkml_runtime/utils/yamlutils.py\u001b[0m in \u001b[0;36m_normalize_inlined\u001b[0;34m(self, slot_name, slot_type, key_name, keyed, is_list)\u001b[0m\n\u001b[1;32m 179\u001b[0m \u001b[0;31m# **kwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 180\u001b[0m \u001b[0mcooked_obj\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mslot_type\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mas_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlist_entry\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 181\u001b[0;31m \u001b[0morder_up\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcooked_obj\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey_name\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcooked_obj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 182\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlist_entry\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 183\u001b[0m \u001b[0;31m# *args\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/.local/share/virtualenvs/example-data-WqQDUTxX/lib/python3.9/site-packages/linkml_runtime/utils/yamlutils.py\u001b[0m in \u001b[0;36morder_up\u001b[0;34m(key, cooked_entry)\u001b[0m\n\u001b[1;32m 130\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mkeyed\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mkey\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mcooked_keys\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 131\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"{loc(key)}: duplicate key\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 132\u001b[0;31m \u001b[0mcooked_keys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 133\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mis_list\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 134\u001b[0m \u001b[0mcooked_slot\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcooked_entry\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mTypeError\u001b[0m: unhashable type: 'CodeableConcept'" + ] + } + ], + "source": [ + "yaml_loader.load(csos2_yaml, ccdh.CancerGradeObservationSet)" + ] + }, + { + "cell_type": "markdown", + "id": "9e0cb64c", + "metadata": {}, + "source": [ + "----" + ] + }, + { + "cell_type": "markdown", + "id": "812449d7", + "metadata": {}, + "source": [ + "- where can we learn about mappings like XXX?\n", + " - mappings within model\n", + " - terminology service" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "45d00df0", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:55:56.225641Z", + "start_time": "2021-11-18T19:55:56.222896Z" + } + }, + "outputs": [], + "source": [ + "def get_mapping_table(model_name, class_name, slot_name):\n", + " global global_mapping_table\n", + " current_url = f\"https://terminology.ccdh.io/models/{model_name}/entities/{class_name}/attributes/{slot_name}/mappings\"\n", + " response = requests.get(current_url)\n", + " resp_struct = response.json()\n", + " current_mappings = pd.DataFrame(resp_struct[\"mappings\"])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "514c4ca5", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:55:57.158770Z", + "start_time": "2021-11-18T19:55:56.999469Z" + } + }, + "outputs": [], + "source": [ + "mapping_res = get_mapping_table(\"CRDC-H\",\"BodySite\",\"site\")" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "bad41335", + "metadata": { + "ExecuteTime": { + "end_time": "2021-11-18T19:55:58.087753Z", + "start_time": "2021-11-18T19:55:58.084905Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n" + ] + } + ], + "source": [ + "print(mapping_res)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "873e57c1", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.8" + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}