FHIR Chat · unsignedInt and positiveInt string in JSON and FHIRPath? · implementers

Stream: implementers

Topic: unsignedInt and positiveInt string in JSON and FHIRPath?


view this post on Zulip Alexander Kiel (Sep 18 2020 at 16:30):

Why are the primitive data types unsignedInt and positiveInt are represented as string rather than number in JSON? In addition to that, why is the FHIRPath type of both values specified as http://hl7.org/fhirpath/System.String in the v4.0.1 StructureDefinitions when https://www.hl7.org/fhir/fhirpath.html says that FHIR.integer, FHIR.unsignedInt, FHIR.positiveInt should map to System.Integer. Mostly the value type FHIR primitive types already matches the conversion table. Except for FHIR.date, but let's stay at the integers here.

How do other implementers represent unsignedInt and positiveInt in memory? Would it be any problem to just use a 32-bit signed integer here?

view this post on Zulip Jean Duteau (Sep 18 2020 at 16:33):

In the spec, it says that unsignedInt and positiveInt are represented as JSON number:

unsignedInt Any non-negative integer in the range 0..2,147,483,647 xs:nonNegativeInteger JSON number
positiveInt Any positive integer in the range 1..2,147,483,647 xs:positiveInteger JSON number

view this post on Zulip Gino Canessa (Sep 18 2020 at 16:37):

Alexander: according the the datatypes page, the JSON serialization is as a number. The regex is provided for validation purposes.

I'll note that in R5, there is now a 64-bit integer, which needs to be serialized as a string in JSON because a number will not guarantee precision.

In C#, I use uint for unsigned and positive. In JS/TS I use number.

view this post on Zulip Alexander Kiel (Sep 18 2020 at 16:38):

@Jean Duteau Ah you are right. At this point, JSON number is given. But here https://www.hl7.org/fhir/json.html#primitive only integer and decimal are given and the https://www.hl7.org/fhir/datatypes.html#attachment example has the unsingedInt also as string.

view this post on Zulip Alexander Kiel (Sep 18 2020 at 16:51):

In FHIR#26937 it also sounds like unsignedInt and positiveInt should be represented as strings like integer64. Looks like this should be clarified.

{
  "id" : "positiveInt.value",
  "path" : "positiveInt.value",
  "representation" : [ "xmlAttr" ],
  "short" : "Primitive value for positiveInt",
  "definition" : "Primitive value for positiveInt",
  "min" : 0,
  "max" : "1",
  "type" : [ {
    "extension" : [ {
      "url" : "http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type",
      "valueUrl" : "positiveInt"
    }, {
      "url" : "http://hl7.org/fhir/StructureDefinition/regex",
      "valueString" : "[1-9][0-9]*"
    } ],
    "code" : "http://hl7.org/fhirpath/System.String"
  } ]
}

Also here, I would replace System.String with System.Integer.

view this post on Zulip Lloyd McKenzie (Sep 18 2020 at 17:13):

@Grahame Grieve

view this post on Zulip Gino Canessa (Sep 18 2020 at 17:14):

Ahh, I see the confusion. I believe @Ewout Kramer was asking that all three be specifically listed, not to imply that they are serialized as strings.
The issue was started around "integer64" and the other types were tacked on aftwards.
Edit: If I remember correctly

view this post on Zulip Grahame Grieve (Sep 18 2020 at 20:31):

I would replace System.String with System.Integer.

yes. Can you please make a task for this

view this post on Zulip Alexander Kiel (Sep 20 2020 at 13:41):

Done it: https://jira.hl7.org/browse/FHIR-28586


Last updated: Apr 12 2022 at 19:14 UTC