SMART on FHIR Python Client 4.2.0
 
Loading...
Searching...
No Matches
fhirclient.models.fhirdate.FHIRDate Class Reference

A convenience class for working with FHIR dates in Python. More...

Inheritance diagram for fhirclient.models.fhirdate.FHIRDate:
fhirclient.models.fhirdatetime.FHIRDateTime fhirclient.models.fhirinstant.FHIRInstant fhirclient.models.fhirtime.FHIRTime

Public Member Functions

 __init__ (self, Union[str, None] jsonval=None)
 
 __setattr__ (self, prop, value)
 
 with_json (cls, Union[str, list] jsonobj)
 Initialize a date from an ISO date string.
 
 with_json_and_owner (cls, Union[str, list] jsonobj, owner)
 Added for compatibility reasons to FHIRElement; "owner" is discarded.
 
Union[str, None] as_json (self)
 Returns the original JSON string used to create this instance.
 

Public Attributes

 date
 
 origval
 

Static Protected Member Functions

 _parse_partial (str value, cls)
 Handle partial dates like 1970 or 1980-12.
 
datetime.date _parse_date (str value)
 
datetime.datetime _parse_datetime (str value)
 
datetime.time _parse_time (str value)
 
str _strip_leap_seconds (str value)
 Manually ignore leap seconds by clamping the seconds value to 59.
 
Any _from_string (str value)
 

Protected Attributes

 _FIELD
 

Static Protected Attributes

 _REGEX
 Private properties and methods #.
 
str _FIELD
 

Properties

 isostring = property
 Returns a standardized ISO 8601 version of the Python representation of the FHIR JSON.
 

Detailed Description

A convenience class for working with FHIR dates in Python.

http://hl7.org/fhir/R4/datatypes.html#date

Converting to a Python representation does require some compromises:

  • This class will convert partial dates ("reduced precision dates") like "2024" into full dates using the earliest possible time (in this example, "2024-01-01") because Python's date class does not support partial dates.

If such compromise is not useful for you, avoid using the date or isostring properties and just use the as_json() method in order to work with the original, exact string.

For backwards-compatibility reasons, this class is the parent class of FHIRDateTime, FHIRInstant, and FHIRTime. But they are all separate concepts and in a future major release, they should be split into entirely separate classes.

Public properties:

  • date: datetime.date representing the JSON value
  • isostring: an ISO 8601 string version of the above Python object

Public methods:

  • as_json: returns the original JSON used to construct the instance

Constructor & Destructor Documentation

◆ __init__()

fhirclient.models.fhirdate.FHIRDate.__init__ (   self,
Union[str, None]   jsonval = None 
)

Member Function Documentation

◆ __setattr__()

fhirclient.models.fhirdate.FHIRDate.__setattr__ (   self,
  prop,
  value 
)

◆ _from_string()

Any fhirclient.models.fhirdate.FHIRDate._from_string ( str  value)
staticprotected

◆ _parse_date()

datetime.date fhirclient.models.fhirdate.FHIRDate._parse_date ( str  value)
staticprotected

◆ _parse_datetime()

datetime.datetime fhirclient.models.fhirdate.FHIRDate._parse_datetime ( str  value)
staticprotected

◆ _parse_partial()

fhirclient.models.fhirdate.FHIRDate._parse_partial ( str  value,
  cls 
)
staticprotected

Handle partial dates like 1970 or 1980-12.

   FHIR allows them, but Python's datetime classes do not natively parse them.

◆ _parse_time()

datetime.time fhirclient.models.fhirdate.FHIRDate._parse_time ( str  value)
staticprotected

◆ _strip_leap_seconds()

str fhirclient.models.fhirdate.FHIRDate._strip_leap_seconds ( str  value)
staticprotected

Manually ignore leap seconds by clamping the seconds value to 59.

   Python native times don't support them (at the time of this writing, but also watch
   https://bugs.python.org/issue23574). For example, the stdlib's datetime.fromtimestamp()
   also clamps to 59 if the system gives it leap seconds.

   But FHIR allows leap seconds and says receiving code SHOULD accept them,
   so we should be graceful enough to at least not throw a ValueError,
   even though we can't natively represent the most-correct time.

◆ as_json()

Union[str, None] fhirclient.models.fhirdate.FHIRDate.as_json (   self)

Returns the original JSON string used to create this instance.

◆ with_json()

fhirclient.models.fhirdate.FHIRDate.with_json (   cls,
Union[str, list]  jsonobj 
)

Initialize a date from an ISO date string.

◆ with_json_and_owner()

fhirclient.models.fhirdate.FHIRDate.with_json_and_owner (   cls,
Union[str, list]  jsonobj,
  owner 
)

Added for compatibility reasons to FHIRElement; "owner" is discarded.

Member Data Documentation

◆ _FIELD [1/2]

fhirclient.models.fhirdate.FHIRDate._FIELD
protected

◆ _FIELD [2/2]

fhirclient.models.fhirdate.FHIRDate._FIELD
staticprotected

◆ _REGEX

fhirclient.models.fhirdate.FHIRDate._REGEX
staticprotected

Private properties and methods #.

◆ date

fhirclient.models.fhirdate.FHIRDate.date

◆ origval

fhirclient.models.fhirdate.FHIRDate.origval

Property Documentation

◆ isostring

fhirclient.models.fhirdate.FHIRDate.isostring = property
static

Returns a standardized ISO 8601 version of the Python representation of the FHIR JSON.

   Note that this may not be a fully accurate version of the input JSON.
   In particular, it will convert partial dates like "2024" to full dates like "2024-01-01".
   It will also normalize the timezone, if present.

The documentation for this class was generated from the following file: