Search in sources :

Example 1 with HL7MessageEngine

use of io.github.linuxforhealth.hl7.message.HL7MessageEngine in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7ToFHIRConverter method convertToBundle.

/**
 * Converts the input HL7 message (String data) into FHIR bundle resource.
 *
 * @param hl7MessageData Message to convert
 * @param options Options for conversion
 * @param engine Hl7Message engine
 * @return Bundle {@link Bundle} resource.
 * @throws UnsupportedOperationException - if message type is not supported
 */
public Bundle convertToBundle(String hl7MessageData, ConverterOptions options, HL7MessageEngine engine) {
    Preconditions.checkArgument(StringUtils.isNotBlank(hl7MessageData), "Input HL7 message cannot be blank");
    if (engine == null) {
        engine = getMessageEngine(options);
    }
    Message hl7message = getHl7Message(hl7MessageData);
    if (hl7message != null) {
        String messageType = HL7DataExtractor.getMessageType(hl7message);
        HL7MessageModel hl7MessageTemplateModel = messagetemplates.get(messageType);
        if (hl7MessageTemplateModel != null) {
            return hl7MessageTemplateModel.convert(hl7message, engine);
        } else {
            throw new UnsupportedOperationException("Message type not yet supported " + messageType);
        }
    } else {
        throw new IllegalArgumentException("Parsed HL7 message was null.");
    }
}
Also used : HL7MessageModel(io.github.linuxforhealth.hl7.message.HL7MessageModel) Message(ca.uhn.hl7v2.model.Message)

Example 2 with HL7MessageEngine

use of io.github.linuxforhealth.hl7.message.HL7MessageEngine in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7ToFHIRConverter method convert.

/**
 * Converts the input HL7 message (String data) into FHIR bundle resource.
 *
 * @param hl7MessageData Message to convert
 * @param options Options for conversion
 *
 * @return JSON representation of FHIR {@link Bundle} resource.
 * @throws UnsupportedOperationException - if message type is not supported
 */
public String convert(String hl7MessageData, ConverterOptions options) {
    HL7MessageEngine engine = getMessageEngine(options);
    Bundle bundle = convertToBundle(hl7MessageData, options, engine);
    return engine.getFHIRContext().encodeResourceToString(bundle);
}
Also used : HL7MessageEngine(io.github.linuxforhealth.hl7.message.HL7MessageEngine) Bundle(org.hl7.fhir.r4.model.Bundle)

Example 3 with HL7MessageEngine

use of io.github.linuxforhealth.hl7.message.HL7MessageEngine in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7ToFHIRConverter method getMessageEngine.

private HL7MessageEngine getMessageEngine(ConverterOptions options) {
    Preconditions.checkArgument(options != null, "options cannot be null.");
    FHIRContext context = new FHIRContext(options.isPrettyPrint(), options.isValidateResource(), options.getProperties(), options.getZoneIdText());
    return new HL7MessageEngine(context, options.getBundleType());
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) HL7MessageEngine(io.github.linuxforhealth.hl7.message.HL7MessageEngine)

Aggregations

HL7MessageEngine (io.github.linuxforhealth.hl7.message.HL7MessageEngine)2 Message (ca.uhn.hl7v2.model.Message)1 FHIRContext (io.github.linuxforhealth.fhir.FHIRContext)1 HL7MessageModel (io.github.linuxforhealth.hl7.message.HL7MessageModel)1 Bundle (org.hl7.fhir.r4.model.Bundle)1