package net.ihe.gazelle.ccd.test; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import net.ihe.gazelle.ccd.CCDValidator; import net.ihe.gazelle.cda.POCDMT000040ClinicalDocument; import net.ihe.gazelle.gen.common.ConstraintValidatorModule; import net.ihe.gazelle.validation.DetailedResult; import net.ihe.gazelle.validation.MDAValidation; import net.ihe.gazelle.validation.Notification; import org.junit.Assert; import org.junit.Test; public class CCDTest { @Test public void test_constraint_ccd_code() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1001.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_code"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1002.xml"); nn = selectNotification(res, "error", "constraint_ccd_code"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1003.xml"); nn = selectNotification(res, "error", "constraint_ccd_code"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_documentationOf_serviceEvent() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1004.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_documentationOf_serviceEvent"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1005.xml"); nn = selectNotification(res, "error", "constraint_ccd_documentationOf_serviceEvent"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1006.xml"); nn = selectNotification(res, "error", "constraint_ccd_documentationOf_serviceEvent"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_documentationOf_serviceEvent_classCode() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1007.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_documentationOf_serviceEvent_classCode"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1008.xml"); nn = selectNotification(res, "error", "constraint_ccd_documentationOf_serviceEvent_classCode"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1009.xml"); nn = selectNotification(res, "error", "constraint_ccd_documentationOf_serviceEvent_classCode"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_documentationOf_serviceEvent_effectiveTime() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1010.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_documentationOf_serviceEvent_effectiveTime"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1011.xml"); nn = selectNotification(res, "error", "constraint_ccd_documentationOf_serviceEvent_effectiveTime"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1012.xml"); nn = selectNotification(res, "error", "constraint_ccd_documentationOf_serviceEvent_effectiveTime"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1013.xml"); nn = selectNotification(res, "error", "constraint_ccd_documentationOf_serviceEvent_effectiveTime"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_languageCode() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1014.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_languageCode"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1015.xml"); nn = selectNotification(res, "note", "constraint_ccd_languageCode"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1016.xml"); nn = selectNotification(res, "error", "constraint_ccd_languageCode"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1017.xml"); nn = selectNotification(res, "error", "constraint_ccd_languageCode"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1018.xml"); nn = selectNotification(res, "error", "constraint_ccd_languageCode"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_templateId() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1019.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_templateId"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1020.xml"); nn = selectNotification(res, "error", "constraint_ccd_templateId"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_templateId_root() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1021.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_templateId_root"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1022.xml"); nn = selectNotification(res, "error", "constraint_ccd_templateId_root"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_effectiveTime() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1023.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_effectiveTime"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1024.xml"); nn = selectNotification(res, "error", "constraint_ccd_effectiveTime"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1025.xml"); nn = selectNotification(res, "error", "constraint_ccd_effectiveTime"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1026.xml"); nn = selectNotification(res, "error", "constraint_ccd_effectiveTime"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1027.xml"); nn = selectNotification(res, "error", "constraint_ccd_effectiveTime"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1028.xml"); nn = selectNotification(res, "error", "constraint_ccd_effectiveTime"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_recordTarget() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1029.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_recordTarget"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1030.xml"); nn = selectNotification(res, "note", "constraint_ccd_recordTarget"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1031.xml"); nn = selectNotification(res, "error", "constraint_ccd_recordTarget"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1032.xml"); nn = selectNotification(res, "error", "constraint_ccd_recordTarget"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_author_assignedAuthor() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1033.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_author_assignedAuthor"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1034.xml"); nn = selectNotification(res, "note", "constraint_ccd_author_assignedAuthor"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1035.xml"); nn = selectNotification(res, "error", "constraint_ccd_author_assignedAuthor"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1036.xml"); nn = selectNotification(res, "error", "constraint_ccd_author_assignedAuthor"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_author_assignedAuthor_representedOrganization() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1037.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_author_assignedAuthor_representedOrganization"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1038.xml"); nn = selectNotification(res, "error", "constraint_ccd_author_assignedAuthor_representedOrganization"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1039.xml"); nn = selectNotification(res, "error", "constraint_ccd_author_assignedAuthor_representedOrganization"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1040.xml"); nn = selectNotification(res, "error", "constraint_ccd_author_assignedAuthor_representedOrganization"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_component_structuredBody_component_Purpose() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1041.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_component_structuredBody_component_Purpose"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1042.xml"); nn = selectNotification(res, "error", "constraint_ccd_component_structuredBody_component_Purpose"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_participant_associatedEntity_NextOfKin() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1043.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_participant_associatedEntity_NextOfKin"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1044.xml"); nn = selectNotification(res, "info", "constraint_ccd_participant_associatedEntity_NextOfKin"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1045.xml"); nn = selectNotification(res, "info", "constraint_ccd_participant_associatedEntity_NextOfKin"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1046.xml"); nn = selectNotification(res, "info", "constraint_ccd_participant_associatedEntity_NextOfKin"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_participant_typeCode_NextOfKin() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1047.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_participant_typeCode_NextOfKin"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1048.xml"); nn = selectNotification(res, "error", "constraint_ccd_participant_typeCode_NextOfKin"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1049.xml"); nn = selectNotification(res, "error", "constraint_ccd_participant_typeCode_NextOfKin"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_PatientAwareness_participantRole_id() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1050.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_PatientAwareness_participantRole_id"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1051.xml"); nn = selectNotification(res, "error", "constraint_ccd_PatientAwareness_participantRole_id"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1052.xml"); nn = selectNotification(res, "error", "constraint_ccd_PatientAwareness_participantRole_id"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1053.xml"); nn = selectNotification(res, "error", "constraint_ccd_PatientAwareness_participantRole_id"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_documentationOf_serviceEvent_performer_typeCode() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1054.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_documentationOf_serviceEvent_performer_typeCode"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1055.xml"); nn = selectNotification(res, "error", "constraint_ccd_documentationOf_serviceEvent_performer_typeCode"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1056.xml"); nn = selectNotification(res, "error", "constraint_ccd_documentationOf_serviceEvent_performer_typeCode"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1057.xml"); nn = selectNotification(res, "note", "constraint_ccd_documentationOf_serviceEvent_performer_typeCode"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_VitalSigns_text() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1058.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_VitalSigns_text"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1059.xml"); nn = selectNotification(res, "error", "constraint_ccd_VitalSigns_text"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_VitalSigns_code() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1060.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_VitalSigns_code"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1061.xml"); nn = selectNotification(res, "error", "constraint_ccd_VitalSigns_code"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1062.xml"); nn = selectNotification(res, "error", "constraint_ccd_VitalSigns_code"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_VitalSigns_title() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1063.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_VitalSigns_title"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1064.xml"); nn = selectNotification(res, "error", "constraint_ccd_VitalSigns_title"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_VitalSigns_titleValue() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1065.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_VitalSigns_titleValue"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1066.xml"); nn = selectNotification(res, "warning", "constraint_ccd_VitalSigns_titleValue"); Assert.assertTrue(nn != null);// } @Test public void test_constraint_ccd_VitalSigns_entry_vitalSignsOrganizer() { DetailedResult res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1067.xml"); Notification nn = selectNotification(res, "note", "constraint_ccd_VitalSigns_entry_vitalSignsOrganizer"); Assert.assertTrue(nn != null); res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1068.xml"); nn = selectNotification(res, "warning", "constraint_ccd_VitalSigns_entry_vitalSignsOrganizer"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1069.xml"); nn = selectNotification(res, "warning", "constraint_ccd_VitalSigns_entry_vitalSignsOrganizer"); Assert.assertTrue(nn != null);// res = getDetailedResultFromFile("src/test/resources/SampleCCDDocument1070.xml"); nn = selectNotification(res, "warning", "constraint_ccd_VitalSigns_entry_vitalSignsOrganizer"); Assert.assertTrue(nn != null);// } private static DetailedResult getDetailedResultFromFile(String dd){ POCDMT000040ClinicalDocument ss = load(dd); List listConstraintValidatorModule = new ArrayList(); listConstraintValidatorModule.add(new CCDValidator()); DetailedResult res = new DetailedResult(); validateClinicalDocumentType(res, ss, listConstraintValidatorModule); return res; } private static POCDMT000040ClinicalDocument load(String ss) { POCDMT000040ClinicalDocument pr = null; try { pr = load(new FileInputStream(ss)); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } return pr; } private static POCDMT000040ClinicalDocument load(InputStream is) throws JAXBException { JAXBContext jc = JAXBContext.newInstance("net.ihe.gazelle.cda"); Unmarshaller u = jc.createUnmarshaller(); POCDMT000040ClinicalDocument mimi = (POCDMT000040ClinicalDocument) u.unmarshal(is); return mimi; } private static void validateClinicalDocumentType(DetailedResult res, POCDMT000040ClinicalDocument pnr, List listConstraintValidatorModule){ List ln = new ArrayList(); for (ConstraintValidatorModule cvm : listConstraintValidatorModule) { POCDMT000040ClinicalDocument.validateByModule(pnr, "/ClinicalDocument", cvm, ln); } if (res.getMDAValidation() == null) res.setMDAValidation(new MDAValidation()); for (Notification notification : ln) { res.getMDAValidation().getWarningOrErrorOrNote().add(notification); } } private static Notification selectNotification(DetailedResult res, String type, String name){ if (res != null){ if (res.getMDAValidation() != null){ if (res.getMDAValidation().getWarningOrErrorOrNote() != null){ for (Object obj : res.getMDAValidation().getWarningOrErrorOrNote()) { Notification nn = (Notification)obj; if (nn.getTest().equals(name)){ if (type != null){ if (obj.getClass().getSimpleName().toLowerCase().equals(type)){ return nn; } } } } } } } return null; } }