{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "c928623b",
   "metadata": {},
   "source": [
    "# Primary Care Medicines (PCM) Dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "71405ccc",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       ">Last modified: 03 Jul 2025"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import sys\n",
    "import os\n",
    "sys.path.append(os.path.abspath('../../../../scripts/'))\n",
    "from data_doc_helper import NHSEDataSet as DS, last_modified\n",
    "ds = DS(\"PCM\")\n",
    "last_modified()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "91b35815",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "<div style=\"background-color: rgba(0, 178, 169, 0.3); padding: 5px; border-radius: 5px;\"><strong>None</strong></div>"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ds.three_sec_summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7d719ca",
   "metadata": {},
   "source": [
    "## 1. Summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "31f20bc2",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ds.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8c00184b",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_427cc th {\n",
       "  text-align: left;\n",
       "}\n",
       "#T_427cc_row0_col0, #T_427cc_row0_col1, #T_427cc_row1_col0, #T_427cc_row1_col1, #T_427cc_row2_col0, #T_427cc_row2_col1, #T_427cc_row3_col0, #T_427cc_row3_col1, #T_427cc_row4_col0, #T_427cc_row4_col1, #T_427cc_row5_col0, #T_427cc_row5_col1, #T_427cc_row6_col0, #T_427cc_row6_col1, #T_427cc_row7_col0, #T_427cc_row7_col1, #T_427cc_row8_col0, #T_427cc_row8_col1, #T_427cc_row9_col0, #T_427cc_row9_col1, #T_427cc_row10_col0, #T_427cc_row10_col1, #T_427cc_row11_col0, #T_427cc_row11_col1, #T_427cc_row12_col0, #T_427cc_row12_col1, #T_427cc_row13_col0, #T_427cc_row13_col1, #T_427cc_row14_col0, #T_427cc_row14_col1 {\n",
       "  text-align: left;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_427cc\" style=\"font-size: 14px\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th id=\"T_427cc_level0_col0\" class=\"col_heading level0 col0\" >Dataset Descriptor</th>\n",
       "      <th id=\"T_427cc_level0_col1\" class=\"col_heading level0 col1\" >Dataset-specific Information</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row0_col0\" class=\"data row0 col0\" >Name of Dataset in TRE</td>\n",
       "      <td id=\"T_427cc_row0_col1\" class=\"data row0 col1\" >NHSE_PCM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row1_col0\" class=\"data row1 col0\" >Citation (APA)</td>\n",
       "      <td id=\"T_427cc_row1_col1\" class=\"data row1 col1\" >Data Services, NHS England (NHSE) . (2024). <i>NHS England: Primary Care Medicines (PCM).</i> UK Longitudinal Linkage Collaboration (UK LLC).  <a href=\"https://doi.org/10.83126/ukllc-dataset-00050-03\" rel=\"noopener noreferrer\" target=\"_blank\">https://doi.org/10.83126/ukllc-dataset-00050-03</a></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row2_col0\" class=\"data row2 col0\" >Download Citation</td>\n",
       "      <td id=\"T_427cc_row2_col1\" class=\"data row2 col1\" > <a href=\"https://api.datacite.org/application/vnd.citationstyles.csl+json/10.83126/ukllc-dataset-00050-03\" rel=\"noopener noreferrer\" target=\"_blank\">Citeproc JSON</a>&nbsp;&nbsp;&nbsp;&nbsp; <a href=\"https://api.datacite.org/application/x-bibtex/10.83126/ukllc-dataset-00050-03\" rel=\"noopener noreferrer\" target=\"_blank\">BibTeX</a>&nbsp;&nbsp;&nbsp;&nbsp; <a href=\"https://api.datacite.org/application/x-research-info-systems/10.83126/ukllc-dataset-00050-03\" rel=\"noopener noreferrer\" target=\"_blank\">RIS</a></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row3_col0\" class=\"data row3 col0\" >Series</td>\n",
       "      <td id=\"T_427cc_row3_col1\" class=\"data row3 col1\" > <a href=\"https://guidebook.ukllc.ac.uk/docs//linked_health_data/NHS_England/NHSE_intro\" rel=\"noopener noreferrer\" target=\"_blank\">NHS England</a></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row4_col0\" class=\"data row4 col0\" >Owner</td>\n",
       "      <td id=\"T_427cc_row4_col1\" class=\"data row4 col1\" >NHS England, Office for National Statistics and Department of Health and Social Care</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row5_col0\" class=\"data row5 col0\" >Temporal Coverage in the TRE</td>\n",
       "      <td id=\"T_427cc_row5_col1\" class=\"data row5 col1\" >04/2015 - ongoing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row6_col0\" class=\"data row6 col0\" >Geographical Coverage</td>\n",
       "      <td id=\"T_427cc_row6_col1\" class=\"data row6 col1\" >England</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row7_col0\" class=\"data row7 col0\" >Participant Count</td>\n",
       "      <td id=\"T_427cc_row7_col1\" class=\"data row7 col1\" >193008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row8_col0\" class=\"data row8 col0\" >Number of Variables</td>\n",
       "      <td id=\"T_427cc_row8_col1\" class=\"data row8 col1\" >57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row9_col0\" class=\"data row9 col0\" >Number of Observations</td>\n",
       "      <td id=\"T_427cc_row9_col1\" class=\"data row9 col1\" >32640281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row10_col0\" class=\"data row10 col0\" >Key Link</td>\n",
       "      <td id=\"T_427cc_row10_col1\" class=\"data row10 col1\" > <a href=\"https://digital.nhs.uk/data-and-information/data-tools-and-services/data-services/medicines-dispensed-in-primary-care-nhsbsa-data\" rel=\"noopener noreferrer\" target=\"_blank\">https://digital.nhs.uk/data-and-information/data-tools-and-services/data-services/medicines-dispensed-in-primary-care-nhsbsa-data</a></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row11_col0\" class=\"data row11 col0\" >Keywords</td>\n",
       "      <td id=\"T_427cc_row11_col1\" class=\"data row11 col1\" >Medicines, Prescriptions</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row12_col0\" class=\"data row12 col0\" >Latest Extract Date</td>\n",
       "      <td id=\"T_427cc_row12_col1\" class=\"data row12 col1\" >2024-04-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row13_col0\" class=\"data row13 col0\" >Specific Restrictions to Data Use</td>\n",
       "      <td id=\"T_427cc_row13_col1\" class=\"data row13 col1\" >Research must have a focus on the safety and effectiveness of medicines as specified by the NHSBSA Medicines Data Directions: https://digital.nhs.uk/about-nhs-digital/corporate-information-and-documents/directions-and-data-provision-notices/secretary-of-state-directions/nhs-business-services-authority-nhsbsa-medicines-data-directions-2019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td id=\"T_427cc_row14_col0\" class=\"data row14 col0\" >Build a Data Request</td>\n",
       "      <td id=\"T_427cc_row14_col1\" class=\"data row14 col1\" > <a href=\"https://explore.ukllc.ac.uk/\" rel=\"noopener noreferrer\" target=\"_blank\">https://explore.ukllc.ac.uk/</a></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x2a0906fe7b0>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ds.info_table()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebf55707",
   "metadata": {},
   "source": [
    "## 2. Metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "33994195",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "application/javascript": "'use strict';\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  const force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\nconst JS_MIME_TYPE = 'application/javascript';\n  const HTML_MIME_TYPE = 'text/html';\n  const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n  const CLASS_NAME = 'output_bokeh rendered_html';\n\n  /**\n   * Render data to the DOM node\n   */\n  function render(props, node) {\n    const script = document.createElement(\"script\");\n    node.appendChild(script);\n  }\n\n  /**\n   * Handle when an output is cleared or removed\n   */\n  function handleClearOutput(event, handle) {\n    function drop(id) {\n      const view = Bokeh.index.get_by_id(id)\n      if (view != null) {\n        view.model.document.clear()\n        Bokeh.index.delete(view)\n      }\n    }\n\n    const cell = handle.cell;\n\n    const id = cell.output_area._bokeh_element_id;\n    const server_id = cell.output_area._bokeh_server_id;\n\n    // Clean up Bokeh references\n    if (id != null) {\n      drop(id)\n    }\n\n    if (server_id !== undefined) {\n      // Clean up Bokeh references\n      const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n      cell.notebook.kernel.execute(cmd_clean, {\n        iopub: {\n          output: function(msg) {\n            const id = msg.content.text.trim()\n            drop(id)\n          }\n        }\n      });\n      // Destroy server and session\n      const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n      cell.notebook.kernel.execute(cmd_destroy);\n    }\n  }\n\n  /**\n   * Handle when a new output is added\n   */\n  function handleAddOutput(event, handle) {\n    const output_area = handle.output_area;\n    const output = handle.output;\n\n    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n    if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n      return\n    }\n\n    const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n\n    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n      // store reference to embed id on output_area\n      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n    }\n    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n      const bk_div = document.createElement(\"div\");\n      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n      const script_attrs = bk_div.children[0].attributes;\n      for (let i = 0; i < script_attrs.length; i++) {\n        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n      }\n      // store reference to server id on output_area\n      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n    }\n  }\n\n  function register_renderer(events, OutputArea) {\n\n    function append_mime(data, metadata, element) {\n      // create a DOM node to render to\n      const toinsert = this.create_output_subarea(\n        metadata,\n        CLASS_NAME,\n        EXEC_MIME_TYPE\n      );\n      this.keyboard_manager.register_events(toinsert);\n      // Render to node\n      const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n      render(props, toinsert[toinsert.length - 1]);\n      element.append(toinsert);\n      return toinsert\n    }\n\n    /* Handle when an output is cleared or removed */\n    events.on('clear_output.CodeCell', handleClearOutput);\n    events.on('delete.Cell', handleClearOutput);\n\n    /* Handle when a new output is added */\n    events.on('output_added.OutputArea', handleAddOutput);\n\n    /**\n     * Register the mime type and append_mime function with output_area\n     */\n    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n      /* Is output safe? */\n      safe: true,\n      /* Index of renderer in `output_area.display_order` */\n      index: 0\n    });\n  }\n\n  // register the mime type if in Jupyter Notebook environment and previously unregistered\n  if (root.Jupyter !== undefined) {\n    const events = require('base/js/events');\n    const OutputArea = require('notebook/js/outputarea').OutputArea;\n\n    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n      register_renderer(events, OutputArea);\n    }\n  }\n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  const NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded(error = null) {\n    const el = document.getElementById(null);\n    if (el != null) {\n      const html = (() => {\n        if (typeof root.Bokeh === \"undefined\") {\n          if (error == null) {\n            return \"BokehJS is loading ...\";\n          } else {\n            return \"BokehJS failed to load.\";\n          }\n        } else {\n          const prefix = `BokehJS ${root.Bokeh.version}`;\n          if (error == null) {\n            return `${prefix} successfully loaded.`;\n          } else {\n            return `${prefix} <b>encountered errors</b> while loading and may not function as expected.`;\n          }\n        }\n      })();\n      el.innerHTML = html;\n\n      if (error != null) {\n        const wrapper = document.createElement(\"div\");\n        wrapper.style.overflow = \"auto\";\n        wrapper.style.height = \"5em\";\n        wrapper.style.resize = \"vertical\";\n        const content = document.createElement(\"div\");\n        content.style.fontFamily = \"monospace\";\n        content.style.whiteSpace = \"pre-wrap\";\n        content.style.backgroundColor = \"rgb(255, 221, 221)\";\n        content.textContent = error.stack ?? error.toString();\n        wrapper.append(content);\n        el.append(wrapper);\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(() => display_loaded(error), 100);\n    }\n  }\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error(url) {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (let i = 0; i < css_urls.length; i++) {\n      const url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    for (let i = 0; i < js_urls.length; i++) {\n      const url = js_urls[i];\n      const element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.async = false;\n      element.src = url;\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-3.7.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.7.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.7.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.7.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-3.7.2.min.js\"];\n  const css_urls = [];\n\n  const inline_js = [    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\nfunction(Bokeh) {\n    }\n  ];\n\n  function run_inline_js() {\n    if (root.Bokeh !== undefined || force === true) {\n      try {\n            for (let i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n\n      } catch (error) {throw error;\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      const cell = $(document.getElementById(null)).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));",
      "application/vnd.bokehjs_load.v0+json": ""
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "Table 2: Please note, individual cohort counts of less than 10 are suppressed to 0 and are therefore excluded from total participant counts for datasets"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "  <div id=\"e8610284-d45c-4c19-9e72-104142c58733\" data-root-id=\"p1016\" style=\"display: contents;\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": "(function(root) {\n  function embed_document(root) {\n  const docs_json = {\"e6973bec-382c-4ca7-bd4b-ba3e6ba169e9\":{\"version\":\"3.7.2\",\"title\":\"Bokeh Application\",\"roots\":[{\"type\":\"object\",\"name\":\"DataCube\",\"id\":\"p1016\",\"attributes\":{\"source\":{\"type\":\"object\",\"name\":\"ColumnDataSource\",\"id\":\"p1001\",\"attributes\":{\"selected\":{\"type\":\"object\",\"name\":\"Selection\",\"id\":\"p1002\",\"attributes\":{\"indices\":[],\"line_indices\":[]}},\"selection_policy\":{\"type\":\"object\",\"name\":\"UnionRenderers\",\"id\":\"p1003\"},\"data\":{\"type\":\"map\",\"entries\":[[\"d0\",[\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\",\"PCM\"]],[\"d1\",[\"ALSPAC\",\"BCS70\",\"BIB\",\"ELSA\",\"EPICN\",\"EXCEED\",\"FENLAND\",\"GLAD\",\"MCS\",\"NCDS58\",\"NEXTSTEP\",\"NIHRBIO_COPING\",\"NSHD46\",\"TEDS\",\"TRACKC19\",\"TWINSUK\",\"UKHLS\"]],[\"px\",[5313,5360,24916,6890,14580,9112,9588,65930,16191,5856,4585,15568,2441,6931,12855,11423,6474]]]}}},\"view\":{\"type\":\"object\",\"name\":\"CDSView\",\"id\":\"p1020\",\"attributes\":{\"filter\":{\"type\":\"object\",\"name\":\"AllIndices\",\"id\":\"p1021\"}}},\"columns\":[{\"type\":\"object\",\"name\":\"TableColumn\",\"id\":\"p1008\",\"attributes\":{\"field\":\"d1\",\"title\":\"PCM Dataset\",\"width\":80,\"formatter\":{\"type\":\"object\",\"name\":\"StringFormatter\",\"id\":\"p1007\",\"attributes\":{\"font_style\":{\"type\":\"value\",\"value\":\"bold\"}}},\"editor\":{\"type\":\"object\",\"name\":\"StringEditor\",\"id\":\"p1010\"},\"sortable\":false}},{\"type\":\"object\",\"name\":\"TableColumn\",\"id\":\"p1011\",\"attributes\":{\"field\":\"px\",\"title\":\"Participant Count\",\"width\":40,\"formatter\":{\"type\":\"object\",\"name\":\"StringFormatter\",\"id\":\"p1012\"},\"editor\":{\"type\":\"object\",\"name\":\"StringEditor\",\"id\":\"p1013\"},\"sortable\":false}}],\"grouping\":[{\"type\":\"object\",\"name\":\"GroupingInfo\",\"id\":\"p1015\",\"attributes\":{\"getter\":\"d0\",\"aggregators\":[{\"type\":\"object\",\"name\":\"SumAggregator\",\"id\":\"p1014\",\"attributes\":{\"field_\":\"px\"}}]}}],\"target\":{\"type\":\"object\",\"name\":\"ColumnDataSource\",\"id\":\"p1004\",\"attributes\":{\"selected\":{\"type\":\"object\",\"name\":\"Selection\",\"id\":\"p1005\",\"attributes\":{\"indices\":[],\"line_indices\":[]}},\"selection_policy\":{\"type\":\"object\",\"name\":\"UnionRenderers\",\"id\":\"p1006\"},\"data\":{\"type\":\"map\",\"entries\":[[\"row_indices\",[]],[\"labels\",[]]]}}}}}]}};\n  const render_items = [{\"docid\":\"e6973bec-382c-4ca7-bd4b-ba3e6ba169e9\",\"roots\":{\"p1016\":\"e8610284-d45c-4c19-9e72-104142c58733\"},\"root_ids\":[\"p1016\"]}];\n  void root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n  }\n  if (root.Bokeh !== undefined) {\n    embed_document(root);\n  } else {\n    let attempts = 0;\n    const timer = setInterval(function(root) {\n      if (root.Bokeh !== undefined) {\n        clearInterval(timer);\n        embed_document(root);\n      } else {\n        attempts++;\n        if (attempts > 100) {\n          clearInterval(timer);\n          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n        }\n      }\n    }, 10, root)\n  }\n})(window);",
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "p1016"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "ds.metrics()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d7fecf8",
   "metadata": {},
   "source": [
    "## 3. Version History"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a176d142",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "application/vnd.microsoft.datawrangler.viewer.v0+json": {
       "columns": [
        {
         "name": "index",
         "rawType": "object",
         "type": "string"
        },
        {
         "name": "1",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "2",
         "rawType": "object",
         "type": "unknown"
        },
        {
         "name": "3",
         "rawType": "object",
         "type": "unknown"
        }
       ],
       "ref": "99bcc683-0034-4cf5-b7f1-9a56a97890a0",
       "rows": [
        [
         "Name in TRE",
         "NHSE_PCM",
         "NHSE_PCM",
         "NHSE_PCM"
        ],
        [
         "Version Date",
         "21 Dec 2022",
         "13 Apr 2023",
         "26 Apr 2024"
        ],
        [
         "Number of Variables",
         "57",
         "57",
         "57"
        ],
        [
         "Number of Rows",
         "19239373",
         "22859974",
         "32640281"
        ],
        [
         "DOI",
         "10.83126/ukllc-dataset-00050-01",
         "10.83126/ukllc-dataset-00050-02",
         "10.83126/ukllc-dataset-00050-03"
        ]
       ],
       "shape": {
        "columns": 3,
        "rows": 5
       }
      },
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>Version Number</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Name in TRE</th>\n",
       "      <td>NHSE_PCM</td>\n",
       "      <td>NHSE_PCM</td>\n",
       "      <td>NHSE_PCM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Version Date</th>\n",
       "      <td>21 Dec 2022</td>\n",
       "      <td>13 Apr 2023</td>\n",
       "      <td>26 Apr 2024</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Number of Variables</th>\n",
       "      <td>57</td>\n",
       "      <td>57</td>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Number of Rows</th>\n",
       "      <td>19239373</td>\n",
       "      <td>22859974</td>\n",
       "      <td>32640281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DOI</th>\n",
       "      <td>10.83126/ukllc-dataset-00050-01</td>\n",
       "      <td>10.83126/ukllc-dataset-00050-02</td>\n",
       "      <td>10.83126/ukllc-dataset-00050-03</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Version Number                                     1  \\\n",
       "Name in TRE                                 NHSE_PCM   \n",
       "Version Date                             21 Dec 2022   \n",
       "Number of Variables                               57   \n",
       "Number of Rows                              19239373   \n",
       "DOI                  10.83126/ukllc-dataset-00050-01   \n",
       "\n",
       "Version Number                                     2  \\\n",
       "Name in TRE                                 NHSE_PCM   \n",
       "Version Date                             13 Apr 2023   \n",
       "Number of Variables                               57   \n",
       "Number of Rows                              22859974   \n",
       "DOI                  10.83126/ukllc-dataset-00050-02   \n",
       "\n",
       "Version Number                                     3  \n",
       "Name in TRE                                 NHSE_PCM  \n",
       "Version Date                             26 Apr 2024  \n",
       "Number of Variables                               57  \n",
       "Number of Rows                              32640281  \n",
       "DOI                  10.83126/ukllc-dataset-00050-03  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ds.version_history()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12e6b815",
   "metadata": {},
   "source": [
    "## 4. Documentation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "02e29089",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "We are currently building a documentation storage system, which will host relevant and useful documents related to datasets, groupings, and studies themselves. Relevant documentation for this particular dataset will go here."
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ds.documentation()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ecce32ec",
   "metadata": {},
   "source": [
    "## 5. Useful Syntax"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ee22f894",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "Below we will include syntax that may be helpful to other researchers in the UK LLC TRE. For longer scripts, we will include a snippet of the code plus a link to Git where you can find the full script"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ds.useful_syntax()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "jupbook",
   "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.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}