reporting major cancers with checklists / synoptic reports has been a mandated requirement by college of american pathologists and the american college of surgeons - commission on cancer .
the use of the synoptic reporting format helps to ensure the completeness of the reports and lessen the chance of pathologists omitting relevant information ; format consistency also makes it easier for the treating physicians to grasp all the relevant information .
the underlying mechanisms for generating and storing information for synoptic reports may vary , including both a continuous string of text and as structured individualized elements .
since the communication of the information to the treating physician is text - based reports , this variability does not affect the treating physicians or the individual patients treated .
however , it does have implications on how pathologists prepare the reports , whether there is added cost involved in generating the reports , how the data are reported to the cancer registrars , and how readily the underlying information can be retrieved and used for the purpose of research and quality assurance .
different approaches have been used to extract individual elements in the pathology reports . natural language processing ( nlp )
has been used to extract information from breast carcinoma pathology reports with variable degrees of success .
recently , boag described a simpler yet powerful approach : programing language r was used to extract and analyze data from discrete synoptic pathology reports ( from the reports of prostate needle core biopsies ) .
first , all the reports with synoptic reports of prostate needle core biopsies were retrieved using a built - in report retrieving mechanism of their pathology information system .
these report texts were uniformly formatted and consistently phrased since they were generated by a third - party software that captures individual data elements discretely ( mtuitive xpert cancer reporting version 3 software , mtuitive corporation , centerville , ma , usa ) .
second , after file - type conversion , the texts were read into r , and the individual data elements were extracted and used for analysis . using melanoma of skin as an example , the above approach has been extended in the following ways : having r script directly interact with the database ( through rodbc package ) , applying r to nonuniformly formatted and semi - consistently expressed report texts , and performing lesion - specific retrieval and analysis across multiple reports .
the process is described in sufficient detail , including providing key portions of the r code , so as to enable readers with some r programing knowledge to test out the approach in their own systems .
the computer workstation is a desktop pc with intel(r ) core(tm ) i5 - 3470 cpu @ 3.20ghz , 4 gb ram . the pathology information system is powerpath 10.0.0.19 ( sunquest ) , with advanced material processing module .
open source programing language r version 3.3.1 ( https://www.r-project.org ) is used for interacting with powerpath database and for data extraction , tidying , and analysis .
rstudio version 0.99.489 ( https://www.rstudio.com ) is the integrated development environment used for both running the r script and interactively analyzing the data .
figure 1 shows the r script used to retrieve data from the powerpath database and to extract the elements of interest from the retrieved data .
the lines starting with hash mark ( # ) are the comment lines for human readers only .
the script first loads the required packages : rodbc , dplyr , stringr , gdata , splitstackshape , and ggplot2 .
it then makes a connection to the database , retrieves data , and closes the connection .
the server ip address , uid , and pwd in the line to open a connection to database have been modified to protect the security of the system .
the retrieved data are in the format of r data frame with 4 columns : accession number , patient i d , created date , and text containing the melanoma of skin synoptic report .
conn < - odbcdriverconnect(driver={sql server } ; server = 192.168.*. * * * , * * * * ; database = pathology _ database ; uid = jay_ye ; pwd = open_sesame  )  is modified for confidentiality .
twenty - nine ( 29 ) lines of code for selecting out synoptic reports corresponding to unique lesions are omitted .
see materials and methods for additional description in our system , not every synoptic report represents a unique lesion .
reports of some lesions are copied and re - accessioned under a different case number for the subsequent molecular send out tests .
these repetitions have the acc_type of 184 in our database and are excluded from the retrieval by adding the condition 
< > 184  to the where clause of the query . among the retrieved synoptic reports , while most patients have only one synoptic report , a minority of patients have multiple different synoptic reports that represent the following situations : ( 1 ) one synoptic report for biopsies , followed by one for excisions with or without concomitant lymph node biopsies , ( 2 ) metachronous multiple primaries , and ( 3 ) synchronous multiple primaries .
the following rules are set to programmatically obtain a data frame with each synoptic report corresponding to a unique lesion of melanoma . for patients with two synoptic reports ,
if the dates of these two reports are within 120 days , the second synoptic report is treated as the synoptic report for the excision specimen and only the second synoptic report is kept for data extraction . if the two reports are more than 120 days apart , the synoptic reports are treated as two different primary melanomas and both reports are kept for data extraction . if the patient has more than two reports , only the last one is kept for data extraction .
since these are futures idiosyncratic to our system , the code to obtain a data frame containing synoptic reports for unique lesion is not discussed in detail .
then , the script reads a. txt file [ figure 2 ] into memory so that it has the information as to what elements to extract .
subsequently , the script extracts the elements of interest from the retrieved data and adds each element as a new column of the data frame .
content of text file ( .txt ) containing elements of interest that are to be extracted from the text of melanoma synoptic report .
each line of the file is used in line  pattern < -paste0(mycolnames[i],(.*)?\r\n  )  to form portion of a regular expression text pattern for data element extraction ; the extraction is performed in the immediate following line  element < -str_match ( ms$finding_text , pattern)[,2 ]  combining breslow depth of melanoma obtained from two different formats of synoptic reports , extracting the numeric value and the subsequent summary analysis using these values are shown below : the two columns of data  maximumtumorthickness  and  depthofinvasion  can be merged to form a new column  depth  : depth<-coalesce ( ms$maximumtumorthickness , ms$depthofinvasion ) then , the merged data can be used to extract the numeric portion of the text , converted to the r numeric data type , and added to the original data frame : pured<-str_match ( depth,([0 - 9.]{1 , 5})(.*)?(mm  millimeter )  ) breslowdepth<-as.numeric ( pured[,2 ] ) ms<-cbind ( ms , 
breslowdepth ( mm) = breslowdepth ) using the case number of retrieved list of cases , for each case , the script goes back to powerpath database to retrieve subsequent reports within 120 days of the synoptic report for the same patient .
patient i d associated with the accession number of the synoptic report is used to bridge the synoptic reports and the subsequent reports .
the particular query used in our system is as follows ( myaccnum is the variable containing the accession number of the synoptic report ) : declare @acc_num varchar ( 60 ) set @acc_num myaccnum select accession_no , coalesce ( finding , finding_text ) as report from path_rpt_heading as heading join acc_results r on heading.id=r.heading_id join accession_2 a on r.acc_id=a.id where acc_id in ( select i d from accession_2 where patient_id=(select patient_id from accession_2 where accession_no = @acc_num ) ) and a.accession_no > @acc_num and a.created_date < = ( select dateadd ( day , 120 , a2.created_date ) from accession_2 a2 where a2.accession_no = myaccnum ) and a.acc_type_id < > 184 and accession_no like  s-% and ( heading.name like  comment% or heading.name like 
diagnosis% or heading.name like  amended diagnosis% ) powerpath implemented the database table in such a way that each section of the report text , such as diagnosis , comment , clinical information , gross description , and so on , is stored in different rows , and they are stored in either column  finding  or column  finding_text  ( but not both ) depending on the length of the text for the given section .
the column - wise concatenation was performed within sql query using the function coalesce , and the row - wise concatenation for each report was performed within r. the resulting data frame  reportbycase  contained diagnosis , comment , and amended diagnosis section of the report text for each retrieved report .
many reports of lymph node biopsies contain a summary sentence in the comment such as  the updated melanoma stage is pt1a , pn0 , and pmx .
 the staging information from such reports can be extracted using the following r code : reportbycase$pt < -str_match ( reportbycase$report,(melanoma  melanoma)(.*)?(pt[a - oq - wyza - mo - wyz0 - 9]{1,3}))[,4 ] reportbycase$pn < -str_match ( reportbycase$report,(melanoma  melanoma)(.*)?(pn[a - oq - wyza - wyz0 - 9]{1,3})(.sn.)?)[,4 ] reportbycase$pm < -str_match ( reportbycase$report,(melanoma  melanoma)(.*)?(pm[a - oq - wyza - wyz0 - 9]{1,3}))[,4 ] the following code is used for the report text when the extraction described above returns na : if ( is.na ( reportbycase$pn[i ] ) ) { if ( ! is.na ( str_match ( reportbycase$report[i],(melanoma  melanoma  melan )  ) ) and ! is.na ( str_match ( reportbycase$report[i],(sentinel  sentinel  node )  ) ) ) { if ( ! is.na ( str_match ( reportbycase$report[i ] ,  \\([1 - 9]/  ) ) ) { reportbycase$pn[i ] < -  pnp } else if ( ! is.na ( str_match ( reportbycase$report[i ] ,  \\(/  ) ) ) { reportbycase$pn[i ] < -  pn0 reportbycase$pn[i ] < -  pn? the above code utilizes the observation that many lymph node reports , even without summarizing sentences , would include the ratio of positive nodes to the total number of nodes within parentheses in the diagnosis for each specimen such as 0/1 denoting one node being negative and 2/3 denoting two of three nodes being positive .
three potential results can be retrieved : pn0 , pnp ( at least one node is positive ) , and pn ?
( there is a lymph node biopsy , but the result is not automatically retrievable ) .
the highest stage obtained from all the subsequent reports is used as the updated staging information for that patient . the highest stage for pt , pn , and
< - as.character(max(reportbycase$pm , na.rm = true ) ) this process is repeated for each synoptic report .
the relationship between the lymph node status and breslow depth of melanoma was then explored to demonstrate that information dispersed among different reports can be collated and used for data analysis .
two dermatopathologists in the group happen to have used different synoptic reports for melanoma of skin [ figure 3a and b ] . this necessitates the r script to be written in such a way that information from both synoptic reports is extracted .
figure 2 is a file containing the elements of interest from both formats of synoptic reports .
if the text of the element of interest contains parentheses , a backslash ( \ ) , which is an escape character for regular expression , needs to be added before both the open parenthesis and close parenthesis .
( a ) an example of melanoma of skin synoptic report by pathologist a. ( b ) an example of melanoma of skin synoptic report by pathologist b when an r script depicted in figure 1 [ with the connection string modified , see figure legend for figure 1 ] is run to retrieve from 4 years of data of roughly 50 k cases / per year database ( approximately 14 k skin cases / year ) , 440 synoptic reports are retrieved .
four hundred and twenty - six synoptic reports are considered to represent unique lesions using the rules described in materials and methods for programmatic selection .
eight of them have the pairs < 120 days apart and are correctly classified as re - excision of the same lesion ; only the second synoptic reports are retained .
nine have the pair of synoptic reports more than 120 days apart , and they are correctly classified as metachronous primaries ; both synoptic reports are retained .
two patients have three and five synoptic reports , representing two and four primaries , respectively . only the last synoptic reports of these two patients
are included ; the others ( a total of four lesions ) are excluded due to the unmanageable complexity of multiple lesions .
there are also two patients with two synchronous primaries ( two synoptic reports within the same report ) ; they are included in the within - report summary but excluded from searching for the updated staging information from the subsequent report ( value for column  can not update  is set to true [ figure 4a ] ) since the script does not have a good way to attribute which update goes to which primary .
the result is an r data frame with 426 rows and 33 columns ( four columns are retrieved data , one column is  can not update ,  and 28 columns are extracted elements ) .
( a ) microsoft word table rendition of portion of r data frame showing the four columns of retrieved data and one column of generated element .
created_date ,  and  finding_text  are data retrieved from powerpath database . the 5 column  cannotupdate  is used subsequently to determine if updated staging information will be obtained from the subsequent reports .
finding_text  contains large chunks of text data including the synoptic reports ; only the first few words are displayed in the table .
( b ) microsoft word table rendition showing portion of an r data frame containing two columns of extracted elements and one column of tidy data ( breslowdepth[mm ] ) derived from the first two columns a portion of this initial r data frame generated by the script is converted to microsoft word table format and shown in figure 4a .
figure 4b depicts the three depth - related columns of data that have been subsetted out ( selected out ) for the demonstration purpose . using the data in column 
breslowdepth(mm )  and a new column containing year information extracted from column  created_date ,  distribution of breslow depth grouped by year can be plotted [ figure 5 ] .
this graph is made using data in the column named breslowdepth ( mm ) , and the data are grouped by the year when the surgical procedure was performed the data retrieval and analysis described above is based on the individual reports that contain the melanoma of skin synoptic reports .
many patients have multiple subsequent reports that might contain additional information such as lymph node status and distant metastasis .
the script uses the case numbers obtained from the initial retrieval to go back to the database to retrieve any additional reports on the same patient within 120 days of the synoptic reports .
figure 6a shows the distribution of the number of subsequent reports for each synoptic report . for these 422 lesions ( four lesions are excluded because they represent two synchronous primaries from two patients , and the current script does not have the ability to discern which primary the update information should be attributed to ) , a total of 424 subsequent surgical pathology reports exist within 120 days from the dates of the synoptic reports , with a median of 1 and an average 1.0 .
( a ) distribution of the number of subsequent reports ( within 120 days from the date of the synoptic report ) for each synoptic report .
( b ) microsoft word table rendition showing portion of an r data frame containing a list of reports with subsequent reports containing staging information .
synoptic_pn ,  and  synoptic_pm  are staging information extracted from the synoptic reports .
 tnm_subsequentrpt  stores the pt , pn , and pm staging information retrieved from the subsequent report(s ) , as well as the number of subsequent reports associated with that lesion .
pn0 , pn1 , pn2 , and pn3 are categories with precise pn information ; pn ?
and pnp are categories with imprecise staging information , denoting nodal staging information present and node positive , respectively .
the bottom and top of the boxes are the first and third quartiles , and the band inside the box is the median .
the whiskers extend to the most extreme data point that is not more than 1.5 times of the length of the box away from the box figure 6b shows portion of the data frame containing staging information from both the original synoptic reports and subsequent reports .
all of the above synoptic reports and the subsequent pathology reports associated with the synoptic reports are reviewed manually .
there is no useful update information on pt in any of the cases ; all the pt information is from the synoptic reports .
there are a total of 94 opportunities for pn update . in 54 of them ,
the subsequent reports on lymph nodes contain the summary sentence that summarizes pt , pn , and pm ; pn is retrieved correctly from each one of them . in 27 reports ,
the ratio of positive to total number of nodes is present within the diagnoses of the lymph nodes ; 23 of them were retrieved as pn0 and 4 of them were retrieved as pnp ( the current script knows that the nodes are positive but does not have a way to know how many are positive ) . in ten reports , the reports do not contain either summary sentence or put the ratio of nodes within a pair of parentheses ; the script retrieves 
pn ?  ( there is at least one lymph node biopsy , but the script can not extract the results ) .
there are three cases that are beyond 120 days from the date of synoptic reports , and the information is not retrieved . in summary , the current script retrieves the pn information precisely with an 82% sensitivity ( [ 54 + 23]/94 ) .
the specificity of retrieved results is 100% , i.e. , there is no erroneous retrieval . for nine pairs of metachronous primary melanomas ,
two pairs have updated pn information for one of the two lesions . each was retrieved and correctly assigned to the corresponding primary . setting the 120 days limit also prevents erroneously updating the pt information of the first lesion by the pt of the second lesion .
this combined data ( without additional human intervention to convert partial retrieval to precise retrieval ) are used to graph the relationship between breslow depth and nodal status [ figure 6c ] .
the nodal status represents combined data from both the original reports with synoptic reports and reports on the subsequent specimens from the same patients . with human intervention to retrieve the pn information by reading the reports that the script partially retrieves the information ( 14 lesions ) , a plot with precise information can also be obtained with minimal added effort ( graph not shown ) .
the graph is used here to demonstrate that this approach can be used to extract data from different reports of the same patients to perform a meaningful analysis .
nodal status represents combined data from both the original reports with synoptic reports and reports on the subsequent specimens from the same patients .
there is no useful update information on pm in any of the cases since we have not reported the updated pm staging information in an easily extractable fashion when a distant metastasis has been detected in subsequent specimens .
synoptic reports differ from free - text reports in that the synoptic reports are formatted in such a way that the reports contain a list of elements , and each element has a descriptive header preceding it . the format consistency of the synoptic reports not only assists pathologists in generating reports that are complete but also makes it easier for the treating physicians to gather information from the reports . in this article , melanoma of the skin
is used as an example and programing language r as a tool to demonstrate that individual data elements included in the text within cancer synoptic reports can be extracted directly from relational database and analyzed in a lesion - specific fashion .
the formatted nature of the synoptic reports and the consistent nature of how pathologists phrase the contents of the elements are two crucial features making the above tasks possible . from the computational point of view , a 
histologic grade :  so that r script knows where to extract the element histologic grade . with these tags
, the sensitivity and specificity of the element extraction should be 100% . from the results section
, one can see that both dermatopathologists use synoptic reports to report melanoma of the skin .
however , it does provide an opportunity to demonstrate the flexibility of the approach in handling the variability in report formats .
thus , as long as the elements are tagged , whether they are uniformly tagged , or there are several varieties of tagging the same elements , the sensitivity of extraction is not affected .
the variability does require additional steps in the subsequent data processing , i.e. , requiring the data from the mutually exclusive columns in the r data frame to be combined into a single new column .
the ease of data analysis is mostly determined by how consistently the contents of the elements are phrased . for breslow depth ,
a small degree of variability exists but does not pose any difficulty in extraction . for , pt , pn , and pm , the expression is nearly 100% consistent . for the margin status ,
one pathologist uses  positive  and  negative  and one uses  involved  and  uninvolved .
 these differences do not pose difficulty in summarizing the data . in extracting the new staging information from the subsequent reports
, there is no specific tag to use ; as such , the consistency in phrasing is even more important .
it is a pleasant surprise that without prospective planning or prospective emphasis on consistent phrasing , 82% of the lymph node staging information in our database can be extracted precisely with 100% specificity .
since relational database ( sql database ) is the backend for the majority of the pathology information system and r script can run in many different platforms , the approach described here can be used in different pathology information systems to retrieve individual data elements from formatted pathology reports .
the previously reported methods for data extraction used two - step approaches including obtaining the report texts in step one and performing extraction and analysis in step two .
the integrated one - step approach enables the second round of queries of database using the results of the first query .
this allows the retrieval of information from other reports of the same patients ( lesions ) , instead of limiting the analysis to individual reports .
now , only one format of synoptic report for melanoma of the skin is used .
furthermore , a summary sentence is consistently used when encountering specimens that add staging information .
incorporating these small changes into our practice is not burdensome and will have beneficial effects on the future data extraction .
although to state that using r is easy is not true , one does not need to be a computer scientist to be able to learn and use r. i believe that using r as described in this article is easier than using the more complex approach of nlp .
the inclusion of r code for the key portions of the task is to make any potential attempt to duplicate this approach in other systems easier .
formatted pathology reports , such as but not limited to the cancer synoptic reports , can avail themselves to relatively simple data extraction and analysis using r extended with rodbc package .
the integrated one - step approach has two advantages : ( 1 ) it is not dependent on the retrieval capability of the specific pathology information system and thus can be used in any systems that use relational database as the backend ; and ( 2 ) it allows data extraction to occur across the boundaries of the pathology reports from multiple reports of the same patient for the disease or lesion of concern .
 background : different methods have been described for data extraction from pathology reports with varying degrees of success . here a technique for directly extracting data from relational database is described.methods:our department uses synoptic reports modified from college of american pathologists ( cap ) cancer protocol templates to report most of our cancer diagnoses . choosing the melanoma of skin synoptic report as an example , r scripting language extended with rodbc package was used to query the pathology information system database . 
 reports containing melanoma of skin synoptic report in the past 4 and a half years were retrieved and individual data elements were extracted . using the retrieved list of the cases , the database was queried a second time to retrieve / extract the lymph node staging information in the subsequent reports from the same patients.results:426 synoptic reports corresponding to unique lesions of melanoma of skin were retrieved , and data elements of interest were extracted into an r data frame . 
 the distribution of breslow depth of melanomas grouped by year is used as an example of intra - report data extraction and analysis . when the new pn staging information was present in the subsequent reports , 82% ( 77/94 ) was precisely retrieved ( pn0 , pn1 , pn2 and pn3 ) . 
 additional 15% ( 14/94 ) was retrieved with certain ambiguity ( positive or knowing there was an update ) . 
 the specificity was 100% for both . 
 the relationship between breslow depth and lymph node status was graphed as an example of lesion - specific multi - report data extraction and analysis.conclusions:r extended with rodbc package is a simple and versatile approach well - suited for the above tasks . 
 the success or failure of the retrieval and extraction depended largely on whether the reports were formatted and whether the contents of the elements were consistently phrased . 
 this approach can be easily modified and adopted for other pathology information systems that use relational database for data management . 
INTRODUCTION
MATERIALS AND METHODS
RESULTS
DISCUSSION
CONCLUSION
Financial Support and Sponsorship
Conflicts of Interest