Looking up an SSYK-2012 code given a concept ID

A question was sent to us by the BÄR team, on how to lookup an SSYK-2012 code given a concept id. We post the response here in case anyone else has the same question in the future.

Here are two suggestions on how to do this.

The first way is to look up an individual code with a query. We will use prepare a Curl query from Bash, as it is a commonly used tool, and the logic should be clear enough to translate to any other programming language.

  1. Assign the clear text query to a variable:
QUERY='query MyQuery {   concepts(id: "yVZH_zHh_6fG") { ssyk_code_2012 } }'
  1. URL encode the query to make the special characters HTTP compatible:
URLENCODEDQUERY=$(echo "$QUERY" | perl -pe 's/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;')
  1. Have a look at the URL encoded representation of the query:
echo $URLENCODEDQUERY
query%20MyQuery%20%7B%20%20%20concepts%28id%3A%20%22yVZH_zHh_6fG%22%29%20%7B%20ssyk_code_2012%20%7D%20%7D%0A
  1. Send the query to the taxonomy graphql endpoint (for the T1 taxonomy test environment):
curl --silent "https://taxonomy-t1.api.jobtechdev.se/v1/taxonomy/graphql?query=$URLENCODEDQUERY" -H  "accept: application/json" | jq . 
{
  "data": {
    "concepts": [
      {
        "ssyk_code_2012": "3441"
      }
    ]
  }
}

The second way is an alternative to the approach above, where we looked up an individual code with a query. It is to use a ready made data file containing all mappings between SSYK-2012 (level 4) and concept ids. This file is automatically generated each night and published on our web site.
https://data.jobtechdev.se/taxonomy/SSYK_niv%C3%A5_fyra_med_relationer_till_yrkesben%C3%A4mningar/SSYK_niv%C3%A5_fyra_med_relationer_till_yrkesben%C3%A4mningar.json

There are more of those data files with other types of information - please browse this directory for yourself and see:
https://data.jobtechdev.se/taxonomy/