# coding:utf-8
def splittxt(ImagingConclusion):
    ImagingConclusion = ImagingConclusion + "\n"
    ImagingConclusion = ImagingConclusion.replace("\nAE1/AE3", " AE1/AE3")
    ImagingConclusion = ImagingConclusion.replace("\nEGFR", " EGFR")
    ImagingConclusion = ImagingConclusion.replace("\nCK", " CK")
    ImagingConclusion = ImagingConclusion.replace(":\n", ": ")
    txt = []
    text = []
    ImagingConclusionFrist = ""
    CuttingEdge = ""
    CuttingLymph = ""
    MolecularResults = ""
    Immunohistochemistry = ""
    CuttingEdgeID = -1
    CuttingLymphID = -1
    MolecularResultsID = -1
    ImmunohistochemistryID = -1
    delete = []
    for i, char in enumerate(ImagingConclusion):
        if char != '\n':
            txt.append(char)
        else:
            if txt != []:
                str = ''.join(txt)
                text.append(str)
                txt = []
    for i, block in enumerate(text):
        if block.find("送检切缘") != -1:
            CuttingEdgeID = i
            CuttingEdge = CuttingEdge + block + "\n"
            delete.append(CuttingEdgeID)
        elif block.find("送检淋巴结") != -1:
            CuttingLymphID = i
            CuttingLymph = CuttingLymph + block + "\n"
            delete.append(CuttingLymphID)
        elif block.find("分子结果") != -1:
            MolecularResultsID = i
            MolecularResults = MolecularResults + block + "\n"
            delete.append(MolecularResultsID)
        elif block.find("免疫组化结果") != -1:
            ImmunohistochemistryID = i
            Immunohistochemistry = Immunohistochemistry + block + "\n"
            delete.append(ImmunohistochemistryID)
    j = 0
    for i in range(len(text)):
        if i in delete:
            text.pop(j)
        else:
            ImagingConclusionFrist = ImagingConclusionFrist + text[j] + "\n"
            j = j + 1
    
    MolecularResults.replace(":", "")
    Immunohistochemistry.replace(":", "")
    MolecularResults = MolecularResults[MolecularResults.find("分子结果") + 4:]
    Immunohistochemistry = Immunohistochemistry[Immunohistochemistry.find("免疫组化结果") + 6:]
    return ImagingConclusionFrist, CuttingEdge, CuttingLymph, MolecularResults, Immunohistochemistry


# print(splittxt(
#     "原发灶:一带黏膜组织6*5*3cm,切面见一肿块3*2*2cm,灰白,界不清(1)\n送检切缘:前、后、内、外、底均0.5cm\n左颈大块:6*4*2cm,为脂肪血管及少量腺体,灰黄。\n左I区: 7只直径0.8-1.2cm。\n左II区: 1只直径1cm。\n左III区: 1只直径1.5cm。\n\n“左舌”黏膜鳞状细胞癌,高-中分化,DOI>10mm\n送检切缘:“前、后、内、外、底”均阴性(-)\n“左颌下腺”轻度慢性炎\n送检淋巴结:“左”“I”1/7只有肿瘤转移(+),余及“II”1只(为软组织),“III”1只(为软组织)均阴性(-)\n免疫组化结果NI21-668\nAE1/AE3+ CKH+ CK5/6+ EGFR部分+ Ki67部分+ CD31- S-100- P16-\n北院分子结果(NM2021-0302):EGFR扩增探针 FISH(未见明显扩增(-))\n"))

if __name__ == '__main__':
    a = splittxt("""
“右上颌”黏膜鳞状细胞癌,高-中分化,DOI>10mm
“右颌下腺”慢性炎
送检淋巴结:“右I区”1/5只(其中1只为软组织)有肿瘤转移(+),余及“右II区”6只、“右III区”6只、“右IV区”1只(为软组织)、“右V区”10只均阴性(-)
南院分子结果(M2021-1469):EGFR扩增探针 FISH(-)
南院免疫组化结果(I2021-3111):CKH(+),CK5/6(+),P16(-),Ki67(热点区约30-40%+),CD31(-),S100(-),EGFR(+),P53(-)。
""")
    for i in a:
        print(i.strip())
        print('---------------------------')