LinuxForHealth / hl7v2-fhir-converter

Converts HL7 v2 Messages to FHIR Resources
Apache License 2.0
89 stars 36 forks source link

Only GeneralUtils available as JEXL in a variable definition #485

Open PatriciaPerozoUSDS opened 2 years ago

PatriciaPerozoUSDS commented 2 years ago

Describe the bug In extensionMeta.yml, extension_4 calls GeneralUtils within a variable definition

vars:
    value: MSH.7, GeneralUtils.dateTimeWithZoneId(value,ZONEID)

None of the other classes available in the explicit JEXL definition (String, StringUtils, NumberUtils) work in this style of declaration.

To Reproduce

Expected behavior I would expect if GeneralUtils was available to be used as a part of variable definition, that the other classes initialized in the JEXLEngineUtil constructor would be available too.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

cragun47 commented 2 years ago

@PatriciaPerozoUSDS Looking into the code over your concerns, I don’t see an easy way to enable anything other than GeneralUtils for JEXL handling. I am investigating further with some of the other developers, but it could take a while.



In the mean time, can you explain what it is you’re trying to accomplish? Perhaps there is some other way to do what you want to do.

PatriciaPerozoUSDS commented 2 years ago

Hi @cragun47 - We were hoping to simplify OID generation by adding a line to one of our extensions like config below:

# Patient las update facility universal ID
extension_4:
  generateList: true
  valueOf: extension/Extension
  expressionType: resource
  condition: $idStr NOT_NULL && $systemStr EQUALS ISO
  vars:
    idStr: String, PID.34.2
    value: PID.34.2, "urn:oid:".concat(value)
    systemStr: String, PID.34.3
  constants:
    KEY_NAME_SUFFIX: Oid
    urlValue: last-updated-facility-universal-id

We have a way to define the extension above by defining a constant and then using value: $oidUrlPrefix + PID.34.2 instead but were looking for ways to use JEXL to simplify the config

Ideally, we would love to be able to add our own utilities class and add that as a usable expression in the same way GeneralUtils is used. Then we could define a makeOID function in the util class and use that everywhere we wanted to instead of the inline use above.

davidmurch commented 1 year ago

Ideally, we would love to be able to add our own utilities class and add that as a usable expression in the same way GeneralUtils is used. Then we could define a makeOID function in the util class and use that everywhere we wanted to instead of the inline use above.

I'm very much interested in adding this functionality. We would like to be able to supply our own utils classes which could then interrogate our FHIR server to lookup Resources such as ValueSets and ConceptMaps for use in the HL7 mapping of many of our custom segments to our IG.

stueynz commented 1 year ago

I tracked down the reason why only GeneralUtils functions can be placed into variables:

There's special code in VariableGenerator - specifically targeted at GeneralUtils functions.

A stop-gap solution that allows for functions from any group (so long as that group name ends in Utils) is reletively easy.

    // Any custom function will work - so long as the group name ends in Utils  e.g.:
    //  vars
    //      value: PID.26 , MyCustomUtils.myCustomFunction(value)
    //
    if (StringUtils.contains(rawVariable, "Utils.")) {
      String[] values = rawVariable.split(",", 2);
      // Handle * in combination with GeneralUtils function
      exp = ExpressionAttributes.extractExpressionModifiers(values[0], false);
      if (values.length == COMPONENT_LENGTH_FOR_VAR_EXPRESSION) {
        List<String> specs = getTokens(exp.getExpression());
        return new ExpressionVariable(varName, values[1], specs, exp.getExtractMultiple(), exp.getRetainEmpty());
      }

I wonder if we can make the customFunctions Map easily available so we can check the map keys in VariableGenerator rather than brute-force it the way it is currently?

stueynz commented 1 year ago

Keep an eye on https://github.com/LinuxForHealth/hl7v2-fhir-converter/pull/504 - we really need this to work.