Smile CDR v2024.05.PRE
On this page:

39.4.1Converter API

 

The Converter object can be used to convert object types from one format to another.

39.4.2Method: hl7v2TsToFhirDate(dt);

 

This method converts an HL7 v2.x DT or TS datatype value into an equivalent FHIR Date (ISO 8601) string.

Inputs:

  • ts – An HL7 v2.x datetime string (e.g. 20110101 or 201512010005). Note that any precision beyond the day of the month will be ignored.

Outputs:

  • Returns a FHIR Date string (e.g. 2011-01-01).

Example:

var dt = '20110202123000-0400'; // this would likely come from an HL7 v2.x message
var authoredOn = Converter.hl7v2TsToFhirDate(dt);
Log.info(authoredOn); // 2011-02-02

39.4.3Method: hl7v2TsToFhirDateTime(ts);

 

This method converts an HL7 v2.x DT or TS datatype value into an equivalent FHIR DateTime (ISO 8601) string.

Inputs:

  • ts – An HL7 v2.x datetime string (e.g. 20110101 or 201512010005).

Outputs:

  • Returns a FHIR DateTime string (e.g. 2011-01-01T12:30:00-04:00).

Example:

var ts = '20110202123000-0400'; // this would likely come from an HL7 v2.x message
var authoredOn = Converter.hl7v2TsToFhirDateTime(ts);
Log.info(authoredOn); // 2011-02-02T12:30:00-04:00

39.4.4Method: hl7v2TsToFhirDateTime(ts, impliedTimeZone);

 

This method converts an HL7 v2.x DT or TS datatype value into an equivalent FHIR DateTime (ISO 8601) string. This method is useful for processing messages originating in an HL7 v2.x system that does not include timezone offset information in messages, and is known to be located in a specific timezone.

Inputs:

  • ts – An HL7 v2.x datetime string (e.g. 20110101 or 201512010005).
  • impliedTimeZone – A timezone string to use for the resulting FHIR DateTime string (e.g. America/New_York).

Outputs:

  • Returns a FHIR DateTime string (e.g. 2011-01-01T12:30:00-04:00).

Example:

var ts = '20110202123000'; // this would likely come from an HL7 v2.x message
var authoredOn = Converter.hl7v2TsToFhirDateTime(ts, 'America/New_York');

39.4.5Method: urlDecodeString(string);

 

This method decodes a URL Encoded string.

Inputs:

  • string – A URL encoded string

Outputs:

  • Returns the corresponding URL decoded string (if the supplied string was null, this method returns null)

Example:

var input = 'help%20i%20%C3%A4m%20a%20b%C3%BBg';
var output = Converter.urlDecodeString(input); // returns "help i äm a bûg"

39.4.6Method: urlEncodeString(string);

 

This method decodes a URL Encoded string.

Inputs:

  • string – A string

Outputs:

  • Returns the corresponding URL encoded string (if the supplied string was null, this method returns null)

Example:

var input = 'help i äm a bûg';
var output = Converter.urlEncodeString(input); // returns help%20i%20%C3%A4m%20a%20b%C3%BBg

39.4.7Method: base64Encode(string);

 

This method encodes a string to base64.

Inputs:

  • string – A string

Outputs:

  • Returns the corresponding base64 encoded string

Example:

var input = 'help i äm a bûg';
var output = Converter.base64Encode(input); // returns aGVscCBpIMOkbSBhIGLDu2c=

39.4.8Method: base64Decode(string);

 

This method decodes a base64 encoded string.

Inputs:

  • string – A string

Outputs:

  • Returns the corresponding base64 decoded string

Example:

var input = 'aGVscCBpIMOkbSBhIGLDu2c=';
var output = Converter.base64Decode(input); // returns "help i äm a bûg"