The CWE (Coded With Exceptions) data type was introduced in HL7 v2.5 to replace the deprecated CE composite. It carries a code, its display text, the coding system that defines it, optional alternate and second-alternate triplets, coding-system versions, the Original Text the user actually entered, and — added through v2.6 and v2.7 — OIDs and value-set identifiers that pin the code to an exact, queryable terminology. Today it is the single most common composite in modern HL7 v2 traffic: every "coded value with a local exception path" field uses it, including OBX-3 Observation Identifier, PID-10 Race, IAR-1 Allergy Reaction Code, AL1-3 Allergen Code, and DG1-3 Diagnosis Code.
Purpose
CWE solves the real-world problem CE could not: most healthcare interfaces need to send a code that should come from a standard vocabulary but sometimes carries a local extension, a deprecated term, or a value that no profile anticipated. The "Exceptions" in the name is literal — CWE permits values outside the stated value set, as long as the sender flags the coding system. Its companion CNE (Coded No Exceptions) is structurally identical but conformance-strict: CNE values must be from the stated value set.
CWE additionally carries three pieces of metadata that CE lacks and that interface engineers had been smuggling into adjacent fields for years:
- Coding system version (CWE.7, CWE.8, CWE.13) — disambiguates ICD-10-CM-2024 from ICD-10-CM-2026.
- Original Text (CWE.9) — the exact text the user typed, before any code lookup.
- OIDs and Value Set IDs (CWE.14–CWE.22) — machine-resolvable identifiers for the coding system and the value set the code was drawn from.
Component reference
Source: HAPI HL7v2 v2.8.1 javadocs — CWE. CWE has 22 components in v2.7+, separated by ^. Length is not published in the javadocs (—).
| Seq | Name | Data Type | Length | Req | Description |
|---|---|---|---|---|---|
| CWE.1 | Identifier | st | — | C | Primary code value. At least one of CWE.1 / CWE.4 / CWE.10 must be present. |
| CWE.2 | Text | st | — | O | Display text for CWE.1. |
| CWE.3 | Name of Coding System | id | — | C | Coding system for CWE.1 — e.g. LN, SCT, I10, HL70005. Required when CWE.1 is present. |
| CWE.4 | Alternate Identifier | st | — | C | Equivalent code from a second coding system. |
| CWE.5 | Alternate Text | st | — | O | Display text for CWE.4. |
| CWE.6 | Name of Alternate Coding System | id | — | C | Coding system for CWE.4. |
| CWE.7 | Coding System Version ID | st | — | O | Version of CWE.3, e.g. 2024 for ICD-10-CM. |
| CWE.8 | Alternate Coding System Version ID | st | — | O | Version of CWE.6. |
| CWE.9 | Original Text | st | — | O | The exact text the user entered, before coding. Authoritative for human-readable rendering. |
| CWE.10 | Second Alternate Identifier | st | — | O | Third code (second alternate). |
| CWE.11 | Second Alternate Text | st | — | O | Display text for CWE.10. |
| CWE.12 | Name of Second Alternate Coding System | id | — | C | Coding system for CWE.10. |
| CWE.13 | Second Alternate Coding System Version ID | st | — | O | Version of CWE.12. |
| CWE.14 | Coding System OID | st | — | O | OID for CWE.3, e.g. 2.16.840.1.113883.6.96 for SNOMED CT. |
| CWE.15 | Value Set OID | st | — | O | OID of the value set CWE.1 was drawn from. |
| CWE.16 | Value Set Version ID | dtm | — | O | Version (typically a date/time) of the value set. |
| CWE.17 | Alternate Coding System OID | st | — | O | OID for CWE.6. |
| CWE.18 | Alternate Value Set OID | st | — | O | Value set OID for CWE.4. |
| CWE.19 | Alternate Value Set Version ID | dtm | — | O | Version of CWE.18. |
| CWE.20 | Second Alternate Coding System OID | st | — | O | OID for CWE.12. |
| CWE.21 | Second Alternate Value Set OID | st | — | O | Value set OID for CWE.10. |
| CWE.22 | Second Alternate Value Set Version ID | dtm | — | O | Version of CWE.21. |
The composite is organized in triplets: primary (1–3), alternate (4–6), second alternate (10–12), each with its own version (7 / 8 / 13) and OID/value-set block (14–16 / 17–19 / 20–22). CWE.9 Original Text sits outside the triplet structure as a free-text fallback.
Most-used components
- CWE.1 Identifier — the code; the value every consumer reads first.
- CWE.2 Text — display string for the code, used in UIs and logs.
- CWE.3 Name of Coding System — disambiguates CWE.1. Without it, a code is unparseable.
- CWE.4 / CWE.5 / CWE.6 — the alternate triplet, typically a local code paired with the standard one in 1–3 (or vice versa).
- CWE.9 Original Text — the user's actual typed input, preserved through coding; essential when no code matched and free text is all the receiver has.
Where it's used
CWE is the dominant coded composite in v2.7+ messages. Representative fields:
- PID-10 Race
- PID-22 Ethnic Group
- PID-26 Citizenship
- PID-28 Nationality
- PV1-10 Hospital Service
- OBX-3 Observation Identifier (carries LOINC under CWE)
- OBX-6 Units (often CWE referencing UCUM)
- OBR-4 Universal Service Identifier
- AL1-3 Allergen Code / Mnemonic / Description
- AL1-5 Allergy Reaction Code
- IAR-1 Allergy Reaction Code
- DG1-3 Diagnosis Code – DG1
- PR1-4 Procedure Code – PR1
- RXA-9 Administration Notes
Version differences
- v2.5 — CWE introduced with 9 components (Identifier through Original Text), replacing CE for fields that permit local extensions.
- v2.6 — Second alternate triplet added (CWE.10–CWE.13).
- v2.7 — OID and Value Set metadata added (CWE.14–CWE.22), bringing the total to 22 components.
- v2.7.1 — Field-level conformance descriptions refined; no structural changes.
- v2.8 / v2.8.1 / v2.8.2 — Structurally stable per the HAPI v2.8.1 javadocs. 22 components, same names and order.
Common mistakes
- Leaving CWE.3 Name of Coding System empty. The identifier alone is ambiguous —
M,2,1234all need a system. Engines cannot normalize CWE.1 without CWE.3. - Putting display text in CWE.1 instead of CWE.2.
Male^^HL70001looks superficially correct but the code isMale, which is not in HL70001. - Treating CWE as CE in HAPI version-specific code.
getCe3_NameOfCodingSystem()does not exist on a CWE object; calls compile against the wrong version structure package. - Treating components as repetitions — sending
M~Finside CWE.1 to mean "either Male or Female." CWE is a single composite; multiple coded values require field-level repetition with~. - Populating CWE.7 Coding System Version with a date when the coding system uses a semantic version (or vice versa). Downstream engines cannot resolve the version into a known release.
- Sending an OID in CWE.3 instead of the HL7 short name. CWE.3 takes the symbolic system name (
SCT,LN,I10); the OID belongs in CWE.14. - Down-casting CWE → CE on the way out and silently dropping CWE.9 Original Text. The receiver loses the only authoritative human-readable string when CWE.2 is empty.
Examples
Minimal value — just the identifier (legal but discouraged):
M
Three-component value — code + display + coding system:
M^Male^HL70001
SNOMED CT clinical finding:
39579001^Anaphylaxis^SCT
Six-component value with alternate triplet — standard primary, local alternate:
39579001^Anaphylaxis^SCT^ANAPH^Anaphylactic reaction^MERCYRXN
Fully populated (most-used 9) — primary + alternate + version + Original Text:
39579001^Anaphylaxis^SCT^T78.2XXA^Anaphylactic shock, initial^I10^20260301^2024^Severe peanut anaphylaxis reported by mother
With OID metadata (CWE.14–CWE.16):
39579001^Anaphylaxis^SCT^^^^20260301^^Severe peanut anaphylaxis^^^^^2.16.840.1.113883.6.96^2.16.840.1.113883.3.88.12.3221.6.2^20240101000000
In context — IAR-1 Allergy Reaction Code in an allergy/intolerance segment:
IAR|1|39579001^Anaphylaxis^SCT^^^^^^Severe peanut anaphylaxis|SV^Severe^HL70128|20260601||A^Active^HL70498
In context — OBX-3 Observation Identifier with a LOINC CWE:
OBX|1|NM|2345-7^Glucose [Mass/volume] in Serum or Plasma^LN^^^^2.74||118|mg/dL|70-99|H|||F
Common pitfall — omitting CWE.3:
2345-7^Glucose
Common pitfall — raw text in CWE.1 with no code lookup performed:
Peanut allergy^^^^^^^^Peanut allergy
This pattern is sometimes deliberate (sender knows there is no code), but it should appear as ""^""^""^""^""^""^""^""^Peanut allergy — i.e. populate only CWE.9, not CWE.1.
FHIR mapping
The HL7 v2-to-FHIR Implementation Guide publishes multiple ConceptMaps for CWE because CWE is reused across fields whose FHIR equivalents are not all CodeableConcept:
- ConceptMap-datatype-cwe-to-codeableconcept — the canonical mapping.
- ConceptMap-datatype-cwe-to-coding — when the target field is a single
Coding. - ConceptMap-datatype-cwe-to-annotation — for note/annotation fields.
- ConceptMap-datatype-cwe-to-identifier — when CWE is used as a coded identifier.
- ConceptMap-datatype-cwe-to-quantity — when CWE carries a unit of measure on a quantity.
Component-level mapping into CodeableConcept (the most common target):
| HL7 v2 | FHIR target |
|---|---|
| CWE.1 Identifier | CodeableConcept.coding[0].code |
| CWE.2 Text | CodeableConcept.coding[0].display |
| CWE.3 Name of Coding System | CodeableConcept.coding[0].system (HL7 table name → URI) |
| CWE.4 Alternate Identifier | CodeableConcept.coding[1].code |
| CWE.5 Alternate Text | CodeableConcept.coding[1].display |
| CWE.6 Name of Alternate Coding System | CodeableConcept.coding[1].system |
| CWE.7 / CWE.8 / CWE.13 Coding System Version | CodeableConcept.coding[n].version |
| CWE.9 Original Text | CodeableConcept.text |
| CWE.10–CWE.12 Second alternate | CodeableConcept.coding[2] |
| CWE.14 Coding System OID | resolves to CodeableConcept.coding[0].system URI |
| CWE.15 / CWE.16 Value Set OID + version | tracked on the bound ValueSet, not on the instance |
Engine considerations
- Vocabulary normalization — every inbound CWE flows through a code-system lookup keyed off CWE.3. Engines that cache the HL7 v3 table-name-to-OID mapping (
SCT→2.16.840.1.113883.6.96) cut translation latency to microseconds. - OID lookup — when CWE.14 is present and CWE.3 is missing, the engine should resolve OID → short name rather than reject the message; the OID is the more authoritative identifier.
- Unmapped local codes — when CWE arrives with a code outside the stated value set, the engine must either honor the "exception" (route the value to a curation queue and pass it through with a warning) or down-grade to a CWE that surfaces only CWE.9 Original Text. Silent drop is a data-loss bug.
- Round-trip preservation — CWE.9 Original Text should always survive transit even when CWE.1–CWE.8 are dropped. This is the contract that makes CWE more forgiving than CE.
- Degraded behavior with FHIR-only consumers — five CWE components collapse onto two
Codingentries insideCodeableConcept. The second alternate triplet (CWE.10–CWE.13) lands oncoding[2]; consumers that read onlycoding[0]will miss it. - HAPI typing —
ca.uhn.hl7v2.model.v281.datatype.CWEexposes typed accessors for all 22 components. Older-version code paths must import the matching version's CWE class; a v2.5 CWE has only 9 components and the v2.8.1 accessors will throw.
How Vorro parses and produces CWE
Vorro treats CWE as the canonical coded composite. On inbound:
- The parser resolves CWE.3 against a curated table that maps HL7 v3 short names, OIDs, and common local aliases to a single internal system URI. CWE.14, if present, takes priority over CWE.3 when the two disagree.
- CWE.9 Original Text is preserved untouched and surfaced in every downstream representation — FHIR
CodeableConcept.text, JSON event payloads, and the audit log. - Local codes that fail value-set membership are not dropped: they pass through with a soft warning and are queued for terminology curation, matching the "with exceptions" contract.
- Coding-system versions (CWE.7 / 8 / 13) are normalized to a canonical release identifier; a date in CWE.7 against a vocabulary that uses semantic versions triggers a flag.
On outbound, Vorro emits CWE with CWE.1, CWE.2, and CWE.3 always populated together, CWE.9 set whenever the receiving system has a free-text fallback, and OID metadata (CWE.14–CWE.16) added when the destination profile advertises support. We never silently down-cast to CE on send.
Related pages
- CNE data type — Coded No Exceptions
- CE data type — Coded Element (legacy)
- CF data type — Coded Element with Formatted Values
Sources
- HAPI HL7v2 v2.8.1 javadoc — CWE datatype
- HAPI HL7v2 v2.8.1 apidocs index
- HL7 v2 product brief
- HL7 v2-to-FHIR IG — ConceptMap CWE to CodeableConcept
- HL7 v2-to-FHIR IG — ConceptMap CWE to Coding
- HL7 v2-to-FHIR IG — ConceptMap CWE to Annotation
- HL7 v2-to-FHIR IG — ConceptMap CWE to Identifier
- HL7 v2-to-FHIR IG — ConceptMap CWE to Quantity
