eCR/RCKMS Community of Practice

The purpose of the eCR/RCKMS Community of Practice Basecamp is to provide staff from state, local, territorial, and tribal public health agencies with a venue to participate in peer-to-peer discussions pertaining to using RCKMS. This Basecamp is not intended for formal communications about RCKMS or eCR and will not be moderated by CSTE staff. For technical issues or assistance with RCKMS, please visit www.rckms.org to submit a ticket. Disclaimer: The statements and responses posted on the eCR/RCKMS Community of Practice are solely the views of the authors and do not necessarily represent the official views of CDC or CSTE.

Easy/Quick eICR xml redacting?

Hi Team. Does anyone have a quick and easy way to redact names, DOB, and address from an xml without manually searching and deleting using Notepad++? We are spending a lot of time redacting xml files to send to NBS/AIMS for help requests, especially in the "Notes" section where patient and family member PHI is sometimes used. Thank you!

Jana Meridith (she/her)
eCR Coordinator
Maine Center for Disease Control and Prevention
jana.meridith@maine.gov | (707) 502-5739

Comments & Events

Sara Mader
Hi Jana,
I agree that de-identifying an XML is difficult. One thing that has helped me and maybe you all already use it, is using the replace feature in the search pop up box in Notepad++. Then you can put in the patient first name in the find box and a fake name in the replace box and then it will remove it in the whole document. This might be a little more difficult if a family name is only in the notes, you would still have to review. But it removes some of the steps in the document.  
I do the same thing with phone numbers. and nice where it will keep a history of what you have replaced so you can keep the fake one and then just add in different real numbers to replace.
And if it is within 7 days, AIMS should be able to find the eCR with just the doc ID. 
Not a lot of great workarounds.
thanks,
Sara 
Jana Meridith, Epidemiologist at Maine Department of Health and Human Services
That's helpful to hear, thank you Sara!
Michael Schneider, Epidemiologist at Connecticut Department of Public Health
Hey Jana, you could use R to redact files. This does have some limitations since the str_replace_all() function is case sensitive. This was done using a quick internet search, so others with more knowledge of R might be able to add to the code below.

library(xml2)
library(tidyverse)
library(stringr)

xml_file <- read_xml("input.xml")

lastname_real <- xml_file %>%
  xml_find_first("//patientRole/patient/name/family") %>%
  xml_text()

firstname_real <- xml_file %>%
  xml_find_first("//patientRole/patient/name/given") %>%
  xml_text()

xml_string <- as.character(xml_file)

updated_xml_string <- str_replace_all(xml_string, lastname_real, "Smith")
updated_xml_string <- str_replace_all(updated_xml_string, firstname_real, "Bob")

updated_xml_file <- read_xml(updated_xml_string)
write_xml(updated_xml_file, "output.xml")
Michael Schneider, Epidemiologist at Connecticut Department of Public Health
Updates to code below to make it more case insensitive and forgot to strip namespaces

library(xml2)
library(tidyverse)
library(stringr)

xml_file <- read_xml("input.xml")
xml_file_ns <- xml_ns_strip(xml_file)


lastname_real <- xml_file_ns %>%
  xml_find_first("//patientRole/patient/name/family") %>%
  xml_text()

firstname_real <- xml_file_ns %>%
  xml_find_first("//patientRole/patient/name/given") %>%
  xml_text()

xml_string <- as.character(xml_file)

lastname <- regex(lastname_real, ignore_case = TRUE)
firstname <- regex(firstname_real, ignore_case = TRUE)

updated_xml_string <- str_replace_all(xml_string, lastname, "Smith")
updated_xml_string <- str_replace_all(updated_xml_string, firstname, "Bob")

updated_xml_file <- read_xml(updated_xml_string)

write_xml(updated_xml_file, "output.xml")
Jana Meridith, Epidemiologist at Maine Department of Health and Human Services
Thank you Michael! I'm going to try this and I'll let you know how it goes!
Michael Brunjes, Epidemiologist at California Department of Public Health
If it is useful, text fields can be made all lower-case, or all upper-case, using str_to_lower() and str_to_upper() respectively. Both functions are in the stringr library. This can be nested in the str_replace_all(). I use this for text matching without modifying the original values.

Example:


updated_xml_string <- str_replace_all(string = str_to_lower(“SMITH”),

pattern = str_to_lower(lastname_real),

replacement = "Smith"))
Jana Meridith, Epidemiologist at Maine Department of Health and Human Services
Thank you Michael! It worked great! I used a reg-ex to replace all <given>XXXX</given> with <given>John</given> and Doe for the <family> tag....that was pretty easy, then just found all the notes and any that had text with names I replaced with "Redacted" Worked like a charm! 

-Jana 
Michael Schneider, Epidemiologist at Connecticut Department of Public Health
Michael Brunjes, Epidemiologist at California Department of Public Health Michael I was wondering if there was a way to do that. Thanks for the code, looking forward to giving it a try.
Cheers!