{
  "$schema": "../cases.schema.json",
  "format": 1,
  "domain": "cid10",
  "title": {
    "en": "CID-10",
    "pt-BR": "CID-10"
  },
  "functions": [
    {
      "id": "cid10.format",
      "level": "extended",
      "summary": "Formats a CID-10 code.",
      "description": "Formats a CID-10 code the way it is printed: upper case, with a dot between the 3-character category and the fourth character (`A00.0`). Only the structure changes (use `cid10.isValid` to check the code).\n\n- The mask is applied as far as the value goes. A category stays without a dot (`A00`). The dot shows up with the fourth character.\n- Only the letters A to Z (any case) and the digits 0 to 9 are read; every other character is dropped, accented letters included. The result is capped at 4 characters plus the dot. The mask does not check which characters are letters and which are digits (`\"1234\"` gives `123.4`).\n- A value that is not a string returns an empty string.",
      "params": [
        {
          "name": "value",
          "type": "string"
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "cid10.format#[\"f322\"]",
          "args": [
            "f322"
          ],
          "expect": {
            "returns": "F32.2"
          },
          "note": "from the maintainer briefing, #568"
        },
        {
          "id": "cid10.format#[\"A000\"]",
          "args": [
            "A000"
          ],
          "expect": {
            "returns": "A00.0"
          },
          "note": "JavaScript's own test: should add the dot to a subcategory"
        },
        {
          "id": "cid10.format#[\"M545\"]",
          "args": [
            "M545"
          ],
          "expect": {
            "returns": "M54.5"
          },
          "note": "JavaScript's own test: should add the dot to a subcategory"
        },
        {
          "id": "cid10.format#already-formatted",
          "args": [
            "A00.0"
          ],
          "expect": {
            "returns": "A00.0"
          },
          "note": "JavaScript's own test: should keep a subcategory that already has the dot"
        },
        {
          "id": "cid10.format#[\"A00\"]",
          "args": [
            "A00"
          ],
          "expect": {
            "returns": "A00"
          },
          "note": "JavaScript's own test: should leave a category without a dot"
        },
        {
          "id": "cid10.format#[\"A00.\"]",
          "args": [
            "A00."
          ],
          "expect": {
            "returns": "A00"
          },
          "note": "JavaScript's own test: should leave a category without a dot"
        },
        {
          "id": "cid10.format#[\"A\"]",
          "args": [
            "A"
          ],
          "expect": {
            "returns": "A"
          },
          "note": "JavaScript's own test: should mask a partial value progressively"
        },
        {
          "id": "cid10.format#partial",
          "args": [
            "A0"
          ],
          "expect": {
            "returns": "A0"
          },
          "note": "JavaScript's own test: should mask a partial value progressively"
        },
        {
          "id": "cid10.format#[\" A-00/0 \"]",
          "args": [
            " A-00/0 "
          ],
          "expect": {
            "returns": "A00.0"
          },
          "note": "JavaScript's own test: should drop the characters outside the mask"
        },
        {
          "id": "cid10.format#[\"A00.01\"]",
          "args": [
            "A00.01"
          ],
          "expect": {
            "returns": "A00.0"
          },
          "note": "JavaScript's own test: should not add characters after the subcategory length"
        },
        {
          "id": "cid10.format#[\"A00012345\"]",
          "args": [
            "A00012345"
          ],
          "expect": {
            "returns": "A00.0"
          },
          "note": "JavaScript's own test: should not add characters after the subcategory length"
        },
        {
          "id": "cid10.format#[\"Z999\"]",
          "args": [
            "Z999"
          ],
          "expect": {
            "returns": "Z99.9"
          },
          "note": "JavaScript's own test: should not validate whether the code exists in the official table"
        },
        {
          "id": "cid10.format#[\"0A9Z\"]",
          "args": [
            "0A9Z"
          ],
          "expect": {
            "returns": "0A9.Z"
          },
          "note": "JavaScript's own test: should not validate whether the code exists in the official table"
        },
        {
          "id": "cid10.format#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string for an empty value"
        },
        {
          "id": "cid10.format#[\" . \"]",
          "args": [
            " . "
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string for an empty value"
        },
        {
          "id": "cid10.format#[1000]",
          "args": [
            1000
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string for a value that is not a string"
        }
      ]
    },
    {
      "id": "cid10.get",
      "level": "extended",
      "summary": "Looks up a CID-10 code and returns its official description.",
      "description": "Looks up a CID-10 category or subcategory in the DATASUS tables and returns its code and official Portuguese description.\n\n- Same input rules as `cid10.isValid`. Returns `null` exactly when that function returns `false`.\n- The returned code is upper case and without the dot (`A000`).\n- Same table as `cid10.isValid`: the DATASUS V2008 tables plus the U07 codes of the SIM table (`U07.1` is `{ code: \"U071\", description: \"Infecção pelo novo Coronavírus (COVID-19)\" }`). U09.9 and U10.9 are not found.",
      "params": [
        {
          "name": "value",
          "type": "string"
        }
      ],
      "returns": "Cid10?",
      "cases": [
        {
          "id": "cid10.get#[\"A00.0\"]",
          "args": [
            "A00.0"
          ],
          "expect": {
            "returns": {
              "code": "A000",
              "description": "Cólera devida a Vibrio cholerae 01, biótipo cholerae"
            }
          },
          "note": "from the maintainer briefing, #568"
        },
        {
          "id": "cid10.get#[\"a000\"]",
          "args": [
            "a000"
          ],
          "expect": {
            "returns": {
              "code": "A000",
              "description": "Cólera devida a Vibrio cholerae 01, biótipo cholerae"
            }
          },
          "note": "from the maintainer briefing, #568"
        },
        {
          "id": "cid10.get#[\"A00.5\"]",
          "args": [
            "A00.5"
          ],
          "expect": {
            "returns": null
          },
          "note": "from the maintainer briefing, #568"
        },
        {
          "id": "cid10.get#[\"F322\"]",
          "args": [
            "F322"
          ],
          "expect": {
            "returns": {
              "code": "F322",
              "description": "Episódio depressivo grave sem sintomas psicóticos"
            }
          },
          "note": "JavaScript's own test: should return a subcategory written without the dot"
        },
        {
          "id": "cid10.get#[\"A00\"]",
          "args": [
            "A00"
          ],
          "expect": {
            "returns": {
              "code": "A00",
              "description": "Cólera"
            }
          },
          "note": "JavaScript's own test: should return a category"
        },
        {
          "id": "cid10.get#[\"F32\"]",
          "args": [
            "F32"
          ],
          "expect": {
            "returns": {
              "code": "F32",
              "description": "Episódios depressivos"
            }
          },
          "note": "JavaScript's own test: should return a category"
        },
        {
          "id": "cid10.get#[\"I10\"]",
          "args": [
            "I10"
          ],
          "expect": {
            "returns": {
              "code": "I10",
              "description": "Hipertensão essencial (primária)"
            }
          },
          "note": "JavaScript's own test: should return a category that has no subcategory (I10)"
        },
        {
          "id": "cid10.get#[\"Z99.9\"]",
          "args": [
            "Z99.9"
          ],
          "expect": {
            "returns": {
              "code": "Z999",
              "description": "Dependência de máquina e aparelho capacitante não especificado"
            }
          },
          "note": "JavaScript's own test: should return the first and the last code of the table"
        },
        {
          "id": "cid10.get#[\"F43.0\"]",
          "args": [
            "F43.0"
          ],
          "expect": {
            "returns": {
              "code": "F430",
              "description": "Reação aguda ao \"stress\""
            }
          },
          "note": "JavaScript's own test: should keep the quotes and brackets a description carries"
        },
        {
          "id": "cid10.get#[\"Z76.5\"]",
          "args": [
            "Z76.5"
          ],
          "expect": {
            "returns": {
              "code": "Z765",
              "description": "Pessoa fingindo ser doente [simulação consciente]"
            }
          },
          "note": "JavaScript's own test: should keep the quotes and brackets a description carries"
        },
        {
          "id": "cid10.get#[\" m54.5 \"]",
          "args": [
            " m54.5 "
          ],
          "expect": {
            "returns": {
              "code": "M545",
              "description": "Dor lombar baixa"
            }
          },
          "note": "JavaScript's own test: should ignore the letter case and surrounding whitespace"
        },
        {
          "id": "cid10.get#[\"I10.0\"]",
          "args": [
            "I10.0"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a subcategory its category does not have"
        },
        {
          "id": "cid10.get#[\"U07\"]",
          "args": [
            "U07"
          ],
          "expect": {
            "returns": {
              "code": "U07",
              "description": "Uso emergencial do U07"
            }
          },
          "note": "JavaScript's own test: should find the U07 codes the SIM table adds to the V2008 files"
        },
        {
          "id": "cid10.get#[\"U07.0\"]",
          "args": [
            "U07.0"
          ],
          "expect": {
            "returns": {
              "code": "U070",
              "description": "Doença por cigarro eletrônico"
            }
          },
          "note": "JavaScript's own test: should find the U07 codes the SIM table adds to the V2008 files"
        },
        {
          "id": "cid10.get#[\"U07.1\"]",
          "args": [
            "U07.1"
          ],
          "expect": {
            "returns": {
              "code": "U071",
              "description": "Infecção pelo novo Coronavírus (COVID-19)"
            }
          },
          "note": "JavaScript's own test: should find the U07 codes the SIM table adds to the V2008 files"
        },
        {
          "id": "cid10.get#[\"U07.2\"]",
          "args": [
            "U07.2"
          ],
          "expect": {
            "returns": {
              "code": "U072",
              "description": "COVID-19, vírus não identificado"
            }
          },
          "note": "JavaScript's own test: should find the U07 codes the SIM table adds to the V2008 files"
        },
        {
          "id": "cid10.get#[\"A10\"]",
          "args": [
            "A10"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a category the table does not have"
        },
        {
          "id": "cid10.get#[\"U09.9\"]",
          "args": [
            "U09.9"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a category the table does not have"
        },
        {
          "id": "cid10.get#[\"U10.9\"]",
          "args": [
            "U10.9"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a category the table does not have"
        },
        {
          "id": "cid10.get#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a value that is not written in a documented form"
        },
        {
          "id": "cid10.get#whitespace",
          "args": [
            "   "
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a value that is not written in a documented form"
        },
        {
          "id": "cid10.get#[\"A00-0\"]",
          "args": [
            "A00-0"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a value that is not written in a documented form"
        },
        {
          "id": "cid10.get#[\"A00.00\"]",
          "args": [
            "A00.00"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a value that is not written in a documented form"
        },
        {
          "id": "cid10.get#[\"A00.0 Cólera\"]",
          "args": [
            "A00.0 Cólera"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a value that is not written in a documented form"
        },
        {
          "id": "cid10.get#[\"constructor\"]",
          "args": [
            "constructor"
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for the keys of Object.prototype"
        },
        {
          "id": "cid10.get#[100]",
          "args": [
            100
          ],
          "expect": {
            "returns": null
          },
          "note": "JavaScript's own test: should return null for a value that is not a string"
        }
      ]
    },
    {
      "id": "cid10.isValid",
      "level": "extended",
      "summary": "Checks whether a CID-10 code exists in the official DATASUS tables.",
      "description": "Checks whether a CID-10 category or subcategory exists in the Brazilian tables DATASUS publishes.\n\n- Accepts a category (3 characters, `A00`) or a subcategory (4 characters), with the dot (`A00.0`) or without it (`A000`). Letter case and surrounding whitespace are ignored.\n- Other separators (`A00-0`), a fifth character, a dagger or asterisk suffix and a value that is not a string are rejected.\n- A subcategory is valid only when the table lists it under its category. `I10.0` is invalid because I10 has no subcategories; `I10` is valid as a category.\n- Data: CID-10 V2008 of DATASUS, 2045 categories and 12188 subcategories, plus U07, U07.0, U07.1 and U07.2 from the SIM table of DATASUS (COVID-19 codes among them). Codes the WHO added later, such as U09.9 and U10.9, are invalid.\n- The `codCID` layout of eSocial event S-2230 was not checked against this function.",
      "params": [
        {
          "name": "value",
          "type": "string"
        }
      ],
      "returns": "boolean",
      "cases": [
        {
          "id": "cid10.isValid#[\"I10.0\"]",
          "args": [
            "I10.0"
          ],
          "expect": {
            "returns": false
          },
          "note": "from the maintainer briefing, #568"
        },
        {
          "id": "cid10.isValid#[\"A00.0\"]",
          "args": [
            "A00.0"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should validate a subcategory written with the dot"
        },
        {
          "id": "cid10.isValid#[\"A00.9\"]",
          "args": [
            "A00.9"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should validate a subcategory written with the dot"
        },
        {
          "id": "cid10.isValid#[\"A000\"]",
          "args": [
            "A000"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should validate a subcategory written without the dot"
        },
        {
          "id": "cid10.isValid#[\"F322\"]",
          "args": [
            "F322"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should validate a subcategory written without the dot"
        },
        {
          "id": "cid10.isValid#[\"A00\"]",
          "args": [
            "A00"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should validate a category, subdivided or not"
        },
        {
          "id": "cid10.isValid#[\"I10\"]",
          "args": [
            "I10"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should validate a category, subdivided or not"
        },
        {
          "id": "cid10.isValid#[\"Z99.9\"]",
          "args": [
            "Z99.9"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should validate the first and the last code of the table"
        },
        {
          "id": "cid10.isValid#[\"m54.5\"]",
          "args": [
            "m54.5"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should ignore the letter case and surrounding whitespace"
        },
        {
          "id": "cid10.isValid#[\" M545 \"]",
          "args": [
            " M545 "
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should ignore the letter case and surrounding whitespace"
        },
        {
          "id": "cid10.isValid#[\"A00.2\"]",
          "args": [
            "A00.2"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject a subcategory its category does not have"
        },
        {
          "id": "cid10.isValid#[\"A00.5\"]",
          "args": [
            "A00.5"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject a subcategory its category does not have"
        },
        {
          "id": "cid10.isValid#[\"I109\"]",
          "args": [
            "I109"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject any subcategory of a category that is not subdivided"
        },
        {
          "id": "cid10.isValid#[\"U07\"]",
          "args": [
            "U07"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should accept the U07 codes the SIM table adds to the V2008 files"
        },
        {
          "id": "cid10.isValid#[\"U07.1\"]",
          "args": [
            "U07.1"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should accept the U07 codes the SIM table adds to the V2008 files"
        },
        {
          "id": "cid10.isValid#[\"u072\"]",
          "args": [
            "u072"
          ],
          "expect": {
            "returns": true
          },
          "note": "JavaScript's own test: should accept the U07 codes the SIM table adds to the V2008 files"
        },
        {
          "id": "cid10.isValid#[\"U07.3\"]",
          "args": [
            "U07.3"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should accept the U07 codes the SIM table adds to the V2008 files"
        },
        {
          "id": "cid10.isValid#[\"A10\"]",
          "args": [
            "A10"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject a category the table does not have"
        },
        {
          "id": "cid10.isValid#[\"U09.9\"]",
          "args": [
            "U09.9"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject a category the table does not have"
        },
        {
          "id": "cid10.isValid#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject a value that is not written in a documented form"
        },
        {
          "id": "cid10.isValid#whitespace",
          "args": [
            "   "
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject a value that is not written in a documented form"
        },
        {
          "id": "cid10.isValid#[\"A0\"]",
          "args": [
            "A0"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject a value that is not written in a documented form"
        },
        {
          "id": "cid10.isValid#[\"A00-0\"]",
          "args": [
            "A00-0"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject a value that is not written in a documented form"
        },
        {
          "id": "cid10.isValid#[\"A00.00\"]",
          "args": [
            "A00.00"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject a value that is not written in a documented form"
        },
        {
          "id": "cid10.isValid#[\"A00.0 Cólera\"]",
          "args": [
            "A00.0 Cólera"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject a value that is not written in a documented form"
        },
        {
          "id": "cid10.isValid#[\"constructor\"]",
          "args": [
            "constructor"
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject the keys of Object.prototype"
        },
        {
          "id": "cid10.isValid#[100]",
          "args": [
            100
          ],
          "expect": {
            "returns": false
          },
          "note": "JavaScript's own test: should reject a value that is not a string"
        }
      ]
    },
    {
      "id": "cid10.parse",
      "level": "extended",
      "summary": "Removes the formatting of a CID-10 code.",
      "description": "Removes the formatting of a CID-10 code and returns it in upper case without the dot, the form the DATASUS tables store.\n\n- Keeps only letters and digits, capped at 4 characters. A shorter value (a category, or a code being typed) passes through as far as it goes.\n- It does not check the code against the table (use `cid10.isValid`).\n- A value that is not a string returns an empty string.",
      "params": [
        {
          "name": "value",
          "type": "string"
        }
      ],
      "returns": "string",
      "cases": [
        {
          "id": "cid10.parse#[\"A00.0\"]",
          "args": [
            "A00.0"
          ],
          "expect": {
            "returns": "A000"
          },
          "note": "from the maintainer briefing, #568"
        },
        {
          "id": "cid10.parse#[\"A000\"]",
          "args": [
            "A000"
          ],
          "expect": {
            "returns": "A000"
          },
          "note": "JavaScript's own test: should keep a code that has no dot"
        },
        {
          "id": "cid10.parse#[\"A00\"]",
          "args": [
            "A00"
          ],
          "expect": {
            "returns": "A00"
          },
          "note": "JavaScript's own test: should keep a code that has no dot"
        },
        {
          "id": "cid10.parse#[\"f32.2\"]",
          "args": [
            "f32.2"
          ],
          "expect": {
            "returns": "F322"
          },
          "note": "JavaScript's own test: should upper case the letter"
        },
        {
          "id": "cid10.parse#[\" A-0/0.0 \"]",
          "args": [
            " A-0/0.0 "
          ],
          "expect": {
            "returns": "A000"
          },
          "note": "JavaScript's own test: should drop every character that is not a letter or a digit"
        },
        {
          "id": "cid10.parse#[\"A\"]",
          "args": [
            "A"
          ],
          "expect": {
            "returns": "A"
          },
          "note": "JavaScript's own test: should pass a partial value through"
        },
        {
          "id": "cid10.parse#partial",
          "args": [
            "A00."
          ],
          "expect": {
            "returns": "A00"
          },
          "note": "JavaScript's own test: should pass a partial value through"
        },
        {
          "id": "cid10.parse#[\"A00.01\"]",
          "args": [
            "A00.01"
          ],
          "expect": {
            "returns": "A000"
          },
          "note": "JavaScript's own test: should cap the result at the 4 characters of a subcategory"
        },
        {
          "id": "cid10.parse#[\"A00012345\"]",
          "args": [
            "A00012345"
          ],
          "expect": {
            "returns": "A000"
          },
          "note": "JavaScript's own test: should cap the result at the 4 characters of a subcategory"
        },
        {
          "id": "cid10.parse#[\"0A.9Z\"]",
          "args": [
            "0A.9Z"
          ],
          "expect": {
            "returns": "0A9Z"
          },
          "note": "JavaScript's own test: should not validate whether the code exists in the official table"
        },
        {
          "id": "cid10.parse#empty",
          "args": [
            ""
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string for an empty value"
        },
        {
          "id": "cid10.parse#[\" . \"]",
          "args": [
            " . "
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string for an empty value"
        },
        {
          "id": "cid10.parse#[1000]",
          "args": [
            1000
          ],
          "expect": {
            "returns": ""
          },
          "note": "JavaScript's own test: should return an empty string for a value that is not a string"
        }
      ]
    }
  ]
}
