LinuxForHealth / hl7v2-fhir-converter

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

Add custom JEXL functions #504

Open davidmurch opened 1 year ago

davidmurch commented 1 year ago

Issue logged here https://github.com/LinuxForHealth/hl7v2-fhir-converter/issues/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);
LisaWellman commented 1 year ago

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 commented 1 year ago

@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"

LisaWellman commented 1 year ago

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

LisaWellman commented 9 months ago

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

davidmurch commented 1 month ago

@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.