[507] | 1 | /*
|
---|
| 2 | * To change this template, choose Tools | Templates
|
---|
| 3 | * and open the template in the editor.
|
---|
| 4 | */
|
---|
| 5 | package gov.hhs.fha.nhinc.adaptercomponentmpi;
|
---|
| 6 |
|
---|
| 7 | import java.util.List;
|
---|
| 8 | import javax.xml.bind.JAXBElement;
|
---|
| 9 | import org.hl7.v3.*;
|
---|
| 10 | import gov.hhs.fha.nhinc.mpilib.*;
|
---|
| 11 | import java.io.Serializable;
|
---|
| 12 | import java.util.Iterator;
|
---|
| 13 | import static org.junit.Assert.*;
|
---|
| 14 | import org.apache.commons.logging.Log;
|
---|
| 15 | import org.apache.commons.logging.LogFactory;
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
| 18 | *
|
---|
| 19 | * @author Jon Hoppesch
|
---|
| 20 | */
|
---|
| 21 | public class TestHelper {
|
---|
| 22 |
|
---|
| 23 | private static Log log = LogFactory.getLog(TestHelper.class);
|
---|
| 24 |
|
---|
| 25 | public static void AssertPatientIdsAreSame(PRPAIN201306UV expected, PRPAIN201306UV result) {
|
---|
| 26 | AssertPatientNotNull(expected);
|
---|
| 27 | AssertPatientNotNull(result);
|
---|
| 28 |
|
---|
| 29 | AssertPatientIdsEqual(expected.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient(),
|
---|
| 30 | result.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient());
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | public static void AssertPatientNamesAreSame(PRPAIN201306UV expected, PRPAIN201306UV result) {
|
---|
| 34 | AssertPatientPersonNotNull(expected);
|
---|
| 35 | AssertPatientPersonNotNull(result);
|
---|
| 36 |
|
---|
| 37 | AssertPatientNamesEqual(expected.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getPatientPerson().getValue(),
|
---|
| 38 | result.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getPatientPerson().getValue());
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public static void AssertPatientGendersAreSame(PRPAIN201306UV expected, PRPAIN201306UV result) {
|
---|
| 42 | AssertPatientPersonNotNull(expected);
|
---|
| 43 | AssertPatientPersonNotNull(result);
|
---|
| 44 |
|
---|
| 45 | AssertPatientGendersEqual(expected.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getPatientPerson().getValue(),
|
---|
| 46 | result.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getPatientPerson().getValue());
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public static void AssertPatientBdaysAreSame(PRPAIN201306UV expected, PRPAIN201306UV result) {
|
---|
| 50 | AssertPatientPersonNotNull(expected);
|
---|
| 51 | AssertPatientPersonNotNull(result);
|
---|
| 52 |
|
---|
| 53 | AssertPatientBdaysEqual(expected.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getPatientPerson().getValue(),
|
---|
| 54 | result.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getPatientPerson().getValue());
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public static void AssertPatientNamesEqual(PRPAMT201310UVPerson patient1, PRPAMT201310UVPerson patient2) {
|
---|
| 58 | assertNotNull(patient1.getName());
|
---|
| 59 | assertNotNull(patient1.getName().get(0));
|
---|
| 60 | assertNotNull(patient1.getName().get(0).getContent());
|
---|
| 61 | assertNotNull(patient2.getName());
|
---|
| 62 | assertNotNull(patient2.getName().get(0));
|
---|
| 63 | assertNotNull(patient2.getName().get(0).getContent());
|
---|
| 64 |
|
---|
| 65 | String pat1Name = extractName (patient1.getName().get(0));
|
---|
| 66 | log.info("Patient 1 name:" + pat1Name);
|
---|
| 67 | String pat2Name = extractName (patient2.getName().get(0));
|
---|
| 68 | log.info("Patient 2 name:" + pat2Name);
|
---|
| 69 | assertEquals(pat1Name, pat2Name);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | private static String extractName (PNExplicit name) {
|
---|
| 73 | String nameString = "";
|
---|
| 74 | Boolean hasName = false;
|
---|
| 75 | List<Serializable> choice = name.getContent();
|
---|
| 76 | Iterator<Serializable> iterSerialObjects = choice.iterator();
|
---|
| 77 |
|
---|
| 78 | EnExplicitFamily familyName = new EnExplicitFamily();
|
---|
| 79 | EnExplicitGiven givenName = new EnExplicitGiven();
|
---|
| 80 |
|
---|
| 81 | while (iterSerialObjects.hasNext()) {
|
---|
| 82 | Serializable contentItem = iterSerialObjects.next();
|
---|
| 83 |
|
---|
| 84 | if (contentItem instanceof JAXBElement) {
|
---|
| 85 | JAXBElement oJAXBElement = (JAXBElement) contentItem;
|
---|
| 86 | if (oJAXBElement.getValue() instanceof EnExplicitFamily) {
|
---|
| 87 | familyName = (EnExplicitFamily) oJAXBElement.getValue();
|
---|
| 88 | hasName = true;
|
---|
| 89 | } else if (oJAXBElement.getValue() instanceof EnExplicitGiven) {
|
---|
| 90 | givenName = (EnExplicitGiven) oJAXBElement.getValue();
|
---|
| 91 | hasName = true;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | if (hasName == true) {
|
---|
| 97 | nameString = familyName.getContent() + " " + givenName.getContent();
|
---|
| 98 | System.out.println(nameString);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | return nameString;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | public static void AssertPatientGendersEqual(PRPAMT201310UVPerson patient1, PRPAMT201310UVPerson patient2) {
|
---|
| 105 | assertNotNull(patient1.getAdministrativeGenderCode());
|
---|
| 106 | assertNotNull(patient1.getAdministrativeGenderCode().getCode());
|
---|
| 107 | assertNotNull(patient2.getAdministrativeGenderCode());
|
---|
| 108 | assertNotNull(patient1.getAdministrativeGenderCode().getCode());
|
---|
| 109 |
|
---|
| 110 | assertEquals(patient1.getAdministrativeGenderCode().getCode(), patient1.getAdministrativeGenderCode().getCode());
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | public static void AssertPatientBdaysEqual(PRPAMT201310UVPerson patient1, PRPAMT201310UVPerson patient2) {
|
---|
| 114 | assertNotNull(patient1.getBirthTime());
|
---|
| 115 | assertNotNull(patient1.getBirthTime().getValue());
|
---|
| 116 | assertNotNull(patient2.getBirthTime());
|
---|
| 117 | assertNotNull(patient2.getBirthTime().getValue());
|
---|
| 118 |
|
---|
| 119 | assertEquals(patient1.getBirthTime().getValue(), patient2.getBirthTime().getValue());
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | public static void AssertPatientIdsEqual(PRPAMT201310UVPatient patient1, PRPAMT201310UVPatient patient2) {
|
---|
| 123 | AssertPatientIdNotNull(patient1);
|
---|
| 124 | AssertPatientIdNotNull(patient2);
|
---|
| 125 |
|
---|
| 126 | assertEquals(patient1.getId().get(0).getRoot(), patient1.getId().get(0).getRoot());
|
---|
| 127 | assertEquals(patient1.getId().get(0).getExtension(), patient1.getId().get(0).getExtension());
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | public static void AssertPatientIdNotNull(PRPAMT201310UVPatient patient) {
|
---|
| 131 | assertNotNull(patient.getId());
|
---|
| 132 | assertNotNull(patient.getId().get(0));
|
---|
| 133 | assertNotNull(patient.getId().get(0).getRoot());
|
---|
| 134 | assertNotNull(patient.getId().get(0).getExtension());
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | public static void AssertPatientPersonNotNull(PRPAIN201306UV queryResp) {
|
---|
| 138 | AssertPatientNotNull(queryResp);
|
---|
| 139 | assertNotNull(queryResp.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getPatientPerson());
|
---|
| 140 | assertNotNull(queryResp.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getPatientPerson().getValue());
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | public static void AssertPatientNotNull(PRPAIN201306UV queryResp) {
|
---|
| 144 | assertNotNull(queryResp);
|
---|
| 145 | assertNotNull(queryResp.getControlActProcess());
|
---|
| 146 | assertNotNull(queryResp.getControlActProcess().getSubject());
|
---|
| 147 | assertNotNull(queryResp.getControlActProcess().getSubject().get(0));
|
---|
| 148 | assertNotNull(queryResp.getControlActProcess().getSubject().get(0).getRegistrationEvent());
|
---|
| 149 | assertNotNull(queryResp.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1());
|
---|
| 150 | assertNotNull(queryResp.getControlActProcess().getSubject().get(0).getRegistrationEvent().getSubject1().getPatient());
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | public static PRPAIN201305UV build201305(String firstName, String lastName, String gender, String birthTime, II subjectId) {
|
---|
| 154 | PRPAIN201305UV msg = new PRPAIN201305UV();
|
---|
| 155 |
|
---|
| 156 | // Set up message header fields
|
---|
| 157 | msg.setITSVersion("XML_1.0");
|
---|
| 158 |
|
---|
| 159 | II id = new II();
|
---|
| 160 | id.setRoot("1.1");
|
---|
| 161 | msg.setId(id);
|
---|
| 162 |
|
---|
| 163 | TSExplicit creationTime = new TSExplicit();
|
---|
| 164 | creationTime.setValue("20090202000000");
|
---|
| 165 | msg.setCreationTime(creationTime);
|
---|
| 166 |
|
---|
| 167 | II interactionId = new II();
|
---|
| 168 | interactionId.setRoot("2.16.840.1.113883.1.6");
|
---|
| 169 | interactionId.setExtension("PRPA_IN201305UV");
|
---|
| 170 | msg.setInteractionId(id);
|
---|
| 171 |
|
---|
| 172 | CS processingCode = new CS();
|
---|
| 173 | processingCode.setCode("P");
|
---|
| 174 | msg.setProcessingCode(processingCode);
|
---|
| 175 |
|
---|
| 176 | CS processingModeCode = new CS();
|
---|
| 177 | processingModeCode.setCode("R");
|
---|
| 178 | msg.setProcessingModeCode(processingModeCode);
|
---|
| 179 |
|
---|
| 180 | CS ackCode = new CS();
|
---|
| 181 | ackCode.setCode("AL");
|
---|
| 182 | msg.setAcceptAckCode(ackCode);
|
---|
| 183 |
|
---|
| 184 | // Set the receiver and sender
|
---|
| 185 | msg.getReceiver().add(createReceiver());
|
---|
| 186 | msg.setSender(createSender());
|
---|
| 187 |
|
---|
| 188 | msg.setControlActProcess(createControlActProcess(firstName, lastName, gender, birthTime, subjectId));
|
---|
| 189 |
|
---|
| 190 | return msg;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | private static PRPAIN201305UVQUQIMT021001UV01ControlActProcess createControlActProcess(String firstName, String lastName, String gender, String birthTime, II subjectId) {
|
---|
| 194 | PRPAIN201305UVQUQIMT021001UV01ControlActProcess controlActProcess = new PRPAIN201305UVQUQIMT021001UV01ControlActProcess();
|
---|
| 195 |
|
---|
| 196 | controlActProcess.setMoodCode("EVN");
|
---|
| 197 |
|
---|
| 198 | CD code = new CD();
|
---|
| 199 | code.setCode("PRPA_TE201305UV");
|
---|
| 200 | code.setCodeSystem("2.16.840.1.113883.1.6");
|
---|
| 201 | controlActProcess.setCode(code);
|
---|
| 202 |
|
---|
| 203 | controlActProcess.setQueryByParameter(createQueryParams(firstName, lastName, gender, birthTime, subjectId));
|
---|
| 204 |
|
---|
| 205 | return controlActProcess;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | private static JAXBElement<PRPAMT201306UVQueryByParameter> createQueryParams(String firstName, String lastName, String gender, String birthTime, II subjectId) {
|
---|
| 209 | PRPAMT201306UVQueryByParameter params = new PRPAMT201306UVQueryByParameter();
|
---|
| 210 |
|
---|
| 211 | II id = new II();
|
---|
| 212 | id.setRoot("12345");
|
---|
| 213 | params.setQueryId(id);
|
---|
| 214 |
|
---|
| 215 | CS statusCode = new CS();
|
---|
| 216 | statusCode.setCode("new");
|
---|
| 217 | params.setStatusCode(statusCode);
|
---|
| 218 |
|
---|
| 219 | params.setParameterList(createParamList(firstName, lastName, gender, birthTime, subjectId));
|
---|
| 220 |
|
---|
| 221 | javax.xml.namespace.QName xmlqname = new javax.xml.namespace.QName("urn:hl7-org:v3", "queryByParameter");
|
---|
| 222 | JAXBElement<PRPAMT201306UVQueryByParameter> queryParams = new JAXBElement<PRPAMT201306UVQueryByParameter>(xmlqname, PRPAMT201306UVQueryByParameter.class, params);
|
---|
| 223 |
|
---|
| 224 | return queryParams;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | private static PRPAMT201306UVParameterList createParamList(String firstName, String lastName, String gender, String birthTime, II subjectId) {
|
---|
| 228 | PRPAMT201306UVParameterList paramList = new PRPAMT201306UVParameterList();
|
---|
| 229 |
|
---|
| 230 | // Set the Subject Gender Code
|
---|
| 231 | paramList.getLivingSubjectAdministrativeGender().add(createGender(gender));
|
---|
| 232 |
|
---|
| 233 | // Set the Subject Birth Time
|
---|
| 234 | paramList.getLivingSubjectBirthTime().add(createBirthTime(birthTime));
|
---|
| 235 |
|
---|
| 236 | // Set the Subject Name
|
---|
| 237 | paramList.getLivingSubjectName().add(createName(firstName, lastName));
|
---|
| 238 |
|
---|
| 239 | // Set the subject Id
|
---|
| 240 | paramList.getLivingSubjectId().add(createSubjectId(subjectId));
|
---|
| 241 |
|
---|
| 242 | return paramList;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | private static PRPAMT201306UVLivingSubjectId createSubjectId(II subjectId) {
|
---|
| 246 | PRPAMT201306UVLivingSubjectId id = new PRPAMT201306UVLivingSubjectId();
|
---|
| 247 | if (subjectId != null) {
|
---|
| 248 | id.getValue().add(subjectId);
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | return id;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | private static PRPAMT201306UVLivingSubjectName createName(String firstName, String lastName) {
|
---|
| 255 | PRPAMT201306UVLivingSubjectName subjectName = new PRPAMT201306UVLivingSubjectName();
|
---|
| 256 | org.hl7.v3.ObjectFactory factory = new org.hl7.v3.ObjectFactory();
|
---|
| 257 | ENExplicit name = (ENExplicit) (factory.createENExplicit());
|
---|
| 258 | List namelist = name.getContent();
|
---|
| 259 |
|
---|
| 260 | if (lastName != null &&
|
---|
| 261 | lastName.length() > 0) {
|
---|
| 262 | EnExplicitFamily familyName = new EnExplicitFamily();
|
---|
| 263 | familyName.setPartType("FAM");
|
---|
| 264 | familyName.setContent(lastName);
|
---|
| 265 |
|
---|
| 266 | namelist.add(factory.createENExplicitFamily(familyName));
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | if (firstName != null &&
|
---|
| 270 | firstName.length() > 0) {
|
---|
| 271 | EnExplicitGiven givenName = new EnExplicitGiven();
|
---|
| 272 | givenName.setPartType("GIV");
|
---|
| 273 | givenName.setContent(firstName);
|
---|
| 274 |
|
---|
| 275 | namelist.add(factory.createENExplicitGiven(givenName));
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | subjectName.getValue().add(name);
|
---|
| 279 |
|
---|
| 280 | return subjectName;
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | private static PRPAMT201306UVLivingSubjectBirthTime createBirthTime(String birthTime) {
|
---|
| 284 | PRPAMT201306UVLivingSubjectBirthTime subjectBirthTime = new PRPAMT201306UVLivingSubjectBirthTime();
|
---|
| 285 | IVLTSExplicit bday = new IVLTSExplicit();
|
---|
| 286 |
|
---|
| 287 | if (birthTime != null &&
|
---|
| 288 | birthTime.length() > 0) {
|
---|
| 289 | bday.setValue(birthTime);
|
---|
| 290 | subjectBirthTime.getValue().add(bday);
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | return subjectBirthTime;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | private static PRPAMT201306UVLivingSubjectAdministrativeGender createGender(String gender) {
|
---|
| 297 | PRPAMT201306UVLivingSubjectAdministrativeGender adminGender = new PRPAMT201306UVLivingSubjectAdministrativeGender();
|
---|
| 298 | CE genderCode = new CE();
|
---|
| 299 |
|
---|
| 300 | if (gender != null &&
|
---|
| 301 | gender.length() > 0) {
|
---|
| 302 | genderCode.setCode(gender);
|
---|
| 303 | adminGender.getValue().add(genderCode);
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | return adminGender;
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | private static MCCIMT000100UV01Receiver createReceiver() {
|
---|
| 310 | MCCIMT000100UV01Receiver receiver = new MCCIMT000100UV01Receiver();
|
---|
| 311 |
|
---|
| 312 | receiver.setTypeCode(CommunicationFunctionType.RCV);
|
---|
| 313 |
|
---|
| 314 | MCCIMT000100UV01Device device = new MCCIMT000100UV01Device();
|
---|
| 315 | device.setDeterminerCode("INSTANCE");
|
---|
| 316 |
|
---|
| 317 | II id = new II();
|
---|
| 318 | id.setRoot("2.16.840.1.113883.3.200");
|
---|
| 319 | device.getId().add(id);
|
---|
| 320 |
|
---|
| 321 | TELExplicit url = new TELExplicit();
|
---|
| 322 | url.setValue("http://localhost:9080/NhinConnect/AdapterComponentMpiService");
|
---|
| 323 | device.getTelecom().add(url);
|
---|
| 324 |
|
---|
| 325 | receiver.setDevice(device);
|
---|
| 326 |
|
---|
| 327 | return receiver;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | private static MCCIMT000100UV01Sender createSender() {
|
---|
| 331 | MCCIMT000100UV01Sender sender = new MCCIMT000100UV01Sender();
|
---|
| 332 |
|
---|
| 333 | sender.setTypeCode(CommunicationFunctionType.SND);
|
---|
| 334 |
|
---|
| 335 | MCCIMT000100UV01Device device = new MCCIMT000100UV01Device();
|
---|
| 336 | device.setDeterminerCode("INSTANCE");
|
---|
| 337 |
|
---|
| 338 | II id = new II();
|
---|
| 339 | id.setRoot("2.16.840.1.113883.3.200");
|
---|
| 340 | device.getId().add(id);
|
---|
| 341 |
|
---|
| 342 | sender.setDevice(device);
|
---|
| 343 |
|
---|
| 344 | return sender;
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | public static Patient createMpiPatient(String firstName, String lastName, String gender, String birthTime, Identifier subjectId) {
|
---|
| 348 | Patient result = new Patient();
|
---|
| 349 |
|
---|
| 350 | // Set the patient name
|
---|
| 351 | PersonName name = new PersonName();
|
---|
| 352 | name.setFirstName(firstName);
|
---|
| 353 | name.setLastName(lastName);
|
---|
| 354 | result.setName(name);
|
---|
| 355 |
|
---|
| 356 | // Set the patient gender
|
---|
| 357 | result.setGender(gender);
|
---|
| 358 |
|
---|
| 359 | // Set the patient birth time
|
---|
| 360 | result.setDateOfBirth(birthTime);
|
---|
| 361 |
|
---|
| 362 | // Set the patient Id
|
---|
| 363 | Identifiers ids = new Identifiers();
|
---|
| 364 | ids.add(subjectId);
|
---|
| 365 | result.setIdentifiers(ids);
|
---|
| 366 |
|
---|
| 367 | return result;
|
---|
| 368 | }
|
---|
| 369 | }
|
---|