test_that("MSH segment parsing works", { msh_line <- "MSH|^~\\&|SAP-ISH|104|104|LEO|202301011200||ADT^A02|12345678|P|2.3" msh <- get_MSH(msh_line) expect_equal(msh$MESSAGE_CONTROL_ID, "12345678") expect_equal(msh$VERSION_ID, "2.3") }) test_that("PID segment parsing works", { pid_line <- "PID|1||12345||SMITH^JOHN^^^^^L||19800101|M" pid <- get_PID(pid_line) expect_equal(pid$INTERNAL_PATIENT_ID, "12345") expect_equal(pid$FIRST_NAME, "JOHN") expect_equal(pid$LAST_NAME, "SMITH") expect_equal(pid$GENDER, "M") }) test_that("EVN segment parsing works", { evn_line <- "EVN|A01|202301011200" evn <- get_EVN(evn_line) expect_equal(evn$EVENT_TYPE_CODE, "A01") }) test_that("get_HL7_LINE works", { data <- c("MSH|...", "PID|...", "NK1|...") line <- get_HL7_LINE(data, "PID|") expect_true(grepl("^PID\\|", line)) }) test_that("get_DATE_TIME works", { dt <- get_DATE_TIME("20230101120000") expect_equal(dt$DATE, "20230101") expect_equal(dt$TIME, "120000") }) test_that("empty input returns NULL", { expect_null(get_HL7_DATA(data = character(0))) })