15.2.612. camcops_server.tools.fetch_snomed_codes

camcops_server/tools/fetch_snomed_codes.py


Copyright (C) 2012, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).

This file is part of CamCOPS.

CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.


Assists a user who has the necessary permission to look up SNOMED CT identifiers from a SNOMED server (e.g. of their national provider).

References:

exception camcops_server.tools.fetch_snomed_codes.ConceptNotFound[source]
class camcops_server.tools.fetch_snomed_codes.SnomedApiInfo(base_url: str = 'https://termbrowser.nhs.uk/sct-browser-api/snomed', edition: str = 'uk-edition', release: str = 'v20210929', language: str = 'english', rate_limit_hz: float = 1, json_indent: int = 4, json_sort_keys: bool = True)[source]

Represents information about a SNOMED API.

__init__(base_url: str = 'https://termbrowser.nhs.uk/sct-browser-api/snomed', edition: str = 'uk-edition', release: str = 'v20210929', language: str = 'english', rate_limit_hz: float = 1, json_indent: int = 4, json_sort_keys: bool = True) None[source]
Parameters
  • base_url – REST API server base URL

  • edition – SNOMED CT edition

  • release – SNOMED CT release (version)

  • language – language to use

  • rate_limit_hz – maximum request rate

  • json_indent – cosmetic: indent for JSON formatting

  • json_sort_keys – cosmetic: sort keys for JSON formatting?

format_json(json_object: Union[str, int, float, bool, None, Dict, List]) str[source]

Pretty-formats a JSON object and returns it as a string.

get_concept_by_id(sctid: Union[int, str]) cardinal_pythonlib.snomed.SnomedConcept[source]

Finds a concept by identifer a SNOMED API provider. You must be entitled to use information from that provider.

Parameters

sctid – SNOMED CT identifier (in string format)

Returns

a SnomedConcept

Raises

ConceptNotFound

get_concept_by_term(term: str, semantic_area: Optional[str] = None, suffix: str = '', limit: int = 1000) cardinal_pythonlib.snomed.SnomedConcept[source]

Finds a concept by name from a SNOMED API provider. You must be entitled to use information from that provider.

Parameters
  • term – SNOMED CT term name

  • semantic_area – SNOMED CT semantic area

  • suffix – special suffix: search without it, match with it

  • limit – maximum number of hits per search (if you don’t specify, you’ll get a default of 100, at least in the NHS)

Returns

a SnomedConcept

Raises

ConceptNotFound

camcops_server.tools.fetch_snomed_codes.disclaim(question: str, required_answer: str) None[source]

Requires the user to agree to a statement. If they don’t, the program exits.

Parameters
  • question – question to be printed

  • required_answer – answer that is required

camcops_server.tools.fetch_snomed_codes.fetch_camcops_snomed_codes(api: camcops_server.tools.fetch_snomed_codes.SnomedApiInfo, filename: str, continue_on_error: bool = False) None[source]

Prints XML to stdout.

Parameters
  • api – a SnomedApiInfo.

  • filename – name of XML file to write

  • continue_on_error – carry on through failed lookups?

camcops_server.tools.fetch_snomed_codes.get_xml(camcops_name: str, concept: cardinal_pythonlib.snomed.SnomedConcept) str[source]

Returns XML representing this concept.

Parameters
  • camcops_name – CamCOPS name for the concept

  • concept – SNOMED CT concept

Returns

the XML

Return type

str

camcops_server.tools.fetch_snomed_codes.test_api(api: camcops_server.tools.fetch_snomed_codes.SnomedApiInfo, concept_ids: Optional[List[int]] = None, terms: Optional[List[str]] = None, semantic_area: Optional[str] = None) None[source]

Examples as per https://confluence.ihtsdotools.org/display/DOCSTART/4.+SNOMED+CT+Basics

Parameters
  • api – a SnomedApiInfo.

  • concept_ids – optional list of concept IDs to test

  • terms – optional list of terms to test

  • semantic_area – optional single semantic area to restrict to