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

[pull] master from CogStack:master #283

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 196 additions & 73 deletions notebook_docs/API_Examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import requests\n",
Expand All @@ -26,7 +28,9 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"URL = 'http://localhost:8001' # Should be set to your running deployment, IP / PORT if not running on localhost:8001"
Expand All @@ -45,7 +49,9 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"ortho_notes = pd.read_csv('example_data/ortho.csv')\n",
Expand All @@ -63,22 +69,24 @@
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"execution_count": 18,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'Authorization': 'Token cc3e60dd2cc4231f7f74d1f30d35ce31d3154f7c'}"
"{'Authorization': 'Token dece457ae382482d9edc999fdbf37dd39ea2893c'}"
]
},
"execution_count": 4,
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"payload = {\"username\": \"admin\", \"password\": \"admin\"}\n",
"payload = {\"username\": \"test\", \"password\": \"foobar312$\"}\n",
"headers = {\n",
" 'Authorization': f'Token {json.loads(requests.post(\"http://localhost:8001/api/api-token-auth/\", json=payload).text)[\"token\"]}',\n",
"}\n",
Expand All @@ -95,15 +103,18 @@
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"execution_count": 19,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'users': 'http://localhost:8001/api/users/',\n",
" 'entities': 'http://localhost:8001/api/entities/',\n",
" 'project-annotate-entities': 'http://localhost:8001/api/project-annotate-entities/',\n",
" 'project-groups': 'http://localhost:8001/api/project-groups/',\n",
" 'documents': 'http://localhost:8001/api/documents/',\n",
" 'annotated-entities': 'http://localhost:8001/api/annotated-entities/',\n",
" 'meta-annotations': 'http://localhost:8001/api/meta-annotations/',\n",
Expand All @@ -113,12 +124,10 @@
" 'entity-relations': 'http://localhost:8001/api/entity-relations/',\n",
" 'concept-dbs': 'http://localhost:8001/api/concept-dbs/',\n",
" 'vocabs': 'http://localhost:8001/api/vocabs/',\n",
" 'datasets': 'http://localhost:8001/api/datasets/',\n",
" 'icd-codes': 'http://localhost:8001/api/icd-codes/',\n",
" 'opcs-codes': 'http://localhost:8001/api/opcs-codes/'}"
" 'datasets': 'http://localhost:8001/api/datasets/'}"
]
},
"execution_count": 5,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -143,63 +152,21 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"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></th>\n",
" <th>name</th>\n",
" <th>text</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Subject 7</td>\n",
" <td>EXAM:,MRI LEFT KNEE WITHOUT CONTRAST,CLINICAL:...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Subject 7</td>\n",
" <td>REASON FOR CONSULTATION: , Left hip fracture.,...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Subject 7</td>\n",
" <td>REASON FOR CONSULTATION: , Left hip fracture.,...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" name text\n",
"0 Subject 7 EXAM:,MRI LEFT KNEE WITHOUT CONTRAST,CLINICAL:...\n",
"1 Subject 7 REASON FOR CONSULTATION: , Left hip fracture.,...\n",
"2 Subject 7 REASON FOR CONSULTATION: , Left hip fracture.,..."
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
"ename": "AttributeError",
"evalue": "'DataFrame' object has no attribute 'subject_id'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/tmp/ipykernel_10318/6590849.py\u001b[0m in \u001b[0;36m?\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Add a name column to the other datasets\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mortho_notes\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'name'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mortho_notes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msubject_id\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0ml\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34mf'Subject {l}'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mneuro_notes\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'name'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mneuro_notes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msubject_id\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0ml\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34mf'Subject {l}'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mcardio_notes\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'name'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcardio_notes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msubject_id\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0ml\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34mf'Subject {l}'\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 5\u001b[0m \u001b[0mortho_notes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'name'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'text'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhead\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/miniconda3/envs/cattrainer/lib/python3.11/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m?\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 6200\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mname\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_accessors\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6201\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_can_hold_identifiers_and_holds_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6202\u001b[0m ):\n\u001b[1;32m 6203\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 6204\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'subject_id'"
]
}
],
"source": [
Expand All @@ -213,7 +180,9 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Collate datasets, with Names\n",
Expand Down Expand Up @@ -257,17 +226,171 @@
"#### Upload a CDB"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"total 4020900\n",
"drwxrwxr-x 6 cerberus cerberus 4096 Jan 17 2024 20230227__kch_gstt_trained_model_494c3717f637bb89\n",
"-rw-rw-r-- 1 cerberus cerberus 954511008 Jan 17 2024 20230227__kch_gstt_trained_model_494c3717f637bb89.zip\n",
"-rw-r--r-- 1 cerberus cerberus 392429568 Jan 5 2024 cdb.dat\n",
"-rw-r--r-- 1 cerberus cerberus 607359360 Jun 7 2023 cdb-medmen.dat\n",
"drwxrwxr-x 4 cerberus cerberus 4096 Feb 8 2024 deid_medcat_n2c2_modelpack\n",
"-rw-r--r-- 1 cerberus cerberus 487520245 Feb 8 2024 deid_medcat_n2c2_modelpack.zip\n",
"-rw-r--r-- 1 cerberus cerberus 181988 Jan 5 2024 icd_11_cbd_utf8.dat\n",
"drwxrwxr-x 6 cerberus cerberus 4096 Feb 22 2024 medcat_model_pack_v1.4.0\n",
"-rw-rw-r-- 1 cerberus cerberus 841304525 Jan 5 2024 medcat_model_pack_v1.4.0.zip\n",
"-rw-r--r-- 1 cerberus cerberus 223 Jan 5 2024 pain_custom_cdb.dat\n",
"-rw-r--r-- 1 cerberus cerberus 25599 Jan 5 2024 pain_term.dat\n",
"-rw-r--r-- 1 cerberus cerberus 772635 Jan 5 2024 rxnorm_analgesic_cbd_utf8.dat\n",
"-rw-r--r-- 1 cerberus cerberus 362697 Jan 5 2024 rxnorm_analgesic_cbd_utf8_Y2VYjZO.dat\n",
"-rw-r--r-- 1 cerberus cerberus 832849835 Jan 5 2024 rxnorm_cdb.dat\n",
"-rw-rw-r-- 1 cerberus cerberus 21316 Aug 22 16:43 Untitled.ipynb\n"
]
}
],
"source": [
"!ls -l ../../medcat-models/cdb-medmen.dat"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from medcat.cdb import CDB"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"<medcat.cdb.CDB at 0x704e66be4050>"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"CDB.load('../../medcat-models/deid_medcat_n2c2_modelpack/cdb.dat')"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"txt = json.loads(requests.post(f'{URL}/api/concept-dbs/', headers=headers, \n",
" data={'name': 'example_cdb', 'use_for_training': True}, \n",
" files={'cdb_file': open('../../medcat-models/deid_medcat_n2c2_modelpack/cdb.dat', 'rb')}).text)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'id': 21,\n",
" 'name': 'example_cdb',\n",
" 'cdb_file': 'http://localhost:8001/media/cdb_HjbPPUI.dat',\n",
" 'use_for_training': True,\n",
" 'create_time': '2024-09-20T21:07:03.062580Z',\n",
" 'last_modified': '2024-09-20T21:07:03.062610Z',\n",
" 'last_modified_by': 1}"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"txt"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"txt = json.loads(requests.put(f'{URL}/api/concept-dbs/21/', headers=headers, \n",
" data={'name': 'example_cdb-EDITED', 'use_for_training': True}, \n",
" files={'cdb_file': open('../../medcat-models/deid_medcat_n2c2_modelpack/cdb.dat', 'rb')}).text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"{'id': 21,\n",
" 'name': 'example_cdb',\n",
" 'cdb_file': 'http://localhost:8001/media/cdb_HjbPPUI.dat',\n",
" 'use_for_training': True,\n",
" 'create_time': '2024-09-20T21:07:03.062580Z',\n",
" 'last_modified': '2024-09-20T21:07:03.062610Z',\n",
" 'last_modified_by': 1}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"txt = json.loads(requests.post(f'{URL}/api/concept-dbs/', headers=headers, \n",
"requests.post(f'{URL}/api/concept-dbs/', headers=headers, \n",
" data={'name': 'example_cdb', 'use_for_training': True}, \n",
" files={'cdb_file': open('<<LOCATION OF CDB>>', 'rb')}).text)"
" files={'cdb_file': open('../../medcat-models/deid_medcat_n2c2_modelpack/cdb.dat', 'rb')}).text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -442,7 +565,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
11 changes: 3 additions & 8 deletions webapp/frontend/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
[*.{js,jsx,ts,tsx,vue}]
indent_style = space
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue}]
charset = utf-8
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
trim_trailing_whitespace = true
1 change: 0 additions & 1 deletion webapp/frontend/.env

This file was deleted.

Loading
Loading