diff --git a/CodeSystem.ipynb b/CodeSystem.ipynb index 464a272..86c71d1 100644 --- a/CodeSystem.ipynb +++ b/CodeSystem.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": 141, + "execution_count": 34, "id": "3c144a36-117c-42a0-9109-df73433e8267", "metadata": { "scrolled": false @@ -57,6 +57,7 @@ " end=\" \")\n", " print(\"id: \" + response_dict['entry'][0]['resource']['id'])\n", " print(\"url: \" + response_dict['entry'][0]['resource']['url'])\n", + " print(\"full url: \" + response_dict['entry'][0]['fullUrl'])\n", " if len(response_dict['entry']) > 1 :\n", " print(\"identifier system:\\\"\" + response_dict['entry'][1]['resource']['identifier'][0]['system'],\n", " end=\"\\\", \")\n", @@ -65,21 +66,38 @@ " print(\"?? no 2nd entry for resource identifier\")\n", " else:\n", " print(\"Not Present\")\n", - " print(\"\") \n" + " print(\"\") \n", + "\n", + "def decode_validate_response(repsonse) :\n", + " print(response)\n", + " if False:\n", + " print(response.keys())\n", + " print(response['issue']['severity'])\n", + " print(response['issue']['response'])\n", + " display(HTML(response['text']['div']))\n", + " print(\"\")\n", + " \n", + "def decode_lookup_response(response):\n", + " if (not decode_status(response)) :\n", + " response_dict = json.loads(response.text)\n", + " for p in response_dict['parameter']:\n", + " if p['name'] != 'property' and p['name'] != 'designation':\n", + " if 'valueString' in p:\n", + " print(p['name'], \":\", p['valueString'], sep=\"\", end=\", \")\n", + " if 'valueBoolean' in p:\n", + " print(p['name'], \":\", p['valueBoolean'], sep=\"\", end=\", \")\n", + " print(\"\")\n", + " else:\n", + " print(\"error\")\n", + " print(\"\")" ] }, { - "cell_type": "code", - "execution_count": 98, - "id": "7e17ea92", + "cell_type": "markdown", + "id": "9f7ba3f7", "metadata": {}, - "outputs": [], "source": [ - "## Test Infrastructure\n", - "search\n", - "$lookup\n", - "$validate-code\n", - "$subsumes" + "# Vocabulary loads not shown here" ] }, { @@ -94,7 +112,7 @@ }, { "cell_type": "code", - "execution_count": 216, + "execution_count": 41, "id": "8add4061", "metadata": {}, "outputs": [ @@ -207,7 +225,6 @@ } ], "source": [ - " \n", "response = do_hapi_request(\"/CodeSystem/\", {}) \n", "if (not decode_status(response)) :\n", " response_dict = json.loads(response.text)\n", @@ -230,7 +247,7 @@ }, { "cell_type": "code", - "execution_count": 228, + "execution_count": 21, "id": "61627370", "metadata": {}, "outputs": [ @@ -242,8 +259,29 @@ "title:Logical Observation Identifiers, Names and Codes (LOINC)\n", "resourceType: CodeSystem id: v3-loinc\n", "url: http://loinc.org\n", + "full url: http://localhost:8088/fhir/CodeSystem/v3-loinc\n", "identifier system:\"urn:ietf:rfc:3986\", value: \"urn:oid:2.16.840.1.113883.6.1\"\n", - "\n", + "\n" + ] + } + ], + "source": [ + "response = do_hapi_request(\"/CodeSystem/\", {\n", + " 'system' : 'http://loinc.org'}) \n", + "if (not decode_status(response)) :\n", + " decode_code_system_json(response)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "d8c04484", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ "http://localhost:8088/fhir/CodeSystem/?system=v3-loinc\n", "Not Present\n", "\n", @@ -252,12 +290,6 @@ } ], "source": [ - "# works\n", - "response = do_hapi_request(\"/CodeSystem/\", {\n", - " 'system' : 'http://loinc.org'}) \n", - "if (not decode_status(response)) :\n", - " decode_code_system_json(response)\n", - "\n", "# fails\n", "response = do_hapi_request(\"/CodeSystem/\", {\n", " 'system' : 'v3-loinc'})\n", @@ -267,41 +299,82 @@ ] }, { - "cell_type": "markdown", - "id": "bdaeb50d", + "cell_type": "code", + "execution_count": 24, + "id": "1fa2396d", "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://localhost:8088/fhir/CodeSystem/?system=http%3A%2F%2Fsnomed.org\n", + "Not Present\n", + "\n" + ] + } + ], "source": [ - "### CodeSystem search - check specific vocabularies are loaded" + "response = do_hapi_request(\"/CodeSystem/\", {'system' : 'http://snomed.org'}) \n", + "decode_code_system_json(response)" ] }, { "cell_type": "code", - "execution_count": 229, - "id": "45afcc95", + "execution_count": 25, + "id": "23b3680d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "http://localhost:8088/fhir/CodeSystem/?system=http%3A%2F%2Floinc.org\n", - "title:Logical Observation Identifiers, Names and Codes (LOINC)\n", - "resourceType: CodeSystem id: v3-loinc\n", - "url: http://loinc.org\n", - "identifier system:\"urn:ietf:rfc:3986\", value: \"urn:oid:2.16.840.1.113883.6.1\"\n", - "\n", - "http://localhost:8088/fhir/CodeSystem/?system=http%3A%2F%2Fsnomed.org\n", - "Not Present\n", - "\n", "http://localhost:8088/fhir/CodeSystem/?system=http%3A%2F%2Fwww.ama-assn.org%2Fgo%2Fcpt\n", "title:Current Procedural Terminology (CPT®)\n", "resourceType: CodeSystem id: CPT\n", "url: http://www.ama-assn.org/go/cpt\n", + "full url: http://localhost:8088/fhir/CodeSystem/CPT\n", "?? no 2nd entry for resource identifier\n", - "\n", + "\n" + ] + } + ], + "source": [ + "response = do_hapi_request(\"/CodeSystem/\", {'system' : 'http://www.ama-assn.org/go/cpt'}) \n", + "decode_code_system_json(response)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "8d98ffe4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ "http://localhost:8088/fhir/CodeSystem/?system=http%3A%2F%2Fhpo.org\n", "Not Present\n", - "\n", + "\n" + ] + } + ], + "source": [ + "response = do_hapi_request(\"/CodeSystem/\", {'system' : 'http://hpo.org'}) \n", + "decode_code_system_json(response)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "e2933784", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ "http://localhost:8088/fhir/CodeSystem/?system=http%3A%2F%2FICD10CM.org\n", "Not Present\n", "\n" @@ -309,22 +382,8 @@ } ], "source": [ - "response = do_hapi_request(\"/CodeSystem/\", {'system' : 'http://loinc.org'}) \n", - "decode_code_system_json(response)\n", - "\n", - "response = do_hapi_request(\"/CodeSystem/\", {'system' : 'http://snomed.org'}) \n", - "decode_code_system_json(response)\n", - "\n", - "response = do_hapi_request(\"/CodeSystem/\", {'system' : 'http://www.ama-assn.org/go/cpt'}) \n", - "decode_code_system_json(response)\n", - "\n", - "response = do_hapi_request(\"/CodeSystem/\", {'system' : 'http://hpo.org'}) \n", - "decode_code_system_json(response)\n", - "\n", - "# ICD-10CM ??\n", "response = do_hapi_request(\"/CodeSystem/\", {'system' : 'http://ICD10CM.org'}) \n", - "decode_code_system_json(response)\n", - "\n" + "decode_code_system_json(response)" ] }, { @@ -337,7 +396,7 @@ }, { "cell_type": "code", - "execution_count": 224, + "execution_count": 42, "id": "a7f9ac11", "metadata": {}, "outputs": [ @@ -346,43 +405,34 @@ "output_type": "stream", "text": [ "http://localhost:8088/fhir/CodeSystem/v3-loinc/$validate-code?code=69551-0\n", - "\n", - "http://localhost:8088/fhir/CodeSystem/v3-loinc/$validate-code?codeSystem=http%3A%2F%2Floinc.org&code=69551-0\n", - "\n", - "http://localhost:8088/fhir/CodeSystem/v3-loinc/$validate-code?codeSystem=http%3A%2F%2FBOGUS.org&code=69551-0\n", - "\n", - "http://localhost:8088/fhir/CodeSystem/v3-loinc/$validate-code?code=LA6668-3\n", - "\n", - "http://localhost:8088/fhir/CodeSystem/$validate-code/?codeSystem=http%3A%2F%2Floinc.org&code=69551-0\n", - "\n", - "\n", - "http://localhost:8088/fhir/CodeSystem/$validate-code/?codeSystem=v3-loinc&code=69551-0\n", - "\n", - "\n" + "\n" ] } ], "source": [ - "def decode_validate_response(repsonse) :\n", - " print(response)\n", - " if False:\n", - " print(response.keys())\n", - " print(response['issue']['severity'])\n", - " print(response['issue']['response'])\n", - " display(HTML(response['text']['div']))\n", - " print(\"\")\n", - "\n", - "# with id \n", "response = do_hapi_request(\"/CodeSystem/v3-loinc/$validate-code\", {\n", - "# 'codeSystem' : 'http://loinc.org',\n", " 'code' : '69551-0'})\n", "if (not decode_status(response)) :\n", " response_dict = json.loads(response.text)\n", - " decode_validate_response(response_dict)\n", - "else:\n", - " print(response, end=\"\\n\\n\")\n", - " \n", - "# with id and codeSystem\n", + " decode_validate_response(response_dict)" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "79458c0c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://localhost:8088/fhir/CodeSystem/v3-loinc/$validate-code?codeSystem=http%3A%2F%2Floinc.org&code=69551-0\n", + "\n" + ] + } + ], + "source": [ "response = do_hapi_request(\"/CodeSystem/v3-loinc/$validate-code\", {\n", " 'codeSystem' : 'http://loinc.org',\n", " 'code' : '69551-0'})\n", @@ -390,27 +440,51 @@ " response_dict = json.loads(response.text)\n", " decode_validate_response(response_dict)\n", "else:\n", - " print(response, end=\"\\n\\n\")\n", - " \n", - "# with id and conflicting codeSystem: INTERESTING, codeSystem must be ignored.\n", - "response = do_hapi_request(\"/CodeSystem/v3-loinc/$validate-code\", {\n", - " 'codeSystem' : 'http://BOGUS.org',\n", - " 'code' : '69551-0'})\n", - "if (not decode_status(response)) :\n", - " response_dict = json.loads(response.text)\n", - " decode_validate_response(response_dict)\n", - "else:\n", - " print(response, end=\"\\n\\n\")\n", - " \n", + " print(response, end=\"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "6f5d6013", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://localhost:8088/fhir/CodeSystem/v3-loinc/$validate-code?code=LA6668-3\n", + "\n" + ] + } + ], + "source": [ "response = do_hapi_request(\"/CodeSystem/v3-loinc/$validate-code\", {\n", " 'code' : 'LA6668-3'})\n", "if (not decode_status(response)) :\n", " response_dict = json.loads(response.text)\n", " decode_validate_response(response_dict)\n", "else:\n", - " print(response, end=\"\\n\\n\")\n", - " \n", - "# with codeSystem parameter only, fails\n", + " print(response, end=\"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "4b15eb19", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://localhost:8088/fhir/CodeSystem/$validate-code/?codeSystem=http%3A%2F%2Floinc.org&code=69551-0\n", + "\n", + "\n" + ] + } + ], + "source": [ "response = do_hapi_request(\"/CodeSystem/$validate-code/\", {\n", " 'codeSystem' : 'http://loinc.org',\n", " 'code' : '69551-0'})\n", @@ -418,8 +492,26 @@ " response_dict = json.loads(response.text)\n", " decode_validate_response(response_dict)\n", "else:\n", - " print(response, end=\"\\n\\n\")\n", - " \n", + " print(response, end=\"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "747397e0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://localhost:8088/fhir/CodeSystem/$validate-code/?codeSystem=v3-loinc&code=69551-0\n", + "\n", + "\n" + ] + } + ], + "source": [ "# with codeSystem parameter only, fails\n", "response = do_hapi_request(\"/CodeSystem/$validate-code/\", {\n", " 'codeSystem' : 'v3-loinc',\n", @@ -441,7 +533,7 @@ }, { "cell_type": "code", - "execution_count": 208, + "execution_count": 52, "id": "bd6f2b99", "metadata": {}, "outputs": [ @@ -451,65 +543,126 @@ "text": [ "http://localhost:8088/fhir/CodeSystem/$lookup?system=http%3A%2F%2Fbogus.org&code=LA6668-3\n", "error\n", - "\n", - "http://localhost:8088/fhir/CodeSystem/$lookup?system=http%3A%2F%2Floinc.org&code=bogus\n", - "error\n", - "\n", - "http://localhost:8088/fhir/CodeSystem/$lookup?system=http%3A%2F%2Floinc.org&code=LA6668-3\n", - "name:LOINC, display:Pathogenic, abstract:False, \n", - "\n", - "http://localhost:8088/fhir/CodeSystem/$lookup?system=http%3A%2F%2Floinc.org&code=LA9633-4\n", - "name:LOINC, display:Present, abstract:False, \n", - "\n", - "http://localhost:8088/fhir/CodeSystem/$lookup?system=http%3A%2F%2Floinc.org&code=69547-8\n", - "name:LOINC, display:Genomic ref allele [ID], abstract:False, \n", - "\n", - "http://localhost:8088/fhir/CodeSystem/$lookup?system=http%3A%2F%2Floinc.org&code=69551-0\n", - "name:LOINC, display:Genomic alt allele [ID], abstract:False, \n", "\n" ] } ], "source": [ - "def decode_lookup_response(response):\n", - " if (not decode_status(response)) :\n", - " response_dict = json.loads(response.text)\n", - " for p in response_dict['parameter']:\n", - " if p['name'] != 'property' and p['name'] != 'designation':\n", - " if 'valueString' in p:\n", - " print(p['name'], \":\", p['valueString'], sep=\"\", end=\", \")\n", - " if 'valueBoolean' in p:\n", - " print(p['name'], \":\", p['valueBoolean'], sep=\"\", end=\", \")\n", - " print(\"\")\n", - " else:\n", - " print(\"error\")\n", - " print(\"\")\n", - "\n", "response = do_hapi_request(\"/CodeSystem/$lookup\", {\n", " 'system' : 'http://bogus.org',\n", " 'code' : 'LA6668-3'}) \n", - "decode_lookup_response(response)\n", - "\n", + "decode_lookup_response(response)" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "e7dafe90", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://localhost:8088/fhir/CodeSystem/$lookup?system=http%3A%2F%2Floinc.org&code=bogus\n", + "error\n", + "\n" + ] + } + ], + "source": [ "response = do_hapi_request(\"/CodeSystem/$lookup\", {\n", " 'system' : 'http://loinc.org',\n", " 'code' : 'bogus'}) \n", - "decode_lookup_response(response)\n", - "\n", + "decode_lookup_response(response)" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "id": "c2aad8e4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://localhost:8088/fhir/CodeSystem/$lookup?system=http%3A%2F%2Floinc.org&code=LA6668-3\n", + "name:LOINC, display:Pathogenic, abstract:False, \n", + "\n" + ] + } + ], + "source": [ "response = do_hapi_request(\"/CodeSystem/$lookup\", {\n", " 'system' : 'http://loinc.org',\n", " 'code' : 'LA6668-3'}) \n", - "decode_lookup_response(response)\n", - "\n", + "decode_lookup_response(response)" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "4fa06697", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://localhost:8088/fhir/CodeSystem/$lookup?system=http%3A%2F%2Floinc.org&code=LA9633-4\n", + "name:LOINC, display:Present, abstract:False, \n", + "\n" + ] + } + ], + "source": [ "response = do_hapi_request(\"/CodeSystem/$lookup\", {\n", " 'system' : 'http://loinc.org',\n", " 'code' : 'LA9633-4'}) \n", - "decode_lookup_response(response)\n", - " \n", + "decode_lookup_response(response)" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "53214419", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://localhost:8088/fhir/CodeSystem/$lookup?system=http%3A%2F%2Floinc.org&code=69547-8\n", + "name:LOINC, display:Genomic ref allele [ID], abstract:False, \n", + "\n" + ] + } + ], + "source": [ "response = do_hapi_request(\"/CodeSystem/$lookup\", {\n", " 'system' : 'http://loinc.org',\n", " 'code' : '69547-8'})\n", - "decode_lookup_response(response)\n", - " \n", + "decode_lookup_response(response)" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "4f4888fa", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://localhost:8088/fhir/CodeSystem/$lookup?system=http%3A%2F%2Floinc.org&code=69551-0\n", + "name:LOINC, display:Genomic alt allele [ID], abstract:False, \n", + "\n" + ] + } + ], + "source": [ "response = do_hapi_request(\"/CodeSystem/$lookup\", {\n", " 'system' : 'http://loinc.org',\n", " 'code' : '69551-0'}) \n", @@ -534,6 +687,18 @@ "\n", "# T B D\n" ] + }, + { + "cell_type": "markdown", + "id": "d08c6297", + "metadata": {}, + "source": [ + "# What else?\n", + "- search for concept by name, or pattern\n", + "- modify concept? (no)\n", + "- hierarchy closure, synonym closure\n", + "- more" + ] } ], "metadata": {