On this page:

29.1Specifying JavaScript in Configuration File

 

In many cases JavaScript can be defined in configuration either as a reference to an external file or inline directly in the Smile CDR configuration properties file. When defining JavaScript in the properties file there a couple of considerations to keep in mind:

  1. Any line delimiters in the JavaScript code will need to be removed or escaped with a backslash, \.
  2. When specifying comments the /* Comment */ notation should be used rather than // Comment.

For example, a mapping script for the ETL Importer module in the properties file might look something like the following:

module.etl_importer.config.mapping.script=/*\
 * CSV Mapping function - Expects input in the format:\
 * ID,FAMILYNAME,GIVENNAME,MIDDLENAME,BIRTHDATE,CITY\
 */\
function handleEtlImportRow(inputMap, context) {\
    Log.info("Processing CSV row from file: " + context.filename);\
\
    /* Create a patient */\
    var patient = ResourceBuilder.build('Patient');\
    patient.id = Uuid.newPlaceholderId();\
\
    /* Identifier */\
    patient.identifier[0].system = 'http://example.com/mrns';\
    patient.identifier[0].value = inputMap['ID'];\
\
    /* Name */\
    patient.name[0].family = inputMap['FAMILYNAME'];\
    patient.name[0].given[0] = inputMap['GIVENNAME'];\
    patient.name[0].given[1] = inputMap['MIDDLENAME'];\
\
    /* DOB */\
    patient.birthDate = inputMap['BIRTHDATE'];\
\
    /* Address */\
    patient.address[0].city = inputMap['CITY'];\
\
    /* Build a transaction and process it */\
    var transaction = TransactionBuilder.newTransactionBuilder();\
    transaction.create(patient);\
    Fhir.transaction(transaction);\
}