Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only GeneralUtils available as JEXL in a variable definition #485

Open
PatriciaPerozoUSDS opened this issue Jul 20, 2022 · 5 comments
Open

Comments

@PatriciaPerozoUSDS
Copy link

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

  • Replace the above with
vars:
    value: MSH.7, String.format("%s", value)
  • run the converter
  • get error ERROR io.github.linuxforhealth.hl7.resource.deserializer.HL7DataBasedResourceDeserializer - deserialization failure expression type RESOURCE

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):

  • OS: MacOS Big Sur
  • Version 1.0.18

Additional context
Add any other context about the problem here.

@cragun47
Copy link
Contributor

@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
Copy link
Author

PatriciaPerozoUSDS commented Jul 22, 2022

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
Copy link

davidmurch commented Aug 16, 2023

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
Copy link

stueynz commented Aug 23, 2023

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
Copy link

stueynz commented Aug 23, 2023

Keep an eye on #504 - we really need this to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants