AnonymisationService { public String pseudonymisePersonHTML(Patient patient, String text) { Document document = Jsoup.parse(text); traverseAndAnonymise(document, patient); return document.toString(); }  String pseudonymisePersonHTML(Patient patient, String text); String pseudonymisePersonPlainText(Patient patient, String text); void setNamePseudonymiser(NamePseudonymiser namePseudonymiser); void setPhonePseudonymiser(PhonePseudonymiser phonePseudonymiser); void setDateOfBirthPseudonymiser(DateOfBirthPseudonymiser dateOfBirthPseudonymiser); void setNhsNumberPseudonymiser(NHSNumberPseudonymiser nhsNumberPseudonymiser); void setAddressPseudonymiser(AddressPseudonymiser addressPseudonymiser);  }
@Test public void shouldAnonymisePatientCarer() throws ParseException { Patient patient = new Patient(); patient.addForeName("Ismail"); patient.addSurname("Kartoglu"); patient.addNhsNumber("11111"); PatientAddress patientAddress1 = new PatientAddress(); patientAddress1.setAddress("addressText"); patientAddress1.setPostCode("cb4 2za"); PatientAddress patientAddress2 = new PatientAddress(); patientAddress2.setAddress("addressText"); patientAddress2.setPostCode("cb4 2za"); patient.addAddress(patientAddress1); patient.addAddress(patientAddress2); patient.addPhoneNumber("50090051234"); patient.addPhoneNumber("11090051234"); patient.addDateOfBirth(TimeUtil.getDateFromString("09/05/1990", "dd/MM/yyyy")); patient.addCarer(new PatientCarer("xyz", "abc")); String anonymisedText = anonymisationService.pseudonymisePersonHTML(patient, "<html>\n" + "<body>\n" + "<h>Ismail</h>\n" + "\n" + "<div>Ismail Kartoglu is our patient. His carer is XYZ ABC</div>\n" + "<div>His phone number is: 32123123456 and 50090051234</div>\n" + "<div>His post code is cb4 2za addressText</div>\n" + "NHS number 11122\n Date of birth is 09/05/1990" + "Ism MrK\n" + "\n" + "\n" + "</body>\n" + "</html>"); assertTrue(anonymisedText.contains("carer is YYYYY YYYYY")); }
@Test public void shouldAnonymisePatient() throws ParseException { Patient patient = new Patient(); patient.addForeName("Ismail"); patient.addSurname("Kartoglu"); patient.addNhsNumber("11111"); PatientAddress patientAddress1 = new PatientAddress(); patientAddress1.setAddress("addressText"); patientAddress1.setPostCode("cb4 2za"); PatientAddress patientAddress2 = new PatientAddress(); patientAddress2.setAddress("addressText"); patientAddress2.setPostCode("cb4 2za"); patient.addAddress(patientAddress1); patient.addAddress(patientAddress2); patient.addPhoneNumber("50090051234"); patient.addPhoneNumber("11090051234"); patient.addDateOfBirth(TimeUtil.getDateFromString("09/05/1990", "dd/MM/yyyy")); String anonymisedText = anonymisationService.pseudonymisePersonHTML(patient, "<html>\n" + "<body>\n" + "<h>Ismail</h>\n" + "\n" + "<div>Ismail Kartoglu is our patient.</div>\n" + "<div>His phone number is: 32123123456 and 50090051234</div>\n" + "<div>His post code is cb4 2za addressText</div>\n" + "NHS number 11122\n Date of birth is 09/05/1990 09th May " + "Ism MrK\n" + "\n" + "\n" + "</body>\n" + "</html>"); assertTrue(anonymisedText.contains("XXXXX")); assertTrue(anonymisedText.contains("Date of birth is DDDDD")); assertTrue(anonymisedText.contains("post code is PPPPP")); assertFalse(anonymisedText.contains("09th May")); }
@Test public void shouldNotReplaceHtmlTags() { Patient patient = new Patient(); patient.addForeName("rich"); patient.addForeName("richard"); patient.addSurname("Jackson"); patient.addNhsNumber("11122"); PatientAddress patientAddress1 = new PatientAddress(); patientAddress1.setAddress("addressText"); patientAddress1.setPostCode("cb4 2za"); PatientAddress patientAddress2 = new PatientAddress(); patientAddress2.setAddress("addressText"); patientAddress2.setPostCode("cb4 2za"); patient.addAddress(patientAddress1); patient.addAddress(patientAddress2); patient.addPhoneNumber("50090051234"); patient.addPhoneNumber("11090051234"); String anonymisedText = anonymisationService.pseudonymisePersonHTML(patient, "<html>\n" + "<body>\n" + "<rich>Richard RICH Jackson</rich>\n" + "\n" + "Ism MrK\n" + "\n" + "\n" + "</body>\n" + "</html>"); assertTrue(anonymisedText.contains("<rich>")); assertTrue(anonymisedText.contains("XXXXX XXXXX XXXXX")); }