0

i have data in database. i need to take that data in json format and convert into HL7 format. can anyone help me on this?

this to done in spring boot

Mahidhar
  • 1
  • 2

2 Answers2

0

This might not be exactly what you are looking for but could be useful.

enter link description here

This is anothor thread i found on coverting HL7 to Json.

enter link description here

Chamodh
  • 61
  • 1
  • 3
  • 11
0

Fetch the data using spring boot data jpa, map that data to Java Object (HL7Message), create a convertor using HAPI HL7 API.

<dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-base</artifactId>
        <version>2.3</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/ca.uhn.hapi/hapi-structures-v25 -->
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v25</artifactId>
        <version>2.3</version>
    </dependency>

Write a convert method something like

public OMI_O23 convert(HL7Message hl7Message) {
    // ORM_O01 message = new ORM_O01();

    OMI_O23 message = new OMI_O23();

    MSH msh = message.getMSH();

    HapiContext hapiContext = null;

    try {
        setMessageHeader(msh);

        OMI_O23_PATIENT patient = message.getPATIENT();

        if (patient != null) {
            log.debug("Setting patient data");
            setPatientData(hl7Message, patient);
        }

        if (patient != null) {
            log.debug("Setting referring Vet Data");
            setReferringVetData(hl7Message, patient);
        }

        if (patient != null) {
            log.debug("Setting performing Vet data");
            setPerformingVet(hl7Message, patient);
        }

        log.debug("Setting Study data");
        setStudyData(hl7Message, message);

        log.debug("Setting ORC data");
        setORCSegment(hl7Message, message);

        log.debug("Setting owner data");
        // setOwnerData(hl7Message, patient);

        log.debug("Setting OBR data");
        setOBRSegment(hl7Message, message);

        // log.debug("setting ZDS data");
        // setZDSSegment(hl7Message,message);
    } catch (HL7Exception e) {
        log.error(e);
    } finally {
        if (hapiContext != null) {
            try {
                hapiContext.close();
            } catch (IOException e) {
                log.error(e);
            }
        }
    }

    return message;
}

To convert your HL7 Message in String write a parser.

public String getHL7StrMessage(OMI_O23 message) {

    String result = null;
    String FLD_SEP = "|";
    String ENC_CHAR = "^~\\&";

    try {
        // Parse the message
        HapiContext hapiContext = new DefaultHapiContext();
        message.getMSH().getFieldSeparator().setValue(FLD_SEP);
        message.getMSH().getEncodingCharacters().setValue(ENC_CHAR);

        log.debug("Parsing and encoding the OMI_O23 message");
        Parser parser = hapiContext.getPipeParser();

        result = parser.encode(message);
        log.debug(result);
    } catch (HL7Exception e) {
        log.error(e);
    }
    return result;
}

I hope this will help.

Govil Kumar
  • 130
  • 2
  • 2
  • 10