|
- package de.uniluebeck.mi.projmi6.hapi;
-
- import ca.uhn.hl7v2.HL7Exception;
- import ca.uhn.hl7v2.model.DataTypeException;
- import ca.uhn.hl7v2.model.Message;
- import ca.uhn.hl7v2.model.v251.datatype.DTM;
- import ca.uhn.hl7v2.model.v251.segment.MSH;
- import de.uniluebeck.mi.projmi6.db.DBHandler;
- import de.uniluebeck.mi.projmi6.model.HL7LogEntry;
-
- import java.sql.SQLException;
- import java.time.LocalDateTime;
- import java.time.ZoneId;
- import java.util.Map;
-
- /**
- * Created by nils on 20.11.2015.
- */
- public class HL7Utils {
- public static LocalDateTime parseLocalDateTime(DTM dtm) {
- try {
- return LocalDateTime.ofInstant(dtm.getValueAsDate().toInstant(), ZoneId.systemDefault());
- } catch (DataTypeException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public static void logHL7MessageToDatabase(HL7LogEntry entry) {
- try {
- DBHandler.setHL7LogEntry(entry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- public static void logInHL7MessageToDatabase(Message message, MSH msh, Map<String, Object> metadata) throws HL7Exception {
- logHL7MessageToDatabase(message, msh, metadata, HL7LogEntry.Direction.IN);
- }
-
- private static void logHL7MessageToDatabase(Message message, MSH msh, Map<String, Object> metadata, HL7LogEntry.Direction direction) throws HL7Exception {
- String sendind_ip = metadata.get("SENDING_IP").toString();
- String sendind_port = metadata.get("SENDING_PORT").toString();
- LocalDateTime ldt = parseLocalDateTime(msh.getDateTimeOfMessage().getTime());
-
- HL7LogEntry entry = new HL7LogEntry();
- entry.setMessage(message.encode());
- entry.setTimestamp(ldt);
- entry.setSource(sendind_ip + ":" + sendind_port);
- entry.setDirection(direction);
-
- logHL7MessageToDatabase(entry);
- }
- }
|