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

Add custom JEXL functions #504

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

davidmurch
Copy link

@davidmurch davidmurch commented Aug 18, 2023

Issue logged here #503

I believe this is minimum change needed to add this capability. The implementer needs to create their own Engine extending HL7MessageEngine here is an example

public class CustomHL7MessageEngine extends HL7MessageEngine {

    private Map<String, Object> customFunctions = new HashMap<>();
    
    public CustomHL7MessageEngine(FHIRContext context, Bundle.BundleType bundleType, Map<String, Object> customFunctions) {
        super(context, bundleType);
        this.customFunctions = customFunctions;
    }

    @Override
    public Bundle transform(InputDataExtractor dataInput, Iterable<FHIRResourceTemplate> resources, Map<String, EvaluationResult> contextValues) {
        HL7MessageData data = (HL7MessageData) dataInput;
        HL7MessageData newMessageData = new HL7MessageData(data.getHL7DataParser(), customFunctions);
        return super.transform(newMessageData, resources, contextValues);
    }
}

The role of the custom Engine is just to intercept the transform so the new constructor on HL7MessageData can be called.

Then when calling the converter supply your Engine.

    Map<String, Object> customFunctions = new HashMap<>();
    customFunctions.put("MyUtils", MyUtils.class);
    CustomHL7MessageEngine engine = new CustomHL7MessageEngine(fhirContext, options.getBundleType(), customFunctions);
    HL7ToFHIRConverter hl7ToFHIRConverter = new HL7ToFHIRConverter();
    Bundle bundle = hl7ToFHIRConverter.convertToBundle(rawHL7Message, options, engine);

…for JEXL engine

Signed-off-by: David Murch <david.murch@integration.works>
… instance var

Signed-off-by: David Murch <david.murch@integration.works>
@davidmurch davidmurch changed the title add custom jexl functions Add custom JEXL functions Aug 20, 2023
@LisaWellman
Copy link
Collaborator

LisaWellman commented Aug 23, 2023

Thanks very much @davidmurch for working on this. Two things I think would be good:

  1. Can we create a testcase (perhaps using your example code) that exercises the new constructor
  2. Depending on the extent of the testcase, we may want to include the example use case, or at least a small blurb on the functionality added, in the documentation.

@stueynz
Copy link

stueynz commented Aug 23, 2023

@davidmurch and I are working on this project together - Test case will be there sometime today (NZ time)
We'll add a new CustomFunctions section to the TECHNIQUES.md - which seems the most appropriate place for a "HOW TO do wild stuff with custom functions"

It's not just GeneralUtils functions that can be put into variables in JEXL expressions
Added CustomFunctionsTest - to make sure we can add customFunctions into variables in JEXL expressions
Renamed test/java/.../hl7/expression/varable directory to variable
Added License SPDX header and Copyright to Te Whatu Ora

Signed-off-by: Stuart McGrigor <stuart.mcgrigor@midcentraldhb.govt.nz>

# Conflicts:
#	src/main/java/io/github/linuxforhealth/hl7/message/HL7MessageData.java

Signed-off-by: David Murch <david.murch@integration.works>
@LisaWellman
Copy link
Collaborator

@davidmurch @stueynz I see you had another commit, please tag when you are ready for a review

@LisaWellman
Copy link
Collaborator

@davidmurch @stueynz I see no activity here; do you still want to pursue?

@davidmurch
Copy link
Author

@LisaWellman

Apologies for the delays as we completed our project using hl7v2-fhir-converter. I need to add our docs/examples etc and will update.

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

Successfully merging this pull request may close these issues.

4 participants