With the growing attention to evidence-based medical guideline development, longitudinal analysis of Electronic Medical Records (EMR) has become a good tool for providing insight into and new knowledge on the existing therapy. For chronic diseases, longitudinal analysis of medication history plays a key role in reaching this goal. However, raw medication data in EMR are not suitable for longitudinal analysis for several reasons. First, many prescriptions have a short duration. Second, the prescription duration may have a gap or overlap with other prescription durations. Additionally, for diabetes cases, physicians must wait for a certain period to observe the effectiveness of the medication. However, the existing methods do not address these conditions. To tackle these issues, we propose a set of rules for medication episode reconstruction. We then apply the rules for longitudinal analysis on anonymous Type 2 diabetes patients' EMR provided by Kyoto University Hospital. The EMR span from 2000 to 2015. Two of our significant results are as follows: (1) our proposed medication episode reconstruction method is able to compress the search space into 23.83% compared to the raw data, and (2) the preliminary results show the benefits of the method in revealing the existing medication patterns over the years and unfamiliar therapy transition.