--------------- START ASHM CODE---------------- -- Family history mentions liver cancer AND EXISTS ( SELECT 1 FROM MD_PATIENT_CLINICAL pc WHERE pc.PATIENT_ID = patient.PATIENT_ID AND pc.FAMILY_HISTORY LIKE '%liver%cancer%' ) -- OR: Patient has a NoK whose family history mentions liver cancer OR EXISTS ( SELECT 1 FROM ( SELECT nok.PATIENT_ID, nok.RELATION_ID, nok.RELATIONSHIP FROM CM_NEXT_OF_KIN nok ) AS nok JOIN MD_PATIENT_CLINICAL rel_pc ON rel_pc.PATIENT_ID = nok.RELATION_ID WHERE nok.PATIENT_ID = patient.PATIENT_ID AND rel_pc.FAMILY_HISTORY LIKE '%liver%cancer%' ) -- OR: Patient has a NoK with liver cancer in their medical history OR EXISTS ( SELECT 1 FROM ( SELECT nok.PATIENT_ID, nok.RELATION_ID, nok.RELATIONSHIP FROM CM_NEXT_OF_KIN nok ) AS nok JOIN MD_HISTORY rel_hist ON rel_hist.PATIENT_ID = nok.RELATION_ID WHERE nok.PATIENT_ID = patient.PATIENT_ID AND ( -- Cover freetext scenarios where a practitioner has opted to not use -- a coded diagnosis rel_hist.CONDITION LIKE '%liver%cancer%' OR rel_hist.COMMENT LIKE '%liver%cancer%' OR rel_hist.CONDITION LIKE '%hepatocellular%carcinoma%' OR rel_hist.COMMENT LIKE '%hepatocellular%carcinoma%' OR -- Hepatocellular carcinoma and Hepatoma code back to `carc.live` -- But only if the practitioner used a coded diagnosis rel_hist.HISTORY_CODE LIKE 'carc.live' ) ) --------------- END ASHM CODE----------------