Datatype factories¶
-
hl7apy.factories.date_factory(value, datatype_cls, validation_level=None)¶ Creates a
DTobjectThe value in input must be a string parsable with
datetime.strptime(). The date format is chosen according to the length of the value as stated in this table:Length Format 4 %Y6 %Y%m8 %Y%m%dSome examples that work are:
>>> from hl7apy.base_datatypes import DT >>> date_factory("1974", DT) #doctest: +ELLIPSIS <hl7apy.base_datatypes.DT object at 0x...> >>> date_factory("198302", DT) #doctest: +ELLIPSIS <hl7apy.base_datatypes.DT object at 0x...> >>> date_factory("19880312", DT) #doctest: +ELLIPSIS <hl7apy.base_datatypes.DT object at 0x...>
If the value does not match one of the valid format it raises
ValueErrorParameters: - value (
str) – the value to assign the date object - value – the
DTclass to use. It has to be one implementation of the different version modules - validation_level (
int) – It must be a value from classvalidation_levelVALIDATION_LEVEL hl7apy.consts.VALIDATION_LEVELorNoneto use the default value
Return type: - value (
-
hl7apy.factories.timestamp_factory(value, datatype_cls, validation_level=None)¶ Creates a
TMobjectThe value in input must be a string parsable with
datetime.strptime(). It can also have an offset part specified with the format +/-HHMM. The offset can be added with all the allowed format The date format is chosen according to the length of the value as stated in this table:Length Format 2 %H4 %H%M6 %H%M%S10-13 %H%M%S.%fSome examples that work are:
>>> from hl7apy.base_datatypes import TM >>> timestamp_factory("12", TM) #doctest: +ELLIPSIS <hl7apy.base_datatypes.TM object at 0x...> >>> timestamp_factory("12+0300", TM) #doctest: +ELLIPSIS <hl7apy.base_datatypes.TM object at 0x...> >>> timestamp_factory("1204", TM) #doctest: +ELLIPSIS <hl7apy.base_datatypes.TM object at 0x...> >>> timestamp_factory("120434", TM) #doctest: +ELLIPSIS <hl7apy.base_datatypes.TM object at 0x...> >>> timestamp_factory("120434-0400", TM) #doctest: +ELLIPSIS <hl7apy.base_datatypes.TM object at 0x...>
If the value does not match one of the valid format it raises :exc:ValueError`
Parameters: - value (
str) – the value to assign the date object - value – the
TMclass to use. It has to be one implementation of the different version modules - validation_level (
int) – It must be a value from classvalidation_levelVALIDATION_LEVEL hl7apy.consts.VALIDATION_LEVELorNoneto use the default value
Return type: - value (
-
hl7apy.factories.datetime_factory(value, datatype_cls, validation_level=None)¶ Creates a
hl7apy.base_datatypes.DTMobjectThe value in input must be a string parsable with
datetime.strptime(). It can also have an offset part specified with the format +HHMM -HHMM. The offset can be added with all the allowed format. The date format is chosen according to the length of the value as stated in this table:Length Format 4 %Y6 %Y%m8 %Y%m%d10 %Y%m%d%H12 %Y%m%d%H%M14 %Y%m%d%H%M%S18-21 %Y%m%d%H%M%S.%fSome examples that work are:
>>> from hl7apy.base_datatypes import DTM >>> datetime_factory("1924", DTM) #doctest: +ELLIPSIS <hl7apy.base_datatypes.DTM object at 0x...> >>> datetime_factory("1924+0300", DTM) #doctest: +ELLIPSIS <hl7apy.base_datatypes.DTM object at 0x...> >>> datetime_factory("19220430", DTM) #doctest: +ELLIPSIS <hl7apy.base_datatypes.DTM object at 0x...> >>> datetime_factory("19220430-0400", DTM) #doctest: +ELLIPSIS <hl7apy.base_datatypes.DTM object at 0x...>
If the value does not match one of the valid format it raises
ValueErrorParameters: - value (
str) – the value to assign the date object - value – the
DTMclass to use. It has to be one implementation of the different version modules - validation_level (
int) – It must be a value from classvalidation_levelVALIDATION_LEVEL hl7apy.consts.VALIDATION_LEVELorNoneto use the default value
Return type: - value (
-
hl7apy.factories.numeric_factory(value, datatype_cls, validation_level=None)¶ Creates a
NMobjectThe value in input can be a string representing a decimal number or a
float. (i.e. a string valid fordecimal.Decimal()). If it’s not, aValueErroris raised Also an empty string orNoneare allowedParameters: - value (
strorNone) – the value to assign the numeric object - value – the
NMclass to use. It has to be one implementation of the different version modules - validation_level (
int) – It must be a value from classVALIDATION_LEVEL hl7apy.consts.VALIDATION_LEVELorNoneto use the default value
Return type: - value (
-
hl7apy.factories.sequence_id_factory(value, datatype_cls, validation_level=None)¶ Creates a
SIobjectThe value in input can be a string representing an integer number or an
int. (i.e. a string valid forint()). If it’s not, aValueErroris raised Also an empty string orNoneare allowedParameters: - value (
strorNone) – the value to assign the date object - value – the SI class to use. It has to be loaded from one implementation of the different version modules
- validation_level (
int) – It must be a value from classVALIDATION_LEVEL hl7apy.consts.VALIDATION_LEVELorNoneto use the default value
Return type: - value (