001/*-
002 * #%L
003 * Smile CDR - CDR
004 * %%
005 * Copyright (C) 2016 - 2026 Smile CDR, Inc.
006 * %%
007 * All rights reserved.
008 * #L%
009 */
010package ca.cdr.test.hl7v2;
011
012import ca.cdr.api.hl7v2.CdrModelClassFactory;
013import ca.cdr.api.model.enm.CodeSystemEnum;
014import ca.cdr.api.util.PublicApiConstants;
015import ca.cdr.test.hl7v2.MinimalHl7v2ToFhirTestData.EncounterData;
016import ca.cdr.test.hl7v2.MinimalHl7v2ToFhirTestData.HospitalData;
017import ca.cdr.test.hl7v2.MinimalHl7v2ToFhirTestData.ObservationData;
018import ca.cdr.test.hl7v2.MinimalHl7v2ToFhirTestData.PatientData;
019import ca.cdr.test.hl7v2.MinimalHl7v2ToFhirTestData.PractitionerData;
020import ca.uhn.fhir.context.FhirContext;
021import ca.uhn.hl7v2.DefaultHapiContext;
022import ca.uhn.hl7v2.HL7Exception;
023import ca.uhn.hl7v2.model.AbstractMessage;
024import ca.uhn.hl7v2.model.AbstractSegment;
025import ca.uhn.hl7v2.model.AbstractType;
026import ca.uhn.hl7v2.model.DataTypeException;
027import ca.uhn.hl7v2.model.Message;
028import ca.uhn.hl7v2.model.Varies;
029import ca.uhn.hl7v2.model.v25.datatype.CE;
030import ca.uhn.hl7v2.model.v25.datatype.CX;
031import ca.uhn.hl7v2.model.v25.datatype.DT;
032import ca.uhn.hl7v2.model.v25.datatype.EI;
033import ca.uhn.hl7v2.model.v25.datatype.NM;
034import ca.uhn.hl7v2.model.v25.datatype.PL;
035import ca.uhn.hl7v2.model.v25.datatype.ST;
036import ca.uhn.hl7v2.model.v25.datatype.TQ;
037import ca.uhn.hl7v2.model.v25.datatype.XAD;
038import ca.uhn.hl7v2.model.v25.datatype.XCN;
039import ca.uhn.hl7v2.model.v25.datatype.XON;
040import ca.uhn.hl7v2.model.v25.datatype.XPN;
041import ca.uhn.hl7v2.model.v25.datatype.XTN;
042import ca.uhn.hl7v2.model.v25.group.ORU_R01_PATIENT_RESULT;
043import ca.uhn.hl7v2.model.v25.group.RAS_O17_ADMINISTRATION;
044import ca.uhn.hl7v2.model.v25.group.RAS_O17_ORDER;
045import ca.uhn.hl7v2.model.v25.group.RDE_O11_ORDER;
046import ca.uhn.hl7v2.model.v25.message.ADT_A01;
047import ca.uhn.hl7v2.model.v25.message.ADT_A03;
048import ca.uhn.hl7v2.model.v25.message.ADT_A06;
049import ca.uhn.hl7v2.model.v25.message.ADT_A09;
050import ca.uhn.hl7v2.model.v25.message.ADT_A21;
051import ca.uhn.hl7v2.model.v25.message.ADT_A39;
052import ca.uhn.hl7v2.model.v25.message.ADT_A45;
053import ca.uhn.hl7v2.model.v25.message.ADT_A54;
054import ca.uhn.hl7v2.model.v25.message.ADT_A60;
055import ca.uhn.hl7v2.model.v25.message.DFT_P03;
056import ca.uhn.hl7v2.model.v25.message.ORM_O01;
057import ca.uhn.hl7v2.model.v25.message.ORU_R01;
058import ca.uhn.hl7v2.model.v25.message.QBP_Q21;
059import ca.uhn.hl7v2.model.v25.message.RAS_O17;
060import ca.uhn.hl7v2.model.v25.message.RDE_O11;
061import ca.uhn.hl7v2.model.v25.message.SIU_S12;
062import ca.uhn.hl7v2.model.v25.message.VXU_V04;
063import ca.uhn.hl7v2.model.v25.segment.AIL;
064import ca.uhn.hl7v2.model.v25.segment.AIP;
065import ca.uhn.hl7v2.model.v25.segment.AL1;
066import ca.uhn.hl7v2.model.v25.segment.DG1;
067import ca.uhn.hl7v2.model.v25.segment.FT1;
068import ca.uhn.hl7v2.model.v25.segment.GT1;
069import ca.uhn.hl7v2.model.v25.segment.IAM;
070import ca.uhn.hl7v2.model.v25.segment.IN1;
071import ca.uhn.hl7v2.model.v25.segment.IN2;
072import ca.uhn.hl7v2.model.v25.segment.MRG;
073import ca.uhn.hl7v2.model.v25.segment.MSH;
074import ca.uhn.hl7v2.model.v25.segment.NK1;
075import ca.uhn.hl7v2.model.v25.segment.OBR;
076import ca.uhn.hl7v2.model.v25.segment.OBX;
077import ca.uhn.hl7v2.model.v25.segment.ORC;
078import ca.uhn.hl7v2.model.v25.segment.PD1;
079import ca.uhn.hl7v2.model.v25.segment.PID;
080import ca.uhn.hl7v2.model.v25.segment.PR1;
081import ca.uhn.hl7v2.model.v25.segment.PV1;
082import ca.uhn.hl7v2.model.v25.segment.PV2;
083import ca.uhn.hl7v2.model.v25.segment.QPD;
084import ca.uhn.hl7v2.model.v25.segment.ROL;
085import ca.uhn.hl7v2.model.v25.segment.RXA;
086import ca.uhn.hl7v2.model.v25.segment.RXC;
087import ca.uhn.hl7v2.model.v25.segment.RXE;
088import ca.uhn.hl7v2.model.v25.segment.RXR;
089import ca.uhn.hl7v2.model.v25.segment.SCH;
090import ca.uhn.hl7v2.validation.impl.NoValidation;
091
092/**
093 * Creates HL7 V2 test data
094 */
095public class Hl7V2TestDataHelper {
096
097        public static final String FACILITY_SYSTEM = "http://acme.org/facility";
098        private static DefaultHapiContext ourV2Ctx;
099        private static FhirContext ourContext;
100
101        public Hl7V2TestDataHelper(FhirContext theFhirContext, DefaultHapiContext v2Ctx) {
102                ourContext = theFhirContext;
103                ourV2Ctx = v2Ctx;
104        }
105
106        public static Hl7V2TestDataHelper buildDefault(FhirContext theFhirContext) {
107                ourV2Ctx = new DefaultHapiContext();
108                ourV2Ctx.setValidationContext(new NoValidation());
109                ourV2Ctx.setModelClassFactory(new CdrModelClassFactory());
110                return new Hl7V2TestDataHelper(theFhirContext, ourV2Ctx);
111        }
112
113        public void addExtraComponent(AbstractType theTarget, int theComponentIndex, String theValue)
114                        throws DataTypeException {
115                ST system = new ST(theTarget.getMessage());
116                system.setValue(theValue);
117                theTarget.getExtraComponents().getComponent(theComponentIndex).setData(system);
118        }
119
120        public ADT_A01 createAdtA01() throws HL7Exception {
121                return createAdtA01(true);
122        }
123
124        public ADT_A01 createAdtA01(boolean theValid) throws HL7Exception {
125                ADT_A01 a01 = new ADT_A01();
126
127                // Patient, family doctor, next of kin, and employer
128                populateMsh(a01.getMSH(), "ADT^A01^ADT_A01");
129                populatePid(a01.getPID(), theValid);
130                populateNk1NextOfKin(a01.insertNK1(0));
131                populateNk1Employer(a01.insertNK1(1));
132                populateRolA(a01.insertROL(0));
133
134                // Visit, attending, admitting, diagnosis, etc
135                populatePv1(a01.getPV1());
136                populatePv2(a01.getPV2());
137                populateRolB(a01.insertROL2(0));
138                populateRolC(a01.insertROL2(1));
139                populateDg1(a01.getDG1());
140                populatePr1First(a01.insertPROCEDURE(0).getPR1());
141                populateGt1(a01.getGT1());
142                populateIn1(a01.insertINSURANCE(0).getIN1());
143                populateIn2(a01.getINSURANCE(0).getIN2());
144
145                // Assessments
146                populateObxAssessmentWeight(a01, a01.insertOBX(0));
147                populateObxAssessmentHeight(a01, a01.insertOBX(0));
148
149                return a01;
150        }
151
152        public ADT_A03 createAdtA03() throws HL7Exception {
153                ADT_A03 a03 = new ADT_A03();
154
155                // Patient and family doctor
156                populateMsh(a03.getMSH(), "ADT^A03^ADT_A03");
157                populatePid(a03.getPID());
158                populateRolA(a03.insertROL(0));
159
160                // Visit, attending, admitting, diagnosis, etc
161                populatePv1(a03.getPV1());
162                populateRolB(a03.insertROL2(0));
163                populateRolC(a03.insertROL2(1));
164                populateDg1(a03.getDG1(), true);
165                populatePr1First(a03.getPROCEDURE(0).getPR1());
166                populatePr1Second(a03.getPROCEDURE(1).getPR1());
167                populateGt1(a03.getGT1());
168                populateIn1(a03.insertINSURANCE(0).getIN1());
169                populateIn2(a03.getINSURANCE(0).getIN2());
170
171                // Assessments (come after DG1 for A03)
172                populateObxAssessmentWeight(a03, a03.insertOBX(0));
173                populateObxAssessmentHeight(a03, a03.insertOBX(0));
174
175                return a03;
176        }
177
178        public ADT_A06 createAdtA06() throws HL7Exception {
179                ADT_A06 a06 = new ADT_A06();
180
181                populateMsh(a06.getMSH(), "ADT^A06^ADT_A06");
182                populatePid(a06.getPID());
183                // pd1
184                populateRolA(a06.insertROL(0));
185                // mrg
186                populateNk1NextOfKin(a06.getNK1());
187                populatePv1(a06.getPV1());
188                populatePv2(a06.getPV2());
189                populateRolB(a06.insertROL2(0));
190                populateObxAssessmentWeight(a06, a06.insertOBX(0));
191                populateAl1(a06.getAL1());
192                populateDg1(a06.getDG1(), true);
193                populatePr1First(a06.getPROCEDURE(0).getPR1());
194                populateGt1(a06.getGT1());
195                populateIn1(a06.insertINSURANCE(0).getIN1());
196                populateIn2(a06.getINSURANCE(0).getIN2());
197
198                return a06;
199        }
200
201        /**
202         * The ADT^A07 trigger uses the same structure as ADT^A06 (i.e. ADT_A06)
203         */
204        public ADT_A06 createAdtA07() throws HL7Exception {
205                ADT_A06 adtA07 = createAdtA06();
206                populateMsh(adtA07.getMSH(), "ADT^A07^ADT_A06");
207                return adtA07;
208        }
209
210        public ADT_A09 createAdtA10() throws HL7Exception {
211                ADT_A09 a09 = new ADT_A09();
212
213                // Patient
214                populateMsh(a09.getMSH(), "ADT^A10^ADT_A09");
215
216                // Visit
217                populatePv1(a09.getPV1());
218
219                return a09;
220        }
221
222        public ADT_A09 createAdtA11() throws HL7Exception {
223                ADT_A09 a09 = new ADT_A09();
224
225                // Patient
226                populateMsh(a09.getMSH(), "ADT^A11^ADT_A09");
227                populatePid(a09.getPID());
228
229                // Visit
230                populatePv1(a09.getPV1());
231                populatePv2(a09.getPV2());
232
233                return a09;
234        }
235
236        public void populateMinimalPatient(PID thePid, PD1 thePd1, PatientData thePatientData) throws HL7Exception {
237                CX pid3 = thePid.insertPid3_PatientIdentifierList(0);
238                pid3.getCx1_IDNumber().setValue(thePatientData.identifier.value);
239                pid3.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue(thePatientData.identifier.system);
240                pid3.getCx5_IdentifierTypeCode().setValue("MR");
241
242                thePd1.getPd119_MilitaryBranch().setValue(thePatientData.militaryBranch);
243        }
244
245        public void populateMinimalEncounter(
246                        PV1 thePv1,
247                        PV2 thePv2,
248                        EncounterData theEncounter,
249                        HospitalData theHospital,
250                        PractitionerData thePractitioner)
251                        throws HL7Exception {
252                thePv1.getPv12_PatientClass().setValue("E"); // Table 0004 - Emergency
253
254                PL assignedLocation = thePv1.getPv13_AssignedPatientLocation();
255                assignedLocation.getPl1_PointOfCare().setValue(theHospital.name);
256                assignedLocation
257                                .getPl10_ComprehensiveLocationIdentifier()
258                                .getEi1_EntityIdentifier()
259                                .setValue(theHospital.identifier.value);
260                assignedLocation
261                                .getPl10_ComprehensiveLocationIdentifier()
262                                .getEi2_NamespaceID()
263                                .setValue(theHospital.identifier.system);
264                assignedLocation.getExtraComponents().getComponent(0).getData().parse(FACILITY_SYSTEM);
265
266                XCN practitioner = thePv1.getPv17_AttendingDoctor(0);
267                practitioner.getXcn1_IDNumber().setValue(thePractitioner.identifier.value);
268                practitioner.getXcn9_AssigningAuthority().getHd1_NamespaceID().setValue(thePractitioner.identifier.system);
269
270                CX visitNumber = thePv1.getPv119_VisitNumber();
271                visitNumber.getCx1_IDNumber().setValue(theEncounter.identifier.value);
272                visitNumber.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue(theEncounter.identifier.system);
273                visitNumber.getCx5_IdentifierTypeCode().setValue("VN"); // Table 0203 - Visit Number
274
275                thePv2.getPv28_ExpectedAdmitDateTime().getTs1_Time().setValue(theEncounter.expectedAdmitTime.v2Date);
276        }
277
278        public void populateMinimalObservation(Message theMessage, OBX theObx, ObservationData theObservationData)
279                        throws DataTypeException {
280                theObx.getObx2_ValueType().setValue("ST");
281                ST obxText = new ST(theMessage);
282                obxText.setValue(theObservationData.text);
283                theObx.getObx5_ObservationValue(0).setData(obxText);
284
285                theObx.getObx3_ObservationIdentifier().getCe1_Identifier().setValue(theObservationData.code);
286                theObx.getObx3_ObservationIdentifier().getCe3_NameOfCodingSystem().setValue(theObservationData.system);
287
288                theObx.getObx11_ObservationResultStatus().setValue(theObservationData.status);
289                theObx.getObx14_DateTimeOfTheObservation().getTs1_Time().setValue(theObservationData.dateTime.v2Date);
290        }
291
292        public ADT_A21 createAdtA29() throws HL7Exception {
293                ADT_A21 a29 = new ADT_A21();
294
295                populateMsh(a29.getMSH(), "ADT^A29^ADT_A21");
296                populatePid(a29.getPID());
297
298                return a29;
299        }
300
301        /**
302         * The ADT^A42 trigger uses the same structure as ADT^A39 (i.e. ADT_A39)
303         */
304        public ADT_A39 createAdtA42() throws HL7Exception {
305                ADT_A39 adtA42 = new ADT_A39();
306                populateMsh(adtA42.getMSH(), "ADT^A42^ADT_A39");
307                populatePid(adtA42.getPATIENT().getPID());
308
309                populateMrg(adtA42.getPATIENT().getMRG());
310                populatePv1(adtA42.getPATIENT().getPV1());
311                return adtA42;
312        }
313
314        public ADT_A45 createAdtA45() throws HL7Exception {
315                ADT_A45 adtA45 = new ADT_A45();
316                populateMsh(adtA45.getMSH(), "ADT^A45^ADT_A45");
317                populatePid(adtA45.getPID());
318
319                populateMrg(adtA45.getMERGE_INFO().getMRG());
320                populatePv1(adtA45.getMERGE_INFO().getPV1());
321
322                return adtA45;
323        }
324
325        public ADT_A54 createAdtA54() throws HL7Exception {
326                ADT_A54 adtA54 = new ADT_A54();
327
328                // Patient and family doctor
329                populateMsh(adtA54.getMSH(), "ADT^A54^ADT_A54");
330                populatePid(adtA54.getPID());
331                populateRolA(adtA54.insertROL(0));
332
333                // Visit, attending, admitting, diagnosis, etc
334                populatePv1(adtA54.getPV1());
335                populateRolB(adtA54.insertROL2(0));
336                populateRolC(adtA54.insertROL2(1));
337
338                return adtA54;
339        }
340
341        public ADT_A60 createAdtA60() throws HL7Exception {
342                return createAdtA60(false);
343        }
344
345        public ADT_A60 createAdtA60(boolean thePopulateEncounterFields) throws HL7Exception {
346                ADT_A60 a60 = new ADT_A60();
347
348                populateMsh(a60.getMSH(), "ADT^A60^ADT_A01");
349                populatePid(a60.getPID());
350                populateIam(a60.getIAM(0));
351
352                if (thePopulateEncounterFields) {
353                        populatePv1(a60.getPV1());
354                        populatePv2(a60.getPV2());
355                }
356
357                return a60;
358        }
359
360        public DFT_P03 createDftP03() throws HL7Exception {
361                DFT_P03 p03 = new DFT_P03();
362
363                populateMsh(p03.getMSH(), "DFT^P03^DFT_P03");
364                populatePid(p03.getPID());
365
366                FT1 ft1 = p03.getFINANCIAL().getFT1();
367                ft1.getFt11_SetIDFT1().setValue("1");
368                ft1.getFt12_TransactionID().setValue("1133");
369                addExtraComponent(ft1.getFt12_TransactionID(), 0, "http://transaction-ids");
370                ft1.getFt13_TransactionBatchID().setValue("9999");
371                ft1.getFt14_TransactionDate().getDr1_RangeStartDateTime().parse("20150325000000-0000");
372                ft1.getFt14_TransactionDate().getDr2_RangeEndDateTime().parse("20150326000000-0000");
373                ft1.getFt16_TransactionType().setValue("CG");
374                ft1.getFt18_TransactionDescription().setValue("Consultation-Level 4");
375                ft1.getFt110_TransactionQuantity().setValue("4");
376                ft1.getFt116_AssignedPatientLocation().getPl1_PointOfCare().setValue("Acme Hospital");
377                ft1.getFt116_AssignedPatientLocation().getPl2_Room().setValue("3rd Floor Room 124");
378                ft1.getFt116_AssignedPatientLocation().getPl3_Bed().setValue("6");
379                ft1.getFt116_AssignedPatientLocation()
380                                .getPl4_Facility()
381                                .getHd1_NamespaceID()
382                                .setValue("Acme Facility");
383                ft1.getFt116_AssignedPatientLocation().getPl9_LocationDescription().setValue("The Acme Hospital");
384                ft1.getFt116_AssignedPatientLocation()
385                                .getPl10_ComprehensiveLocationIdentifier()
386                                .getEi1_EntityIdentifier()
387                                .setValue("Acme H");
388                ft1.getFt116_AssignedPatientLocation()
389                                .getPl10_ComprehensiveLocationIdentifier()
390                                .getEi2_NamespaceID()
391                                .setValue("http://acme.org/wards");
392
393                ft1.getFt120_PerformedByCode(0).getXcn1_IDNumber().setValue("666");
394                ft1.getFt120_PerformedByCode(0).getXcn2_FamilyName().getFn1_Surname().setValue("Dinosaur");
395                ft1.getFt120_PerformedByCode(0).getXcn3_GivenName().setValue("Frances");
396                ft1.getFt120_PerformedByCode(0)
397                                .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
398                                .setValue("Frannie");
399                ft1.getFt120_PerformedByCode(0)
400                                .getXcn9_AssigningAuthority()
401                                .getHd1_NamespaceID()
402                                .setValue("http://acme.org/clinicians");
403
404                ft1.getFt120_PerformedByCode(1).getXcn1_IDNumber().setValue("666");
405                ft1.getFt120_PerformedByCode(1).getXcn2_FamilyName().getFn1_Surname().setValue("Dinosaur");
406                ft1.getFt120_PerformedByCode(1).getXcn3_GivenName().setValue("Frances");
407                ft1.getFt120_PerformedByCode(1)
408                                .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
409                                .setValue("Frannie");
410                ft1.getFt120_PerformedByCode(1)
411                                .getXcn9_AssigningAuthority()
412                                .getHd1_NamespaceID()
413                                .setValue("http://acme.org/clinicians");
414
415                ft1.getFt121_OrderedByCode(0).getXcn1_IDNumber().setValue("555");
416                ft1.getFt121_OrderedByCode(0).getXcn2_FamilyName().getFn1_Surname().setValue("Giraffe");
417                ft1.getFt121_OrderedByCode(0).getXcn3_GivenName().setValue("Longneck");
418                ft1.getFt121_OrderedByCode(0)
419                                .getXcn9_AssigningAuthority()
420                                .getHd1_NamespaceID()
421                                .setValue("http://acme.org/clinicians");
422
423                populatePr1First(p03.getFINANCIAL().getFINANCIAL_PROCEDURE().getPR1());
424                populateDg1(p03.getDG1());
425
426                populateIn1(p03.getINSURANCE().getIN1());
427                populateIn2(p03.getINSURANCE().getIN2());
428
429                return p03;
430        }
431
432        public ORM_O01 createOrmO01() throws HL7Exception {
433                ORM_O01 orm = new ORM_O01();
434
435                populateMsh(orm.getMSH(), "ORM^O01^ORM_O01");
436
437                // PATIENT
438                populatePid(orm.getPATIENT().getPID(), true);
439                populatePv1(orm.getPATIENT().getPATIENT_VISIT().getPV1());
440                populateIn1(orm.getPATIENT().getINSURANCE().getIN1()); // Mapped to Organizaion
441                populateIn2(orm.getPATIENT().getINSURANCE().getIN2()); // Mapped to extension on the Patient
442                populateGt1(orm.getPATIENT().getGT1()); // Mapped to RelatedPerson
443                populateDg1(orm.getORDER(0).getORDER_DETAIL().getDG1());
444                orm.getORDER(0)
445                                .getORDER_DETAIL()
446                                .getDG1()
447                                .getDg13_DiagnosisCodeDG1()
448                                .getCe1_Identifier()
449                                .setValue("193462001");
450                orm.getORDER(0)
451                                .getORDER_DETAIL()
452                                .getDG1()
453                                .getDg13_DiagnosisCodeDG1()
454                                .getCe2_Text()
455                                .setValue("Insomnia");
456                orm.getORDER(0).getORDER_DETAIL().getDG1().getDg16_DiagnosisType().setValue("Tentative");
457
458                XCN dg116 = orm.getORDER(0).getORDER_DETAIL().getDG1().insertDg116_DiagnosingClinician(0);
459                populateXcn(dg116);
460
461                orm.getORDER(0)
462                                .getORDER_DETAIL()
463                                .getDG1()
464                                .getDg120_DiagnosisIdentifier()
465                                .getEi1_EntityIdentifier()
466                                .setValue("0000000042");
467                orm.getORDER(0)
468                                .getORDER_DETAIL()
469                                .getDG1()
470                                .getDg120_DiagnosisIdentifier()
471                                .getEi2_NamespaceID()
472                                .setValue("http://acme.org/diagnosis-identifiers");
473
474                // ORDER
475                ORC orc = orm.getORDER().getORC(); // Mapped to DiagnosticOrder
476                orc.getOrc1_OrderControl().setValue("NW");
477
478                EI orc2 = orc.getOrc2_PlacerOrderNumber();
479                orc2.getEi1_EntityIdentifier().setValue("12345");
480                orc2.getEi2_NamespaceID().setValue("http://acme.org/diagnosticOrderIds");
481
482                orc.getOrc4_PlacerGroupNumber().getEi1_EntityIdentifier().setValue("123");
483                orc.getOrc4_PlacerGroupNumber().getEi2_NamespaceID().setValue("http://foo");
484
485                orc.getOrc7_QuantityTiming(0).getTq4_StartDateTime().getTs1_Time().setValue("20160210111213-0400");
486
487                XCN orc12 = orc.insertOrc12_OrderingProvider(0);
488                populateXcn(orc12);
489
490                OBR obr = orm.getORDER().getORDER_DETAIL().getOBR(); // Mapped to DiagnosticReport
491
492                EI obr2 = obr.getObr2_PlacerOrderNumber();
493                obr2.getEi1_EntityIdentifier().setValue("54321");
494                obr2.getEi2_NamespaceID().setValue("http://acme.org/diagnosticIds");
495
496                CE obr4 = obr.getObr4_UniversalServiceIdentifier();
497                obr4.getCe1_Identifier().setValue("5500-1");
498                obr4.getCe2_Text().setValue("Blood Panel");
499                obr4.getCe3_NameOfCodingSystem().setValue("http://acme.org/diagnosticCodes");
500
501                obr.getObr7_ObservationDateTime().getTs1_Time().setValue("201602131000-0400");
502                obr.getObr8_ObservationEndDateTime().getTs1_Time().setValue("201602131100-0400");
503                obr.getObr22_ResultsRptStatusChngDateTime().getTs1_Time().setValue("2017081312-0500");
504                obr.getObr25_ResultStatus().setValue("F");
505                obr.getObr27_QuantityTiming(0).getTq6_Priority().setValue("stat");
506
507                populateDg1(orm.getORDER(0).getORDER_DETAIL().getDG1()); // Mapped to Condition
508
509                // Observation stuff
510                ca.uhn.hl7v2.model.v25.group.ORM_O01_OBSERVATION order;
511                order = orm.getORDER(0).getORDER_DETAIL().getOBSERVATION();
512                order.getOBX().getObx2_ValueType().setValue("NM");
513                order.getOBX().getObx3_ObservationIdentifier().getCe1_Identifier().setValue("9477-3");
514                order.getOBX().getObx3_ObservationIdentifier().getCe2_Text().setValue("Sodium (Plasma)");
515                order.getOBX()
516                                .getObx3_ObservationIdentifier()
517                                .getCe3_NameOfCodingSystem()
518                                .setValue("http://acme.org/observationCodes");
519                NM nm = new NM(orm);
520                nm.setValue("150");
521                order.getOBX().insertObx5_ObservationValue(0).setData(nm);
522                order.getOBX().getObx6_Units().getCe1_Identifier().setValue("mmol/L");
523                order.getOBX().getObx6_Units().getCe2_Text().setValue("mmol/Liter");
524                order.getOBX().getObx6_Units().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.CODE_SYSTEM_UCUM);
525                order.getOBX().getObx7_ReferencesRange().setValue("0.2-333");
526                order.getOBX().getObx11_ObservationResultStatus().setValue("F");
527
528                CE obx15 = order.getOBX().getObx15_ProducerSID();
529                obx15.getCe1_Identifier().setValue("3141592");
530                obx15.getCe3_NameOfCodingSystem().setValue("http://acme.org/facility");
531
532                XCN obx16 = order.getOBX().getObx16_ResponsibleObserver(0);
533                populateXcn(obx16);
534
535                order.getOBX().getObx19_DateTimeOfTheAnalysis().getTs1_Time().setValue("20110202112233+0100");
536
537                Varies obx23 = (Varies) order.getOBX().getField(23, 0);
538                obx23.parse("Acme Facility");
539
540                Varies obx24 = (Varies) order.getOBX().getField(24, 0);
541                obx24.parse("342 Evergreen Terrace^2nd Floor^Springfield^NI^12345^USA^B^^Awesome Town");
542
543                return orm;
544        }
545
546        public ORU_R01 createOruR01() throws HL7Exception {
547                ORU_R01 r01 = new ORU_R01();
548                r01.setParser(ourV2Ctx.getPipeParser());
549
550                r01.getMSH().getMsh1_FieldSeparator().setValue("|");
551                r01.getMSH().getMsh2_EncodingCharacters().setValue("^~\\&");
552                r01.getMSH().getMsh3_SendingApplication().getHd1_NamespaceID().setValue("http://acme.org/application");
553                r01.getMSH().getMsh3_SendingApplication().getHd2_UniversalID().setValue("ACME Application");
554                r01.getMSH().getMsh4_SendingFacility().getHd1_NamespaceID().setValue("http://acme.org/facility");
555                r01.getMSH().getMsh4_SendingFacility().getHd2_UniversalID().setValue("Acme Facility");
556                r01.getMSH().getMsh9_MessageType().parse("ORU^R01^ORU_R01");
557                r01.getMSH().getMsh10_MessageControlID().setValue("A001");
558                r01.getMSH().getMsh11_ProcessingID().parse("T");
559                r01.getMSH().getMsh12_VersionID().parse("2.5");
560
561                ORU_R01_PATIENT_RESULT patientResult = r01.insertPATIENT_RESULT(0);
562                populatePid(patientResult.getPATIENT().getPID());
563                populatePv1(patientResult.getPATIENT().getVISIT().getPV1());
564
565                ORC orc = patientResult.getORDER_OBSERVATION().getORC();
566                orc.getOrc1_OrderControl().setValue("NW");
567
568                EI orc2 = orc.getOrc2_PlacerOrderNumber();
569                orc2.getEi1_EntityIdentifier().setValue("12345");
570                orc2.getEi2_NamespaceID().setValue("http://acme.org/diagnosticOrderIds");
571
572                orc.getOrc4_PlacerGroupNumber().getEi1_EntityIdentifier().setValue("123");
573                orc.getOrc4_PlacerGroupNumber().getEi2_NamespaceID().setValue("http://foo");
574
575                orc.getOrc7_QuantityTiming(0).getTq4_StartDateTime().getTs1_Time().setValue("20160210111213-0400");
576
577                XCN orc12 = orc.insertOrc12_OrderingProvider(0);
578                populateXcn(orc12);
579
580                OBR obr = patientResult.getORDER_OBSERVATION().getOBR();
581
582                EI obr2 = obr.getObr2_PlacerOrderNumber();
583                obr2.getEi1_EntityIdentifier().setValue("54321");
584                obr2.getEi2_NamespaceID().setValue("http://acme.org/diagnosticIds");
585
586                CE obr4 = obr.getObr4_UniversalServiceIdentifier();
587                obr4.getCe1_Identifier().setValue("5500-1");
588                obr4.getCe2_Text().setValue("Blood Panel");
589                obr4.getCe3_NameOfCodingSystem().setValue("http://acme.org/diagnosticCodes");
590
591                obr.getObr7_ObservationDateTime().getTs1_Time().setValue("201602131000-0400");
592                obr.getObr8_ObservationEndDateTime().getTs1_Time().setValue("201602131100-0400");
593                obr.getObr22_ResultsRptStatusChngDateTime().getTs1_Time().setValue("2017081312-0500");
594                obr.getObr25_ResultStatus().setValue("F");
595                obr.getObr27_QuantityTiming(0).getTq6_Priority().setValue("stat");
596
597                patientResult.getORDER_OBSERVATION().getNTE(0).insertNte3_Comment(0).setValue("Comment Line 1");
598                patientResult.getORDER_OBSERVATION().getNTE(0).insertNte3_Comment(1).setValue("Comment Line 2");
599                patientResult.getORDER_OBSERVATION().getNTE(1).insertNte3_Comment(0).setValue("Comment Line 3");
600                patientResult.getORDER_OBSERVATION().getNTE(2).insertNte3_Comment(0).parse("Comment Line 4a & Comment Line 4b");
601
602                ca.uhn.hl7v2.model.v25.group.ORU_R01_OBSERVATION observation;
603                observation = patientResult
604                                .getORDER_OBSERVATION()
605                                .insertOBSERVATION(patientResult.getORDER_OBSERVATION().getOBSERVATIONReps());
606                observation.getOBX().getObx2_ValueType().setValue("NM");
607                observation.getOBX().getObx3_ObservationIdentifier().getCe1_Identifier().setValue("9477-3");
608                observation.getOBX().getObx3_ObservationIdentifier().getCe2_Text().setValue("Sodium (Plasma)");
609                observation
610                                .getOBX()
611                                .getObx3_ObservationIdentifier()
612                                .getCe3_NameOfCodingSystem()
613                                .setValue("http://acme.org/observationCodes");
614                NM nm = new NM(r01);
615                nm.setValue("150");
616                observation.getOBX().insertObx5_ObservationValue(0).setData(nm);
617                observation.getOBX().getObx6_Units().getCe1_Identifier().setValue("mmol/L");
618                observation.getOBX().getObx6_Units().getCe2_Text().setValue("mmol/Liter");
619                observation.getOBX().getObx6_Units().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.CODE_SYSTEM_UCUM);
620                observation.getOBX().getObx7_ReferencesRange().setValue("0.2-333");
621                observation.getOBX().getObx11_ObservationResultStatus().setValue("F");
622
623                CE obx15 = observation.getOBX().getObx15_ProducerSID();
624                obx15.getCe1_Identifier().setValue("3141592");
625                obx15.getCe3_NameOfCodingSystem().setValue("http://acme.org/facility");
626
627                XCN obx16 = observation.getOBX().getObx16_ResponsibleObserver(0);
628                populateXcn(obx16);
629
630                observation.getOBX().getObx19_DateTimeOfTheAnalysis().getTs1_Time().setValue("20110202112233+0100");
631
632                Varies obx23 = (Varies) observation.getOBX().getField(23, 0);
633                obx23.parse("Acme Facility");
634
635                Varies obx24 = (Varies) observation.getOBX().getField(24, 0);
636                obx24.parse("342 Evergreen Terrace^2nd Floor^Springfield^NI^12345^USA^B^^Awesome Town");
637
638                observation = patientResult
639                                .getORDER_OBSERVATION()
640                                .insertOBSERVATION(patientResult.getORDER_OBSERVATION().getOBSERVATIONReps());
641                observation.getOBX().getObx2_ValueType().setValue("DT");
642                observation.getOBX().getObx3_ObservationIdentifier().getCe1_Identifier().setValue("3472-2");
643                observation.getOBX().getObx3_ObservationIdentifier().getCe2_Text().setValue("Fasting Date");
644                observation
645                                .getOBX()
646                                .getObx3_ObservationIdentifier()
647                                .getCe3_NameOfCodingSystem()
648                                .setValue("http://acme.org/observationCodes");
649                DT dt = new DT(r01);
650                dt.setValue("20160213");
651                observation.getOBX().insertObx5_ObservationValue(0).setData(dt);
652                observation.getOBX().getObx11_ObservationResultStatus().setValue("F");
653                observation.getOBX().getObx14_DateTimeOfTheObservation().getTs1_Time().setValue("20160101121314.1234-0400");
654                observation.getNTE(0).insertNte3_Comment(0).setValue("Comment Line 1");
655                observation.getNTE(0).insertNte3_Comment(1).setValue("Comment Line 2");
656                observation.getNTE(1).insertNte3_Comment(0).setValue("Comment Line 3");
657                observation.getNTE(2).insertNte3_Comment(0).parse("Comment Line 4a & Comment Line 4b");
658
659                obx15 = observation.getOBX().getObx15_ProducerSID();
660                obx15.getCe1_Identifier().setValue("3141592");
661                obx15.getCe3_NameOfCodingSystem().setValue("http://acme.org/facility");
662
663                obx23 = (Varies) observation.getOBX().getField(23, 0);
664                obx23.parse("Acme Facility");
665
666                obx24 = (Varies) observation.getOBX().getField(24, 0);
667                obx24.parse("342 Evergreen Terrace^2nd Floor^Springfield^NI^12345^USA^B^^Awesome Town");
668
669                // Some OBX String lines
670
671                observation = patientResult
672                                .getORDER_OBSERVATION()
673                                .insertOBSERVATION(patientResult.getORDER_OBSERVATION().getOBSERVATIONReps());
674                observation.getOBX().getObx2_ValueType().setValue("ST");
675                observation.getOBX().getObx3_ObservationIdentifier().getCe1_Identifier().setValue("17464-1");
676                observation.getOBX().getObx3_ObservationIdentifier().getCe2_Text().setValue("Text Comment");
677                observation
678                                .getOBX()
679                                .getObx3_ObservationIdentifier()
680                                .getCe3_NameOfCodingSystem()
681                                .setValue("http://acme.org/observationCodes");
682                ST st = new ST(r01);
683                st.setValue("line 1");
684                observation.getOBX().insertObx5_ObservationValue(0).setData(st);
685                st = new ST(r01);
686                st.setValue("line 2");
687                observation.getOBX().insertObx5_ObservationValue(1).setData(st);
688
689                obx15 = observation.getOBX().getObx15_ProducerSID();
690                obx15.getCe1_Identifier().setValue("3141592");
691                obx15.getCe3_NameOfCodingSystem().setValue("http://acme.org/facility");
692
693                obx23 = (Varies) observation.getOBX().getField(23, 0);
694                obx23.parse("Acme Facility");
695
696                obx24 = (Varies) observation.getOBX().getField(24, 0);
697                obx24.parse("342 Evergreen Terrace^2nd Floor^Springfield^NI^12345^USA^B^^Awesome Town");
698
699                observation = patientResult
700                                .getORDER_OBSERVATION()
701                                .insertOBSERVATION(patientResult.getORDER_OBSERVATION().getOBSERVATIONReps());
702                observation.getOBX().getObx2_ValueType().setValue("ST");
703                observation.getOBX().getObx3_ObservationIdentifier().getCe1_Identifier().setValue("17464-1");
704                observation.getOBX().getObx3_ObservationIdentifier().getCe2_Text().setValue("Text Comment");
705                observation
706                                .getOBX()
707                                .getObx3_ObservationIdentifier()
708                                .getCe3_NameOfCodingSystem()
709                                .setValue("http://acme.org/observationCodes");
710                st = new ST(r01);
711                st.setValue("line 3");
712                observation.getOBX().insertObx5_ObservationValue(0).setData(st);
713                st = new ST(r01);
714                st.setValue("line 4");
715                observation.getOBX().insertObx5_ObservationValue(1).setData(st);
716
717                obx15 = observation.getOBX().getObx15_ProducerSID();
718                obx15.getCe1_Identifier().setValue("3141592");
719                obx15.getCe3_NameOfCodingSystem().setValue("http://acme.org/facility");
720
721                obx23 = (Varies) observation.getOBX().getField(23, 0);
722                obx23.parse("Acme Facility");
723
724                obx24 = (Varies) observation.getOBX().getField(24, 0);
725                obx24.parse("342 Evergreen Terrace^2nd Floor^Springfield^NI^12345^USA^B^^Awesome Town");
726
727                return r01;
728        }
729
730        public RDE_O11 createRdeO11() throws HL7Exception {
731                return createRdeO11(false);
732        }
733
734        public RDE_O11 createRdeO11(boolean hasMultipleComponents) throws HL7Exception {
735                return createRdeO11(hasMultipleComponents, true);
736        }
737
738        public RDE_O11 createRdeO11(boolean hasMultipleComponents, boolean bothComponentsAreCoded) throws HL7Exception {
739                RDE_O11 rde = new RDE_O11();
740                populateMsh(rde.getMSH(), "RDE^O11^RDE_O11");
741                populatePid(rde.getPATIENT().getPID(), true);
742                populatePv1(rde.getPATIENT().getPATIENT_VISIT().getPV1());
743
744                RDE_O11_ORDER order = rde.insertORDER(0);
745                ORC orc = order.getORC();
746                populateOrcForMedication(orc, "NW", true, false);
747
748                RXE rxe = order.getRXE();
749                populateRxe(rxe);
750
751                RXR rxr = order.getRXR();
752                populateRxr(rxr);
753
754                RXC rxc = order.insertRXC(0);
755                rxc.getRxc1_RXComponentType().setValue("A");
756                rxc.getRxc2_ComponentCode().getCe1_Identifier().setValue("MEW");
757                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Kittens");
758                rxc.getRxc2_ComponentCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/cats");
759                rxc.getRxc3_ComponentAmount().setValue("0.5");
760                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
761
762                if (hasMultipleComponents) {
763                        if (bothComponentsAreCoded) {
764                                rxc = order.insertRXC(1);
765                                rxc.getRxc1_RXComponentType().setValue("B");
766                                rxc.getRxc2_ComponentCode().getCe1_Identifier().setValue("WAF");
767                                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Puppies");
768                                rxc.getRxc2_ComponentCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/dogs");
769                                rxc.getRxc3_ComponentAmount().setValue("0.3");
770                                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
771                        } else {
772                                rxc = order.insertRXC(1);
773                                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Duckies");
774                                rxc.getRxc3_ComponentAmount().setValue("0.2");
775                                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
776                        }
777                }
778
779                return rde;
780        }
781
782        public SIU_S12 createSiuS12() throws HL7Exception {
783
784                /* Sample from NEMS
785                MSH|^~\&|NextGen Rosetta|NextGen Clinic^0001|Billing System|Billing System|20201215094458188||SIU^S14|365776434|P|2.5
786                SCH|5617679^5617679|5617679^5617679||||79c7e354-8743-47ed-b8ca-66c4308c55ff^Follow Up 15 Min|^Smile API Testing Details|79c7e354-8743-47ed-b8ca-66c4308c55ff^Follow Up 15 Min|15|minutes|^^^202012150945^202012151000|||||1562^CDR^Smile||||1562^CDR^Smile|||||KEPT
787                PID|1|000001084399|312759||Test^Xiuming||20000401|M||11111111-1234-5678-3333-111122223333^Declined to specify|123 Smile Ave^^San Francisco^CA^94112^4c370504-8471-4303-a04b-200a31015e17^^^121cbd16-ba04-4d58-ac09-9ada6474505b||4152223333||^eng^|||||||78860700-68ed-4c0f-bf10-b6a522831ae4^Other||||||||N
788                PV1|1|O|ab8af01a-fbcc-4ead-9b24-8bac014f413b||||bd1a5a82-6dee-4a8a-8059-37e8db475b1e^Smile PROV^Demo|||||||||||||||||||||||||||||||||||||202012150944||||||c9fb567a-e4e5-4e2e-a042-23db78859880
789                AIL|1|A|ab8af01a-fbcc-4ead-9b24-8bac014f413b^San Bruno Adult NEMS^San Bruno 1 Medical|^Place||202012150945||||||KEPT
790                AIP|1|A|bd1a5a82-6dee-4a8a-8059-37e8db475b1e^Smile PROV^Demo|P^Attending||202012150945||||||KEPT
791                AIP|2|A|e1e79ce3-070b-48eb-b898-dc498f6efcaa^Abstracted^Med|S^Resource||202012150945||||||KEPT
792                NTE||{"formSet":[{"formLabel":"nems-instructions"},{"formLabel":"nems-phq9"},{"formLabel":"nems-bhs"},{"formLabel":"nems-gad7"}]}|20^8^14||+Smile API Testing
793                 */
794
795                SIU_S12 siu = new SIU_S12();
796
797                populateMsh(siu.getMSH(), "SIU^S12^SIU_S12");
798
799                populateSch(siu.getSCH());
800                populateAil(siu.getRESOURCES().getLOCATION_RESOURCE().getAIL());
801                populateAip(siu.getRESOURCES().getPERSONNEL_RESOURCE().getAIP());
802
803                populatePv1(siu.getPATIENT().getPV1());
804                populatePid(siu.getPATIENT().getPID(), true);
805
806                return siu;
807        }
808
809        public VXU_V04 createVxuV04() throws HL7Exception {
810                VXU_V04 vxu = new VXU_V04();
811
812                // Patient, family doctor, next of kin, and employer
813                populateMsh(vxu.getMSH(), "VXU^V04^VXU_V04");
814                populatePid(vxu.getPID(), true);
815
816                ORC orc = vxu.getORDER().getORC();
817                orc.getOrc1_OrderControl().setValue("RE");
818                orc.getOrc2_PlacerOrderNumber().getEi1_EntityIdentifier().setValue("0001");
819                orc.getOrc2_PlacerOrderNumber().getEi2_NamespaceID().setValue("http://acme.org/vaxorders");
820
821                XCN orc12 = orc.insertOrc12_OrderingProvider(0);
822                populateXcn(orc12);
823
824                /*
825                Sample from MUSC
826
827                MSH|^~\&|EPIC|SC378274|SIMON|SIMON|20210202071234-0500|NOF200|VXU^V04^VXU_V04|878162|P|2.5.1|||ER|AL|||||Z22^CDCPHINVS||
828                PID|1||009999901^^^MRN^MR||TESTER^NICK^^^^^L||19810724|M|||55 FAKE STREET^^CHARLESTON^SC^29401^US^P^^| |^PRN^PH^^1^865^5551212~^NET^Internet^npappageorgio@gmail.com|||||9950381520||||||N||||||N||
829                ORC|RE|228878084^MUSC_EPIC|16306934^MUSC||||||20210202071216-0500|NOF200^FLEISCHMANN^NOELLE^^^^^^MUSCNetID||1871601732^SCHEURER^DANIELLE^B.^^^^^MUSC_EPIC^^^^PNPI|^^^MUSC RUTLEDGE TOWER&SC378274&IMM^^^^^|^^^^1^843^7922300^^||||58D99F5F5D8CD6502783D9901B5E1ECDA83173F1^ROVER IOS 144|||||||||||I|
830                RXA|0|1|20210202|20210202|208^COVID-19, MRNA, LNP-S, PF, 30 MCG/0.3 ML^CVX|30|mcg^micrograms^UCUM||00^New immunization record^NIP001~^VIS date: 12/01/2020~~~|NOF200^FLEISCHMANN^NOELLE^^^^^^MUSCNetID|^^^MUSC RUTLEDGE TOWER&SC378274&IMM^^^^^||||EN9581|20210502|PFR^Pfizer, Inc^MVX|||CP|A|20210202071234-0500||||||
831                RXR|IM^Intramuscular^HL70162|LD^Left deltoid^HL70163
832                OBX|1|CE|30956-7^Vaccine Type^LN|1|208^COVID-19, MRNA, LNP-S, PF, 30 MCG/0.3 ML^CVX||||||F|||20210202||||||||||||||||||
833                OBX|2|DT|29768-9^VIS Publication Date^LN|1|20201201||||||F|||20210202||||||||||||||||||
834                OBX|3|DT|29769-7^VIS Presentation Date^LN|1|20210202||||||F|||20210202||||||||||||||||||
835                */
836
837                RXA rxa = vxu.getORDER().getRXA();
838                rxa.getRxa2_AdministrationSubIDCounter().setValue("1");
839                rxa.getRxa2_AdministrationSubIDCounter()
840                                .getExtraComponents()
841                                .getComponent(0)
842                                .getData()
843                                .parse("http://acme.org/medadmins");
844                rxa.getRxa3_DateTimeStartOfAdministration().getTs1_Time().setValue("20171209071055-0500");
845                rxa.getRxa4_DateTimeEndOfAdministration().getTs1_Time().setValue("20171209071100-0500");
846                rxa.getRxa5_AdministeredCode().getCe1_Identifier().setValue("208");
847                rxa.getRxa5_AdministeredCode().getCe2_Text().setValue("COVID-19, MRNA, LNP-S, PF, 30 MCG/0.3 ML");
848                rxa.getRxa5_AdministeredCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/meds");
849                rxa.getRxa6_AdministeredAmount().setValue("4");
850                rxa.getRxa7_AdministeredUnits().parse("mg^milligrams^http://unitsofmeasure.org");
851                rxa.getRxa9_AdministrationNotes(0).getCe2_Text().setValue("This is a note");
852
853                rxa.getRxa10_AdministeringProvider(0).getXcn1_IDNumber().setValue("825");
854                rxa.getRxa10_AdministeringProvider(0)
855                                .getXcn2_FamilyName()
856                                .getFn1_Surname()
857                                .setValue("Bouvier");
858                rxa.getRxa10_AdministeringProvider(0).getXcn3_GivenName().setValue("Marge");
859                rxa.getRxa10_AdministeringProvider(0)
860                                .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
861                                .setValue("Q");
862                rxa.getRxa10_AdministeringProvider(0)
863                                .getXcn9_AssigningAuthority()
864                                .getHd1_NamespaceID()
865                                .setValue("http://acme.org/clinicians");
866
867                rxa.getRxa12_AdministeredPerTimeUnit().setValue("Day");
868                rxa.getRxa20_CompletionStatus().setValue("CP");
869
870                populateRxr(vxu.getORDER().getRXR());
871
872                return vxu;
873        }
874
875        public void populateAil(AIL theAil) throws HL7Exception {
876
877                theAil.getAil1_SetIDAIL().setValue("4321");
878                theAil.getAil2_SegmentActionCode().setValue("U"); // [A]dd, [D]elete, [U]pdate, [X] no change
879                theAil.getAil3_LocationResourceID(0)
880                                .getPl1_PointOfCare()
881                                .setValue("locations^http://acme.org/location/321^DNS");
882                theAil.getAil3_LocationResourceID(0).getPl2_Room().setValue("room^http://acme.org/location/room/321^DNS");
883                theAil.getAil3_LocationResourceID(0).getPl3_Bed().setValue("bed^http://acme.org/location/room/321/bed/a^DNS");
884                // AIL-3.PL-10.EI-1,EI-2 are responsible for a location's first identifier
885                theAil.getAil3_LocationResourceID(0)
886                                .getPl10_ComprehensiveLocationIdentifier()
887                                .getEi1_EntityIdentifier()
888                                .setValue("6789");
889                theAil.getAil3_LocationResourceID(0)
890                                .getPl10_ComprehensiveLocationIdentifier()
891                                .getEi2_NamespaceID()
892                                .setValue("http://acme.org/locaton");
893                theAil.getAil3_LocationResourceID(0)
894                                .getPl11_AssigningAuthorityForLocation()
895                                .getHd1_NamespaceID()
896                                .setValue("http://acme.org");
897
898                theAil.getAil4_LocationTypeAIL().getCe1_Identifier().setValue("C");
899
900                theAil.getAil6_StartDateTime().getTs1_Time().setValue("202104121335-0500");
901
902                theAil.getAil9_Duration().setValue("30");
903                theAil.getAil10_DurationUnits().getCe1_Identifier().setValue("minutes");
904                theAil.getAil10_DurationUnits().getCe2_Text().setValue("Minutes");
905        }
906
907        public void populateAip(AIP theAip) throws HL7Exception {
908
909                theAip.getAip1_SetIDAIP().setValue("6543");
910                theAip.getAip2_SegmentActionCode().setValue("U"); // [A]dd, [D]elete, [U]pdate, [X] no change
911                theAip.getAip3_PersonnelResourceID(0).getXcn1_IDNumber().setValue("5432");
912                theAip.getAip3_PersonnelResourceID(0)
913                                .getXcn2_FamilyName()
914                                .getFn1_Surname()
915                                .setValue("Smith");
916                theAip.getAip3_PersonnelResourceID(0).getXcn3_GivenName().setValue("Jane");
917                theAip.getAip3_PersonnelResourceID(0)
918                                .getXcn9_AssigningAuthority()
919                                .getHd1_NamespaceID()
920                                .setValue("http://acme.org");
921
922                theAip.getAip4_ResourceType().getCe1_Identifier().setValue("PPRF");
923
924                theAip.getAip6_StartDateTime().getTs1_Time().setValue("202104121335-0500");
925
926                theAip.getAip9_Duration().setValue("30");
927                theAip.getAip10_DurationUnits().getCe1_Identifier().setValue("minutes");
928                theAip.getAip10_DurationUnits().getCe2_Text().setValue("Minutes");
929
930                theAip.getAip12_FillerStatusCode().getCe1_Identifier().setValue("Booked");
931        }
932
933        public void populateDg1(DG1 theDg1) throws DataTypeException {
934                theDg1.getDg13_DiagnosisCodeDG1().getCe1_Identifier().setValue("193462001");
935                theDg1.getDg13_DiagnosisCodeDG1().getCe2_Text().setValue("Insomnia");
936                theDg1.getDg13_DiagnosisCodeDG1().getCe3_NameOfCodingSystem().setValue("http://snomed.info/sct");
937        }
938
939        public DG1 populateDg1(DG1 theDg1, boolean includeDiagnosisTypeAndPriority) throws HL7Exception {
940                theDg1.getDg13_DiagnosisCodeDG1().getCe1_Identifier().setValue("193462001");
941                theDg1.getDg13_DiagnosisCodeDG1().getCe2_Text().setValue("Insomnia");
942                theDg1.getDg13_DiagnosisCodeDG1().getCe3_NameOfCodingSystem().setValue("http://snomed.info/sct");
943
944                theDg1.getDg15_DiagnosisDateTime().getTs1_Time().setValue("20010101070000-0400");
945
946                if (includeDiagnosisTypeAndPriority) {
947                        theDg1.getDg16_DiagnosisType().setValue("F");
948                        theDg1.getDg115_DiagnosisPriority().setValue("1");
949                }
950
951                XCN dg116 = theDg1.insertDg116_DiagnosingClinician(0);
952                populateXcn(dg116);
953
954                theDg1.getDg120_DiagnosisIdentifier().getEi1_EntityIdentifier().setValue("0000000042");
955                theDg1.getDg120_DiagnosisIdentifier().getEi2_NamespaceID().setValue("http://acme.org/diagnosis-identifiers");
956
957                return theDg1;
958        }
959
960        public void populateGt1(GT1 theGt1) throws HL7Exception {
961                theGt1.getGt12_GuarantorNumber(0).getCx1_IDNumber().setValue("23323");
962                theGt1.getGt12_GuarantorNumber(0)
963                                .getCx4_AssigningAuthority()
964                                .getHd1_NamespaceID()
965                                .setValue("http://acme.org/guarantors");
966                theGt1.getGt12_GuarantorNumber(1).getCx1_IDNumber().setValue("32332");
967                theGt1.getGt12_GuarantorNumber(1)
968                                .getCx4_AssigningAuthority()
969                                .getHd1_NamespaceID()
970                                .setValue("http://acme.org/guarantors");
971                XPN gt13 = theGt1.insertGt13_GuarantorName(0);
972                gt13.getXpn1_FamilyName().getFn1_Surname().setValue("Smith");
973                gt13.getXpn2_GivenName().setValue("Fannie");
974                gt13.getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("Foo");
975                gt13.getXpn4_SuffixEgJRorIII().setValue("Jr");
976                gt13.getXpn7_NameTypeCode().setValue("L");
977                XAD gt15 = theGt1.insertGt15_GuarantorAddress(0);
978                gt15.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("313 Fleet Street");
979                gt15.getXad3_City().setValue("Cheektowaga");
980                gt15.getXad4_StateOrProvince().setValue("NY");
981                gt15.getXad5_ZipOrPostalCode().setValue("28366");
982                gt15.getXad6_Country().setValue("USA");
983                gt15.getXad7_AddressType().setValue("W");
984                XTN gt16 = theGt1.insertGt16_GuarantorPhNumHome(0);
985                gt16.getXtn1_TelephoneNumber().setValue("1(333)555-1234");
986                gt16.getXtn2_TelecommunicationUseCode().setValue("PRN");
987                gt16.getXtn3_TelecommunicationEquipmentType().setValue("PH");
988                theGt1.getGt18_GuarantorDateTimeOfBirth().getTs1_Time().setValue("19000102");
989                theGt1.getGt19_GuarantorAdministrativeSex().setValue("M");
990                theGt1.getGt111_GuarantorRelationship().getCe1_Identifier().setValue("MTH");
991                theGt1.getGt111_GuarantorRelationship().getCe2_Text().setValue("mother");
992                theGt1.getGt111_GuarantorRelationship()
993                                .getCe3_NameOfCodingSystem()
994                                .setValue(CodeSystemEnum.ROLE_CODE.getCodeSystemUri(ourContext));
995        }
996
997        public void populateIam(IAM theIam) throws HL7Exception {
998                theIam.getIam2_AllergenTypeCode().getCe1_Identifier().setValue("DA");
999                theIam.getIam2_AllergenTypeCode().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0127);
1000                theIam.getIam3_AllergenCodeMnemonicDescription().getCe1_Identifier().setValue("256259004");
1001                theIam.getIam3_AllergenCodeMnemonicDescription().getCe2_Text().setValue("Pollen (Substance)");
1002                theIam.getIam3_AllergenCodeMnemonicDescription()
1003                                .getCe3_NameOfCodingSystem()
1004                                .setValue(PublicApiConstants.CODE_SYSTEM_SNOMED);
1005                theIam.getIam4_AllergySeverityCode().getCe1_Identifier().setValue("SV");
1006                theIam.getIam4_AllergySeverityCode().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0128);
1007                theIam.getIam5_AllergyReactionCode(0).setValue("Wheezing");
1008                theIam.getIam5_AllergyReactionCode(1).setValue("Puking Guts Out");
1009                theIam.getIam7_AllergyUniqueIdentifier().getEi1_EntityIdentifier().setValue("88344");
1010                theIam.getIam7_AllergyUniqueIdentifier().getEi2_NamespaceID().setValue("http://acme.org/allergies");
1011                theIam.getIam11_OnsetDate().parse("20170203");
1012                theIam.getIam13_ReportedDateTime().parse("20170204");
1013                theIam.getIam17_AllergyClinicalStatusCode().getCe1_Identifier().setValue("C");
1014                theIam.getIam17_AllergyClinicalStatusCode().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0438);
1015        }
1016
1017        public void populateAl1(AL1 theIam) throws HL7Exception {
1018                theIam.getAl12_AllergenTypeCode().getCe1_Identifier().setValue("DA");
1019                theIam.getAl12_AllergenTypeCode().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0127);
1020                theIam.getAl13_AllergenCodeMnemonicDescription().getCe1_Identifier().setValue("256259004");
1021                theIam.getAl13_AllergenCodeMnemonicDescription().getCe2_Text().setValue("Pollen (Substance)");
1022                theIam.getAl13_AllergenCodeMnemonicDescription()
1023                                .getCe3_NameOfCodingSystem()
1024                                .setValue(PublicApiConstants.CODE_SYSTEM_SNOMED);
1025                theIam.getAl14_AllergySeverityCode().getCe1_Identifier().setValue("SV");
1026                theIam.getAl14_AllergySeverityCode().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0128);
1027                theIam.getAl15_AllergyReactionCode(0).setValue("Wheezing");
1028                theIam.getAl15_AllergyReactionCode(1).setValue("Puking Guts Out");
1029                theIam.getAl16_IdentificationDate().setValue("20001231");
1030        }
1031
1032        public void populateIn1(IN1 theIn1) throws DataTypeException {
1033                theIn1.getIn12_InsurancePlanID().getCe3_NameOfCodingSystem().setValue("http://acme.org/insurancePlanIds");
1034                theIn1.getIn12_InsurancePlanID().getCe1_Identifier().setValue("449988");
1035                theIn1.getIn13_InsuranceCompanyID(0).getCx1_IDNumber().setValue("443322");
1036                theIn1.getIn13_InsuranceCompanyID(0)
1037                                .getCx4_AssigningAuthority()
1038                                .getHd1_NamespaceID()
1039                                .setValue("http://acme.org/insurerIds");
1040                theIn1.getIn14_InsuranceCompanyName(0).getXon1_OrganizationName().setValue("InsurerCo");
1041                theIn1.getIn15_InsuranceCompanyAddress(0)
1042                                .getXad1_StreetAddress()
1043                                .getSad1_StreetOrMailingAddress()
1044                                .setValue("342 Evergreen Terrace");
1045                theIn1.getIn15_InsuranceCompanyAddress(0).getXad2_OtherDesignation().setValue("2nd Floor");
1046                theIn1.getIn15_InsuranceCompanyAddress(0).getXad3_City().setValue("Springfield");
1047                theIn1.getIn15_InsuranceCompanyAddress(0).getXad4_StateOrProvince().setValue("NI");
1048                theIn1.getIn15_InsuranceCompanyAddress(0).getXad5_ZipOrPostalCode().setValue("12345");
1049                theIn1.getIn15_InsuranceCompanyAddress(0).getXad6_Country().setValue("USA");
1050                theIn1.getIn15_InsuranceCompanyAddress(0).getXad7_AddressType().setValue("W");
1051                theIn1.getIn116_NameOfInsured(0).getXpn1_FamilyName().getFn1_Surname().setValue("Smith");
1052                theIn1.getIn116_NameOfInsured(0).getXpn2_GivenName().setValue("John");
1053                theIn1.getIn116_NameOfInsured(0)
1054                                .getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof()
1055                                .setValue("Q");
1056                theIn1.getIn116_NameOfInsured(0).getXpn4_SuffixEgJRorIII().setValue("Jr");
1057                theIn1.getIn116_NameOfInsured(0).getXpn7_NameTypeCode().setValue("L");
1058        }
1059
1060        public void populateIn1Difference(IN1 theIn1, String identifier) throws DataTypeException {
1061                theIn1.getIn12_InsurancePlanID().getCe3_NameOfCodingSystem().setValue("http://acme.org/insurancePlanIds");
1062                theIn1.getIn12_InsurancePlanID().getCe1_Identifier().setValue("449988" + identifier);
1063                theIn1.getIn13_InsuranceCompanyID(0).getCx1_IDNumber().setValue("443322" + identifier);
1064                theIn1.getIn13_InsuranceCompanyID(0)
1065                                .getCx4_AssigningAuthority()
1066                                .getHd1_NamespaceID()
1067                                .setValue("http://acme.org/insurerIds");
1068                theIn1.getIn14_InsuranceCompanyName(0).getXon1_OrganizationName().setValue("InsurerCo" + identifier);
1069                theIn1.getIn15_InsuranceCompanyAddress(0)
1070                                .getXad1_StreetAddress()
1071                                .getSad1_StreetOrMailingAddress()
1072                                .setValue("342 Evergreen Terrace");
1073                theIn1.getIn15_InsuranceCompanyAddress(0).getXad2_OtherDesignation().setValue("2nd Floor");
1074                theIn1.getIn15_InsuranceCompanyAddress(0).getXad3_City().setValue("Springfield");
1075                theIn1.getIn15_InsuranceCompanyAddress(0).getXad4_StateOrProvince().setValue("NI");
1076                theIn1.getIn15_InsuranceCompanyAddress(0).getXad5_ZipOrPostalCode().setValue("12345");
1077                theIn1.getIn15_InsuranceCompanyAddress(0).getXad6_Country().setValue("USA");
1078                theIn1.getIn15_InsuranceCompanyAddress(0).getXad7_AddressType().setValue("W");
1079                theIn1.getIn116_NameOfInsured(0).getXpn1_FamilyName().getFn1_Surname().setValue("Smith");
1080                theIn1.getIn116_NameOfInsured(0).getXpn2_GivenName().setValue("John");
1081                theIn1.getIn116_NameOfInsured(0)
1082                                .getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof()
1083                                .setValue("Q");
1084                theIn1.getIn116_NameOfInsured(0).getXpn4_SuffixEgJRorIII().setValue("Jr");
1085                theIn1.getIn116_NameOfInsured(0).getXpn7_NameTypeCode().setValue("L");
1086        }
1087
1088        public void populateIn2(IN2 theIn2) throws HL7Exception {
1089                theIn2.getIn214_MilitaryService().setValue("A");
1090                theIn2.getIn214_MilitaryService()
1091                                .getExtraComponents()
1092                                .getComponent(0)
1093                                .getData()
1094                                .parse("U.S. ARMY");
1095                theIn2.getIn214_MilitaryService()
1096                                .getExtraComponents()
1097                                .getComponent(1)
1098                                .getData()
1099                                .parse("urn:test:source:militarybranch");
1100                theIn2.getIn214_MilitaryService()
1101                                .getExtraComponents()
1102                                .getComponent(2)
1103                                .getData()
1104                                .parse("http://acme.org/fhir/StructureDefinition/patient-military-information");
1105                theIn2.getIn214_MilitaryService()
1106                                .getExtraComponents()
1107                                .getComponent(3)
1108                                .getData()
1109                                .parse("http://acme.org/fhir/StructureDefinition/patient-military-information/military-branch");
1110
1111                theIn2.getIn215_MilitaryRankGrade().setValue("MG");
1112                theIn2.getIn215_MilitaryRankGrade()
1113                                .getExtraComponents()
1114                                .getComponent(0)
1115                                .getData()
1116                                .parse("O8 MAJ GENERAL");
1117                theIn2.getIn215_MilitaryRankGrade()
1118                                .getExtraComponents()
1119                                .getComponent(1)
1120                                .getData()
1121                                .parse("urn:test:source:militaryrank");
1122                theIn2.getIn215_MilitaryRankGrade()
1123                                .getExtraComponents()
1124                                .getComponent(2)
1125                                .getData()
1126                                .parse("http://acme.org/fhir/StructureDefinition/patient-military-information");
1127                theIn2.getIn215_MilitaryRankGrade()
1128                                .getExtraComponents()
1129                                .getComponent(3)
1130                                .getData()
1131                                .parse("http://acme.org/fhir/StructureDefinition/patient-military-information/military-rank");
1132
1133                theIn2.getIn216_MilitaryStatus().setValue("R");
1134                theIn2.getIn216_MilitaryStatus()
1135                                .getExtraComponents()
1136                                .getComponent(0)
1137                                .getData()
1138                                .parse("RETIRED");
1139                theIn2.getIn216_MilitaryStatus()
1140                                .getExtraComponents()
1141                                .getComponent(1)
1142                                .getData()
1143                                .parse("urn:test:source:militarystatus");
1144                theIn2.getIn216_MilitaryStatus()
1145                                .getExtraComponents()
1146                                .getComponent(2)
1147                                .getData()
1148                                .parse("http://acme.org/fhir/StructureDefinition/patient-military-information");
1149                theIn2.getIn216_MilitaryStatus()
1150                                .getExtraComponents()
1151                                .getComponent(3)
1152                                .getData()
1153                                .parse("http://acme.org/fhir/StructureDefinition/patient-military-information/military-status");
1154        }
1155
1156        public void populateMsh(MSH theMsh, String messageType) throws HL7Exception {
1157                theMsh.getMsh1_FieldSeparator().setValue("|");
1158                theMsh.getMsh2_EncodingCharacters().setValue("^~\\&");
1159                theMsh.getMsh3_SendingApplication().getHd1_NamespaceID().setValue("http://acme.org/application");
1160                theMsh.getMsh3_SendingApplication().getHd2_UniversalID().setValue("ACME Application");
1161                theMsh.getMsh4_SendingFacility().getHd1_NamespaceID().setValue("http://acme.org/facility");
1162                theMsh.getMsh4_SendingFacility().getHd2_UniversalID().setValue("Acme Facility");
1163                theMsh.getMsh9_MessageType().parse(messageType);
1164                theMsh.getMsh10_MessageControlID().setValue("A001");
1165                theMsh.getMsh11_ProcessingID().parse("T");
1166                theMsh.getMsh12_VersionID().parse("2.5");
1167        }
1168
1169        public void populateNk1Employer(NK1 theNk1) throws HL7Exception {
1170                theNk1.getNk11_SetIDNK1().setValue("2");
1171
1172                XPN nk12 = theNk1.insertNk12_NKName(0);
1173                nk12.getXpn1_FamilyName().getFn1_Surname().setValue("Burns");
1174                nk12.getXpn2_GivenName().setValue("Charles");
1175                nk12.getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("Montgomery");
1176
1177                CE nk13 = theNk1.getNk13_Relationship();
1178                nk13.getCe1_Identifier().setValue("ECON");
1179                nk13.getCe2_Text().setValue("Employer");
1180                nk13.getCe3_NameOfCodingSystem().setValue(CodeSystemEnum.ROLE_CODE.getCodeSystemUri(ourContext));
1181
1182                XAD nk14 = theNk1.insertNk14_Address(0);
1183                nk14.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("999 Mammon Avenue");
1184                nk14.getXad3_City().setValue("Springfield");
1185                nk14.getXad4_StateOrProvince().setValue("MO");
1186                nk14.getXad5_ZipOrPostalCode().setValue("91656");
1187                nk14.getXad6_Country().setValue("USA");
1188                nk14.getXad7_AddressType().setValue("W");
1189
1190                XTN nk15 = theNk1.insertNk16_BusinessPhoneNumber(0);
1191                nk15.getXtn1_TelephoneNumber().setValue("(636)555-5678");
1192                nk15.getXtn2_TelecommunicationUseCode().setValue("WPN");
1193                nk15.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1194                nk15.getXtn6_AreaCityCode().setValue("636");
1195                nk15.getXtn7_LocalNumber().setValue("5555678");
1196
1197                CE nk17 = theNk1.getNk17_ContactRole();
1198                nk17.getCe1_Identifier().setValue("E");
1199                nk17.getCe2_Text().setValue("Employer");
1200                nk17.getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0131_R4);
1201
1202                theNk1.getNk115_AdministrativeSex().setValue("M");
1203
1204                XON nk113 = theNk1.insertOrganizationNameNK1(0);
1205                nk113.getXon1_OrganizationName().setValue("Springfield Nuclear Power Plant");
1206
1207                theNk1.getNk18_StartDate().setValue("201506");
1208
1209                CX nk133 = theNk1.insertNk133_NextOfKinAssociatedPartySIdentifiers(0);
1210                nk133.getCx1_IDNumber().setValue("0123456789");
1211                nk133.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/organization");
1212        }
1213
1214        public void populateNk1NextOfKin(NK1 theNk1) throws HL7Exception {
1215                theNk1.getNk11_SetIDNK1().setValue("1");
1216
1217                XPN nk12 = theNk1.insertNk12_NKName(0);
1218                nk12.getXpn1_FamilyName().getFn1_Surname().setValue("Simpson");
1219                nk12.getXpn2_GivenName().setValue("Marjorie");
1220                nk12.getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("Marge");
1221
1222                CE nk13 = theNk1.getNk13_Relationship();
1223                nk13.getCe1_Identifier().setValue("MTH");
1224                nk13.getCe2_Text().setValue("Mother");
1225                nk13.getCe3_NameOfCodingSystem().setValue(CodeSystemEnum.ROLE_CODE.getCodeSystemUri(ourContext));
1226
1227                XAD nk14 = theNk1.insertNk14_Address(0);
1228                nk14.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("742 Evergreen Terrace");
1229                nk14.getXad3_City().setValue("Springfield");
1230                nk14.getXad4_StateOrProvince().setValue("MO");
1231                nk14.getXad5_ZipOrPostalCode().setValue("65619");
1232                nk14.getXad6_Country().setValue("USA");
1233                nk14.getXad7_AddressType().setValue("H");
1234
1235                XTN nk15 = theNk1.insertNk15_PhoneNumber(0);
1236                nk15.getXtn1_TelephoneNumber().setValue("(636)555-1234");
1237                nk15.getXtn2_TelecommunicationUseCode().setValue("PRN");
1238                nk15.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1239                nk15.getXtn6_AreaCityCode().setValue("636");
1240                nk15.getXtn7_LocalNumber().setValue("5551234");
1241
1242                CE nk17 = theNk1.getNk17_ContactRole();
1243                nk17.getCe1_Identifier().setValue("N");
1244                nk17.getCe2_Text().setValue("Next-of-Kin");
1245                nk17.getCe3_NameOfCodingSystem().setValue(PublicApiConstants.TABLE_0131_R4);
1246
1247                theNk1.getNk18_StartDate().setValue("2011");
1248                theNk1.getNk19_EndDate().setValue("20120102");
1249
1250                theNk1.getNk110_NextOfKinAssociatedPartiesJobTitle().setValue("Clown");
1251                theNk1.getNk114_MaritalStatus().getCe1_Identifier().setValue("I");
1252
1253                theNk1.getNk115_AdministrativeSex().setValue("F");
1254                theNk1.getNk116_DateTimeOfBirth().parse("20210101121212-0000");
1255                theNk1.getNk129_ContactReason(0).parse("EMER^Emergency^http://contact-reasons");
1256                theNk1.getNk130_ContactPersonSName(0)
1257                                .getXpn1_FamilyName()
1258                                .getFn1_Surname()
1259                                .setValue("Alt Family Name");
1260
1261                theNk1.getNk113_OrganizationNameNK1(0).getXon1_OrganizationName().setValue("Org Name");
1262                theNk1.getNk133_NextOfKinAssociatedPartySIdentifiers(0)
1263                                .getCx1_IDNumber()
1264                                .setValue("12345");
1265                theNk1.getNk133_NextOfKinAssociatedPartySIdentifiers(0)
1266                                .getCx4_AssigningAuthority()
1267                                .getHd1_NamespaceID()
1268                                .setValue("http://ids");
1269        }
1270
1271        public void populateObxAssessmentHeight(Message theMessage, OBX theObx) throws DataTypeException {
1272                theObx.getObx2_ValueType().setValue("NM");
1273                theObx.getObx3_ObservationIdentifier().getCe1_Identifier().setValue(PublicApiConstants.CODE_LOINC_BODY_HEIGHT);
1274                theObx.getObx3_ObservationIdentifier().getCe2_Text().setValue(PublicApiConstants.CODE_LOINC_BODY_HEIGHT_TEXT);
1275                theObx.getObx3_ObservationIdentifier()
1276                                .getCe3_NameOfCodingSystem()
1277                                .setValue(PublicApiConstants.CODE_SYSTEM_LOINC);
1278                NM obxHtNm = new NM(theMessage);
1279                obxHtNm.setValue("51");
1280                theObx.getObx5_ObservationValue(0).setData(obxHtNm);
1281                theObx.getObx6_Units().getCe1_Identifier().setValue("cm");
1282                theObx.getObx6_Units().getCe2_Text().setValue("cm");
1283                theObx.getObx6_Units().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.CODE_SYSTEM_UCUM);
1284                theObx.getObx11_ObservationResultStatus().setValue("F");
1285                theObx.getObx14_DateTimeOfTheObservation().getTs1_Time().setValue("201109031113-0400");
1286        }
1287
1288        public void populateObxAssessmentWeight(Message a01, OBX theObx) throws DataTypeException {
1289                theObx.getObx2_ValueType().setValue("NM");
1290                theObx.getObx3_ObservationIdentifier().getCe1_Identifier().setValue(PublicApiConstants.CODE_LOINC_BODY_WEIGHT);
1291                theObx.getObx3_ObservationIdentifier().getCe2_Text().setValue(PublicApiConstants.CODE_LOINC_BODY_WEIGHT_TEXT);
1292                theObx.getObx3_ObservationIdentifier()
1293                                .getCe3_NameOfCodingSystem()
1294                                .setValue(PublicApiConstants.CODE_SYSTEM_LOINC);
1295                NM obxWtNm = new NM(a01);
1296                obxWtNm.setValue("123.4");
1297                theObx.getObx5_ObservationValue(0).setData(obxWtNm);
1298                theObx.getObx6_Units().getCe1_Identifier().setValue("kg");
1299                theObx.getObx6_Units().getCe2_Text().setValue("kg");
1300                theObx.getObx6_Units().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.CODE_SYSTEM_UCUM);
1301                theObx.getObx11_ObservationResultStatus().setValue("F");
1302                theObx.getObx14_DateTimeOfTheObservation().getTs1_Time().setValue("201109031113-0400");
1303        }
1304
1305        public void populateOrcForMedication(
1306                        ORC theOrc, String theOrderControl, boolean thePopulateOrc2, boolean thePopulateOrc3) throws HL7Exception {
1307                theOrc.getOrc1_OrderControl().setValue(theOrderControl);
1308                if (thePopulateOrc2) {
1309                        theOrc.getOrc2_PlacerOrderNumber().getEi1_EntityIdentifier().setValue("0001");
1310                        theOrc.getOrc2_PlacerOrderNumber().getEi2_NamespaceID().setValue("http://acme.org/medorders");
1311                }
1312                if (thePopulateOrc3) {
1313                        theOrc.getOrc3_FillerOrderNumber().getEi1_EntityIdentifier().setValue("0002");
1314                        theOrc.getOrc3_FillerOrderNumber().getEi2_NamespaceID().setValue("http://acme.org/medorders");
1315                }
1316
1317                TQ orc7 = theOrc.insertOrc7_QuantityTiming(0);
1318                orc7.getTq4_StartDateTime().getTs1_Time().setValue("201701021110-0500");
1319
1320                theOrc.getOrc9_DateTimeOfTransaction().getTs1_Time().setValue("201701021110-0500");
1321
1322                XCN orc12 = theOrc.insertOrc12_OrderingProvider(0);
1323                populateXcn(orc12);
1324        }
1325
1326        public void populatePid(PID thePid) throws HL7Exception {
1327                populatePid(thePid, true);
1328        }
1329
1330        public void populatePid(PID thePid, boolean theValid) throws HL7Exception {
1331                CX pid3 = thePid.insertPid3_PatientIdentifierList(0);
1332                pid3.getCx1_IDNumber().setValue("7000135");
1333
1334                // If we're creating an invalid message, we'll skip all the mandatory bits of PID-3, since this is a
1335                // pretty common screwup
1336                if (theValid) {
1337                        pid3.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/mrns");
1338                        pid3.getCx5_IdentifierTypeCode().setValue("MR");
1339                        pid3 = thePid.insertPid3_PatientIdentifierList(1);
1340                        pid3.getCx1_IDNumber().setValue("01238638267");
1341                        pid3.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/secondaryIds");
1342                        pid3.getCx5_IdentifierTypeCode().setValue("SB");
1343                }
1344                XPN pid5 = thePid.insertPid5_PatientName(0);
1345                pid5.getXpn1_FamilyName().getFn1_Surname().setValue("Smith");
1346                pid5.getXpn2_GivenName().setValue("John");
1347                pid5.getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("Q");
1348                pid5.getXpn4_SuffixEgJRorIII().setValue("Jr");
1349                pid5.getXpn7_NameTypeCode().setValue("L");
1350
1351                XPN pid6 = thePid.insertPid6_MotherSMaidenName(0);
1352                pid6.getXpn1_FamilyName().getFn1_Surname().setValue("Smythe");
1353                pid6.getXpn2_GivenName().setValue("Jane");
1354                pid6.getXpn3_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("K");
1355                pid6.getXpn4_SuffixEgJRorIII().setValue("Sr");
1356                pid6.getXpn7_NameTypeCode().setValue("D");
1357
1358                thePid.getPid7_DateTimeOfBirth().getTs1_Time().setValue("19650322");
1359
1360                thePid.getPid8_AdministrativeSex().setValue("M");
1361
1362                CE pid10 = thePid.getPid10_Race(0);
1363                pid10.getCe1_Identifier().setValue("2028-9");
1364                pid10.getCe2_Text().setValue("Asian");
1365                pid10.getCe3_NameOfCodingSystem().setValue("urn:oid:2.16.840.1.113883.6.238");
1366                pid10.getExtraComponents()
1367                                .getComponent(0)
1368                                .getData()
1369                                .parse("http://hl7.org/fhir/us/core/StructureDefinition/us-core-race");
1370                pid10.getExtraComponents().getComponent(1).getData().parse("ombCategory");
1371
1372                XAD pid11 = thePid.insertPid11_PatientAddress(0);
1373                pid11.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("342 Evergreen Terrace");
1374                pid11.getXad2_OtherDesignation().setValue("2nd Floor");
1375                pid11.getXad3_City().setValue("Springfield");
1376                pid11.getXad4_StateOrProvince().setValue("NI");
1377                pid11.getXad5_ZipOrPostalCode().setValue("12345");
1378                pid11.getXad6_Country().setValue("USA");
1379                pid11.getXad7_AddressType().setValue("H");
1380
1381                XTN pid13 = thePid.insertPid13_PhoneNumberHome(0);
1382                pid13.getXtn1_TelephoneNumber().setValue("1(333)555-1234");
1383                pid13.getXtn2_TelecommunicationUseCode().setValue("PRN");
1384                pid13.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1385
1386                thePid.getPid15_PrimaryLanguage().parse("EN^English^http://languages");
1387
1388                CE pid16 = thePid.getPid16_MaritalStatus();
1389                pid16.getCe1_Identifier().setValue("I");
1390
1391                CE pid17 = thePid.getPid17_Religion();
1392                pid17.getCe1_Identifier().setValue("AGNOSTIC");
1393                pid17.getCe2_Text().setValue("Agnostic");
1394                pid17.getCe3_NameOfCodingSystem().setValue("urn:test:source:religion");
1395                pid17.getExtraComponents()
1396                                .getComponent(0)
1397                                .getData()
1398                                .parse("http://hl7.org/fhir/StructureDefinition/patient-religion");
1399
1400                CX pid18 = thePid.getPid18_PatientAccountNumber();
1401                pid18.getCx1_IDNumber().setValue("123456789");
1402                pid18.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/patientAccountNumbers");
1403                pid18.getCx5_IdentifierTypeCode().setValue("AN");
1404
1405                CE pid22 = thePid.getPid22_EthnicGroup(0);
1406                pid22.getCe1_Identifier().setValue("2135-2");
1407                pid22.getCe2_Text().setValue("Hispanic or Latino");
1408                pid22.getCe3_NameOfCodingSystem().setValue("urn:oid:2.16.840.1.113883.6.238");
1409                pid22.getExtraComponents()
1410                                .getComponent(0)
1411                                .getData()
1412                                .parse("http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity");
1413                pid22.getExtraComponents().getComponent(1).getData().parse("ombCategory");
1414
1415                // Adding multiple PID-26
1416                CE pid26_1 = thePid.getPid26_Citizenship(0);
1417                pid26_1.getCe1_Identifier().setValue("1");
1418                pid26_1.getCe2_Text().setValue("CA");
1419                pid26_1.getCe3_NameOfCodingSystem().setValue("urn:test:source:citizenship");
1420                CE pid26_2 = thePid.getPid26_Citizenship(1);
1421                pid26_2.getCe1_Identifier().setValue("2");
1422                pid26_2.getCe2_Text().setValue("US");
1423                pid26_2.getCe3_NameOfCodingSystem().setValue("urn:test:source:citizenship");
1424
1425                CE pid27 = thePid.getPid27_VeteransMilitaryStatus();
1426                pid27.getCe1_Identifier().setValue("N");
1427                pid27.getCe2_Text().setValue("Not a Veteran");
1428                pid27.getCe3_NameOfCodingSystem().setValue("urn:test:source:vetstatus");
1429                pid27.getExtraComponents()
1430                                .getComponent(0)
1431                                .getData()
1432                                .parse("http://acme.org/fhir/StructureDefinition/patient-military-information");
1433                pid27.getExtraComponents()
1434                                .getComponent(1)
1435                                .getData()
1436                                .parse("http://acme.org/fhir/StructureDefinition/patient-military-information/vet-status");
1437
1438                CE pid28 = thePid.getPid28_Nationality();
1439                pid28.getCe1_Identifier().setValue("1");
1440                pid28.getCe2_Text().setValue("Canadian");
1441                pid28.getCe3_NameOfCodingSystem().setValue("urn:test:source:nationality");
1442
1443                thePid.getPid30_PatientDeathIndicator().setValue("N");
1444        }
1445
1446        private void populateMrg(MRG theMrg) throws HL7Exception {
1447                CX mrg1 = theMrg.insertPriorPatientIdentifierList(0);
1448                mrg1.getCx1_IDNumber().setValue("7000135");
1449                mrg1.getCx4_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/mrns");
1450                mrg1.getCx5_IdentifierTypeCode().setValue("MR");
1451        }
1452
1453        public void populatePr1First(PR1 thePr1) throws DataTypeException {
1454                thePr1.getPr11_SetIDPR1().setValue("1");
1455                thePr1.getPr13_ProcedureCode().getCe1_Identifier().setValue("2W53XYZ");
1456                thePr1.getPr13_ProcedureCode().getCe2_Text().setValue("Removal of Other Device on Abdominal Wall");
1457                thePr1.getPr13_ProcedureCode()
1458                                .getCe3_NameOfCodingSystem()
1459                                .setValue(CodeSystemEnum.PCS.getCodeSystemUri(ourContext));
1460                thePr1.getPr14_ProcedureDescription().setValue("Face Transplant");
1461                thePr1.getPr15_ProcedureDateTime().getTs1_Time().setValue("20010101070000-0400");
1462                thePr1.getPr16_ProcedureFunctionalType().setValue("D");
1463                thePr1.getPr119_ProcedureIdentifier().getEi1_EntityIdentifier().setValue("0000000042");
1464                thePr1.getPr119_ProcedureIdentifier().getEi2_NamespaceID().setValue("http://acme.org/procedure-identifiers");
1465        }
1466
1467        public void populatePr1Second(PR1 thePr1) throws DataTypeException {
1468                thePr1.getPr11_SetIDPR1().setValue("2");
1469                thePr1.getPr13_ProcedureCode().getCe1_Identifier().setValue("02HV33Z");
1470                thePr1.getPr13_ProcedureCode()
1471                                .getCe2_Text()
1472                                .setValue("Insertion of Infusion Device into Superior Vena Cava, Percutaneous Approach");
1473                thePr1.getPr13_ProcedureCode()
1474                                .getCe3_NameOfCodingSystem()
1475                                .setValue(CodeSystemEnum.PCS.getCodeSystemUri(ourContext));
1476                thePr1.getPr15_ProcedureDateTime().getTs1_Time().setValue("20010101070000-0400");
1477                thePr1.getPr119_ProcedureIdentifier().getEi1_EntityIdentifier().setValue("0000000042");
1478                thePr1.getPr119_ProcedureIdentifier().getEi2_NamespaceID().setValue("http://acme.org/procedure-identifiers");
1479        }
1480
1481        public void populatePv1(PV1 thePv1) throws HL7Exception {
1482                thePv1.getPv12_PatientClass().setValue("I");
1483                thePv1.getPv13_AssignedPatientLocation().getPl1_PointOfCare().setValue("Acme Hospital");
1484                thePv1.getPv13_AssignedPatientLocation().getPl2_Room().setValue("3rd Floor Room 124");
1485                thePv1.getPv13_AssignedPatientLocation().getPl3_Bed().setValue("6");
1486                thePv1.getPv13_AssignedPatientLocation()
1487                                .getPl4_Facility()
1488                                .getHd1_NamespaceID()
1489                                .setValue("Acme Facility");
1490                thePv1.getPv13_AssignedPatientLocation().getPl9_LocationDescription().setValue("The Acme Hospital");
1491                thePv1.getPv13_AssignedPatientLocation()
1492                                .getPl10_ComprehensiveLocationIdentifier()
1493                                .getEi1_EntityIdentifier()
1494                                .setValue("Acme H");
1495                thePv1.getPv13_AssignedPatientLocation()
1496                                .getPl10_ComprehensiveLocationIdentifier()
1497                                .getEi2_NamespaceID()
1498                                .setValue("http://acme.org/wards");
1499                thePv1.getPv13_AssignedPatientLocation()
1500                                .getExtraComponents()
1501                                .getComponent(0)
1502                                .getData()
1503                                .parse("http://acme.org/facility");
1504                thePv1.getPv13_AssignedPatientLocation()
1505                                .getExtraComponents()
1506                                .getComponent(1)
1507                                .getData()
1508                                .parse("Room 124, 3rd Floor");
1509                thePv1.getPv13_AssignedPatientLocation()
1510                                .getExtraComponents()
1511                                .getComponent(2)
1512                                .getData()
1513                                .parse("124-3");
1514                thePv1.getPv13_AssignedPatientLocation()
1515                                .getExtraComponents()
1516                                .getComponent(3)
1517                                .getData()
1518                                .parse("http://acme.org/rooms");
1519                thePv1.getPv13_AssignedPatientLocation()
1520                                .getExtraComponents()
1521                                .getComponent(4)
1522                                .getData()
1523                                .parse("Bed 6");
1524                thePv1.getPv13_AssignedPatientLocation()
1525                                .getExtraComponents()
1526                                .getComponent(5)
1527                                .getData()
1528                                .parse("B 6");
1529                thePv1.getPv13_AssignedPatientLocation()
1530                                .getExtraComponents()
1531                                .getComponent(6)
1532                                .getData()
1533                                .parse("http://acme.org/beds");
1534                thePv1.getPv14_AdmissionType().setValue("E");
1535                thePv1.getPv115_AmbulatoryStatus(0).setValue("A1");
1536
1537                populateXcn(thePv1.getPv17_AttendingDoctor(0));
1538                thePv1.getPv110_HospitalService().setValue("1");
1539                addExtraComponent(thePv1.getPv110_HospitalService(), 0, "Adoption/Permanent Care Info/Support");
1540                addExtraComponent(
1541                                thePv1.getPv110_HospitalService(), 1, CodeSystemEnum.SERVICE_TYPE.getCodeSystemUri(ourContext));
1542
1543                thePv1.getPv114_AdmitSource().setValue("emd");
1544                thePv1.getPv114_AdmitSource()
1545                                .getExtraComponents()
1546                                .getComponent(0)
1547                                .getData()
1548                                .parse("From accident/emergency department");
1549                thePv1.getPv114_AdmitSource()
1550                                .getExtraComponents()
1551                                .getComponent(1)
1552                                .getData()
1553                                .parse(CodeSystemEnum.ADMIT_SOURCE.getCodeSystemUri(ourContext));
1554                thePv1.getPv110_HospitalService().setValue("1");
1555                thePv1.getPv118_PatientType().setValue("QQ");
1556                thePv1.getPv119_VisitNumber().getCx1_IDNumber().setValue("4736455");
1557                thePv1.getPv119_VisitNumber()
1558                                .getCx4_AssigningAuthority()
1559                                .getHd1_NamespaceID()
1560                                .setValue("http://acme.org/visitNumbers");
1561                thePv1.getPv119_VisitNumber().getCx5_IdentifierTypeCode().setValue("VN");
1562                thePv1.getPv120_FinancialClass(0).getFc1_FinancialClassCode().setValue("FC1");
1563                thePv1.getPv120_FinancialClass(0).getFc2_EffectiveDate().getTs1_Time().setValue("20210202121212-0000");
1564                thePv1.getPv124_ContractCode(0).setValue("CC1");
1565                thePv1.getPv136_DischargeDisposition().setValue("home");
1566                thePv1.getPv136_DischargeDisposition()
1567                                .getExtraComponents()
1568                                .getComponent(0)
1569                                .getData()
1570                                .parse("Home");
1571                thePv1.getPv136_DischargeDisposition()
1572                                .getExtraComponents()
1573                                .getComponent(1)
1574                                .getData()
1575                                .parse(CodeSystemEnum.DISCHARGE_DISPOSITION.getCodeSystemUri(ourContext));
1576                thePv1.getPv139_ServicingFacility().setValue("Acme Facility");
1577                thePv1.getPv139_ServicingFacility()
1578                                .getExtraComponents()
1579                                .getComponent(0)
1580                                .getData()
1581                                .parse("http://acme.org/facility");
1582                thePv1.getPv141_AccountStatus().setValue("active");
1583                thePv1.getPv144_AdmitDateTime().getTime().setValue("20160122094430-0400");
1584                thePv1.insertPv145_DischargeDateTime(0).getTime().setValue("20160122094431-0400");
1585        }
1586
1587        public void populatePv2(PV2 thePv2) throws HL7Exception {
1588                thePv2.getPv22_AccommodationCode().getCe1_Identifier().setValue("wheel");
1589                thePv2.getPv22_AccommodationCode().getCe2_Text().setValue("Wheelchair");
1590                thePv2.getPv22_AccommodationCode()
1591                                .getCe3_NameOfCodingSystem()
1592                                .setValue("http://terminology.hl7.org/CodeSystem/encounter-special-arrangements");
1593
1594                thePv2.getPv23_AdmitReason().getCe1_Identifier().setValue("109006");
1595                thePv2.getPv23_AdmitReason().getCe2_Text().setValue("Anxiety disorder of childhood OR adolescence");
1596                thePv2.getPv23_AdmitReason().getCe3_NameOfCodingSystem().setValue("http://snomed.info/sct");
1597
1598                thePv2.getPv24_TransferReason().getCe1_Identifier().setValue("TR");
1599                thePv2.getPv24_TransferReason().getCe2_Text().setValue("Transfer Reasons");
1600                thePv2.getPv24_TransferReason().getCe3_NameOfCodingSystem().setValue("http://transfer-reasons");
1601
1602                thePv2.getPv28_ExpectedAdmitDateTime().getTs1_Time().setValue("20210203040506-0200");
1603                thePv2.getPv29_ExpectedDischargeDateTime().getTs1_Time().setValue("20210605040302-0200");
1604
1605                thePv2.getPv226_PreviousTreatmentDate().setValue("20190203");
1606                thePv2.getPv227_ExpectedDischargeDisposition().parse("DD^Discharge Disposition^http://discharge-dispositions");
1607        }
1608
1609        public void populateRolA(ROL theRol) throws HL7Exception {
1610                populateXcn(theRol.getRol4_RolePerson(0));
1611
1612                XAD rol11 = theRol.insertRol11_OfficeHomeAddressBirthplace(0);
1613                rol11.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("123 Brewer Street");
1614                rol11.getXad3_City().setValue("Buffalo");
1615                rol11.getXad4_StateOrProvince().setValue("NY");
1616                rol11.getXad5_ZipOrPostalCode().setValue("98765");
1617                rol11.getXad6_Country().setValue("USA");
1618                rol11.getXad7_AddressType().setValue("W");
1619
1620                XTN rol12 = theRol.insertRol12_Phone(0);
1621                rol12.getXtn1_TelephoneNumber().setValue("1(837)555-1978");
1622                rol12.getXtn2_TelecommunicationUseCode().setValue("WPN");
1623                rol12.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1624        }
1625
1626        public void populateRolB(ROL rol2) throws HL7Exception {
1627                rol2.getRol3_RoleROL().getCe1_Identifier().setValue("ADM");
1628                rol2.getRol3_RoleROL().getCe2_Text().setValue("admitter");
1629                rol2.getRol3_RoleROL().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.PARTICIPANTTYPE_URI);
1630                rol2.getRol4_RolePerson(0).getXcn1_IDNumber().setValue("3622");
1631                rol2.getRol4_RolePerson(0).getXcn2_FamilyName().getFn1_Surname().setValue("Hawkins");
1632                rol2.getRol4_RolePerson(0).getXcn3_GivenName().setValue("Finnie");
1633                rol2.getRol4_RolePerson(0)
1634                                .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
1635                                .setValue("Winnie Pooh");
1636                rol2.getRol4_RolePerson(0)
1637                                .getXcn9_AssigningAuthority()
1638                                .getHd1_NamespaceID()
1639                                .setValue("http://acme.org/clinicians");
1640                XAD rol11 = rol2.insertRol11_OfficeHomeAddressBirthplace(0);
1641                rol11.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("20 Canal St");
1642                rol11.getXad3_City().setValue("Buffalo");
1643                rol11.getXad4_StateOrProvince().setValue("NY");
1644                rol11.getXad5_ZipOrPostalCode().setValue("98222");
1645                rol11.getXad6_Country().setValue("USA");
1646                rol11.getXad7_AddressType().setValue("W");
1647
1648                XTN rol12 = rol2.insertRol12_Phone(0);
1649                rol12.getXtn1_TelephoneNumber().setValue("1(837)555-2133");
1650                rol12.getXtn2_TelecommunicationUseCode().setValue("WPN");
1651                rol12.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1652        }
1653
1654        public void populateRolC(ROL rol3) throws HL7Exception {
1655                XAD rol11;
1656                XTN rol12;
1657                rol3.getRol3_RoleROL().getCe1_Identifier().setValue("ATND");
1658                rol3.getRol3_RoleROL().getCe2_Text().setValue("attender");
1659                rol3.getRol3_RoleROL().getCe3_NameOfCodingSystem().setValue(PublicApiConstants.PARTICIPANTTYPE_URI);
1660                rol3.getRol4_RolePerson(0).getXcn1_IDNumber().setValue("7452");
1661                rol3.getRol4_RolePerson(0).getXcn2_FamilyName().getFn1_Surname().setValue("May");
1662                rol3.getRol4_RolePerson(0).getXcn3_GivenName().setValue("Sadie");
1663                rol3.getRol4_RolePerson(0)
1664                                .getXcn9_AssigningAuthority()
1665                                .getHd1_NamespaceID()
1666                                .setValue("http://acme.org/clinicians");
1667
1668                rol11 = rol3.insertRol11_OfficeHomeAddressBirthplace(0);
1669                rol11.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().setValue("313 Fleet Street");
1670                rol11.getXad3_City().setValue("Cheektowaga");
1671                rol11.getXad4_StateOrProvince().setValue("NY");
1672                rol11.getXad5_ZipOrPostalCode().setValue("28366");
1673                rol11.getXad6_Country().setValue("USA");
1674                rol11.getXad7_AddressType().setValue("W");
1675
1676                rol12 = rol3.insertRol12_Phone(0);
1677                rol12.getXtn1_TelephoneNumber().setValue("1(837)555-6624");
1678                rol12.getXtn2_TelecommunicationUseCode().setValue("WPN");
1679                rol12.getXtn3_TelecommunicationEquipmentType().setValue("PH");
1680        }
1681
1682        public void populateRxe(RXE theRxe) throws HL7Exception {
1683                theRxe.getRxe1_QuantityTiming().parse("^2 times daily&0900,1800^^20160205101500-0400^20160714165258-0400^R^^");
1684                theRxe.getRxe2_GiveCode()
1685                                .parse("02713^morphine injection 2 mg^http://acme.org/drugs^^^^^^Mighty Morphine Powder Dangers");
1686                theRxe.getRxe3_GiveAmountMinimum().setValue("0.5");
1687                theRxe.getRxe4_GiveAmountMaximum().setValue("2");
1688                theRxe.getRxe5_GiveUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1689                theRxe.getRxe7_ProviderSAdministrationInstructions(0).parse("^Take with Food");
1690                theRxe.getRxe7_ProviderSAdministrationInstructions(1).parse("^Take at Night");
1691                theRxe.getRxe10_DispenseAmount().setValue("1.2");
1692                theRxe.getRxe11_DispenseUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1693                theRxe.getRxe23_GiveRateAmount().setValue("1.0");
1694                theRxe.getRxe24_GiveRateUnits().parse("mL/h^milliliter per hour^http://unitsofmeasure.org");
1695        }
1696
1697        public void populateRxr(RXR theRxr) throws HL7Exception {
1698                theRxr.getRxr1_Route().parse("6064005^Topical^http://snomed.info/sct");
1699                theRxr.getRxr2_AdministrationSite().parse("69536005^Head^http://snomed.info/sct");
1700        }
1701
1702        public void populateSch(SCH theSch) throws HL7Exception {
1703
1704                theSch.getSch1_PlacerAppointmentID().getEi1_EntityIdentifier().parse("1234");
1705                theSch.getSch1_PlacerAppointmentID().getEi2_NamespaceID().parse("http://acme.org/placer/321");
1706
1707                theSch.getSch2_FillerAppointmentID().getEi1_EntityIdentifier().parse("1235");
1708                theSch.getSch2_FillerAppointmentID().getEi2_NamespaceID().parse("http://acme.org/placer/322");
1709
1710                theSch.getSch3_OccurrenceNumber().setValue("1");
1711
1712                theSch.getSch6_EventReason().getCe1_Identifier().parse("22");
1713                theSch.getSch6_EventReason().getCe2_Text().parse("Hypnotherapy"); // Maps to "Hypnotherapy"
1714                // ^ User-defined table in v2 but specific serviceType in FHIR
1715
1716                theSch.getSch7_AppointmentReason().getCe1_Identifier().parse("ROUTINE");
1717                // ^ User-defined table in v2 but specific reasonCode in FHIR
1718
1719                theSch.getSch9_AppointmentDuration().setValue("30");
1720                theSch.getSch10_AppointmentDurationUnits().getCe1_Identifier().setValue("minutes");
1721                theSch.getSch11_AppointmentTimingQuantity(0)
1722                                .getTq4_StartDateTime()
1723                                .getTs1_Time()
1724                                .setValue("202104141300-0500");
1725                theSch.getSch11_AppointmentTimingQuantity(0)
1726                                .getTq5_EndDateTime()
1727                                .getTs1_Time()
1728                                .setValue("202104141330-0500");
1729
1730                // SCH-16
1731                theSch.getSch16_FillerContactPerson(0).getXcn1_IDNumber().setValue("2345");
1732                theSch.getSch16_FillerContactPerson(0)
1733                                .getXcn2_FamilyName()
1734                                .getFn1_Surname()
1735                                .setValue("Smith");
1736                theSch.getSch16_FillerContactPerson(0).getXcn3_GivenName().setValue("Jane");
1737                theSch.getSch16_FillerContactPerson(0)
1738                                .getXcn9_AssigningAuthority()
1739                                .getHd1_NamespaceID()
1740                                .setValue("http://acme.org");
1741
1742                theSch.getSch20_EnteredByPerson(0).getXcn1_IDNumber().setValue("3456");
1743                theSch.getSch20_EnteredByPerson(0).getXcn2_FamilyName().getFn1_Surname().setValue("Coltrane");
1744                theSch.getSch20_EnteredByPerson(0).getXcn3_GivenName().setValue("John");
1745                theSch.getSch20_EnteredByPerson(0)
1746                                .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
1747                                .setValue("William");
1748                theSch.getSch20_EnteredByPerson(0)
1749                                .getXcn9_AssigningAuthority()
1750                                .getHd1_NamespaceID()
1751                                .setValue("http://acme.org");
1752
1753                theSch.getSch25_FillerStatusCode().getCe1_Identifier().setValue("Booked");
1754                // ^ status (appointmentStatus) table in FHIR
1755        }
1756
1757        public void populateZxt(AbstractMessage theMsg) throws HL7Exception {
1758                /*
1759                 * Extensions on Patient
1760                 */
1761                // Patient.active with boolean
1762                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT"))).parse("ZXT||ST|true|Patient.active");
1763                // Patient.multipleBirthInteger with numeric
1764                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1765                                .parse("ZXT||NM|3|Patient.multipleBirthInteger");
1766                // Patient.extension with valueString
1767                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1768                                .parse("ZXT||ST|Golly!|Patient.extension('http://acme.org/extension1').valueString");
1769                // Patient.extension with nested extension with valueString
1770                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1771                                .parse(
1772                                                "ZXT||ST|Gee!|Patient.extension('http://acme.org/extension2').extension('http://acme.org/nestedExtension1').valueString");
1773                // Patient.extension with multiple nested extensions with valueString
1774                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1775                                .parse(
1776                                                "ZXT||ST|Whiz!|Patient.extension('http://acme.org/extension3').extension('http://acme.org/nestedExtension2').extension('http://acme.org/nestedExtension3').valueString");
1777
1778                /*
1779                 * Extensions on Encounter
1780                 */
1781                // Encounter.extension with valueString
1782                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1783                                .parse("ZXT||ST|Aces!|Encounter.extension('http://acme.org/extension4').valueString");
1784                // Encounter.class.extension with valueString
1785                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1786                                .parse(
1787                                                "ZXT||ST|Well, isn't that super?|Encounter.class.extension('http://acme.org/extension5').valueString");
1788                // Encounter.extension with valueCoding
1789                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1790                                .parse(
1791                                                "ZXT||CWE|CODE^This is a code.^http://acme.org/codes|Encounter.extension('http://acme.org/extension6').valueCoding");
1792                // Encounter.extension with valueCodeableConcept, 1st code
1793                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1794                                .parse(
1795                                                "ZXT||CWE|CODE1^This is a code1.^http://acme.org/codes|Encounter.extension('http://acme.org/extension7').valueCodeableConcept");
1796                // Encounter.extension with valueCodeableConcept, 2nd code
1797                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1798                                .parse(
1799                                                "ZXT||CWE|CODE2^This is a code2.^http://acme.org/codes|Encounter.extension('http://acme.org/extension7').valueCodeableConcept");
1800                // Encounter.extension with valueInteger
1801                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1802                                .parse("ZXT||NM|3|Encounter.extension('http://acme.org/extension8').valueInteger");
1803                // Encounter.extension with valueDecimal
1804                ((AbstractSegment) theMsg.get(theMsg.addNonstandardSegment("ZXT")))
1805                                .parse("ZXT||NM|3.3|Encounter.extension('http://acme.org/extension9').valueDecimal");
1806        }
1807
1808        public RAS_O17 createRasO17() throws HL7Exception {
1809                return createRasO17(false);
1810        }
1811
1812        public RAS_O17 createRasO17(boolean hasMultipleComponents) throws HL7Exception {
1813                return createRasO17(hasMultipleComponents, true, true, false);
1814        }
1815
1816        public RAS_O17 createRasO17(boolean hasMultipleComponents, boolean bothComponentsAreCoded) throws HL7Exception {
1817                return createRasO17(hasMultipleComponents, bothComponentsAreCoded, true, false);
1818        }
1819
1820        public RAS_O17 createRasO17(
1821                        boolean hasMultipleComponents,
1822                        boolean bothComponentsAreCoded,
1823                        boolean thePopulateOrc2,
1824                        boolean thePopulateOrc3)
1825                        throws HL7Exception {
1826                RAS_O17 ras = new RAS_O17();
1827                populateMsh(ras.getMSH(), "RAS^O17^RAS_O17");
1828                populatePid(ras.getPATIENT().getPID(), true);
1829                populatePv1(ras.getPATIENT().getPATIENT_VISIT().getPV1());
1830
1831                RAS_O17_ORDER order = ras.insertORDER(0);
1832                ORC orc = order.getORC();
1833                populateOrcForMedication(orc, "NW", thePopulateOrc2, thePopulateOrc3);
1834
1835                populateRxe(ras.getORDER().getENCODING().getRXE());
1836                populateRxr(ras.getORDER().getENCODING().getRXR());
1837
1838                RXC rxc = ras.getORDER().getENCODING().insertRXC(0);
1839                rxc.getRxc1_RXComponentType().setValue("A");
1840                rxc.getRxc2_ComponentCode().getCe1_Identifier().setValue("MEW");
1841                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Kittens");
1842                rxc.getRxc2_ComponentCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/cats");
1843                rxc.getRxc3_ComponentAmount().setValue("0.5");
1844                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1845
1846                if (hasMultipleComponents) {
1847                        if (bothComponentsAreCoded) {
1848                                rxc = ras.getORDER().getENCODING().insertRXC(1);
1849                                rxc.getRxc1_RXComponentType().setValue("B");
1850                                rxc.getRxc2_ComponentCode().getCe1_Identifier().setValue("WAF");
1851                                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Puppies");
1852                                rxc.getRxc2_ComponentCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/dogs");
1853                                rxc.getRxc3_ComponentAmount().setValue("0.3");
1854                                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1855                        } else {
1856                                rxc = ras.getORDER().getENCODING().insertRXC(1);
1857                                rxc.getRxc2_ComponentCode().getCe2_Text().setValue("Duckies");
1858                                rxc.getRxc3_ComponentAmount().setValue("0.2");
1859                                rxc.getRxc4_ComponentUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1860                        }
1861                }
1862
1863                RAS_O17_ADMINISTRATION admin = ras.getORDER().getADMINISTRATION();
1864
1865                RXA rxa = admin.insertRXA(0);
1866                rxa.getRxa2_AdministrationSubIDCounter().setValue("1");
1867                rxa.getRxa2_AdministrationSubIDCounter()
1868                                .getExtraComponents()
1869                                .getComponent(0)
1870                                .getData()
1871                                .parse("http://acme.org/medadmins");
1872                rxa.getRxa3_DateTimeStartOfAdministration().getTs1_Time().setValue("20171209071055-0500");
1873                rxa.getRxa4_DateTimeEndOfAdministration().getTs1_Time().setValue("20171209071100-0500");
1874                rxa.getRxa5_AdministeredCode().getCe1_Identifier().setValue("0001");
1875                rxa.getRxa5_AdministeredCode().getCe2_Text().setValue("Tylenol");
1876                rxa.getRxa5_AdministeredCode().getCe3_NameOfCodingSystem().setValue("http://acme.org/meds");
1877                rxa.getRxa6_AdministeredAmount().setValue("4");
1878                rxa.getRxa7_AdministeredUnits().parse("mg^milligrams^http://unitsofmeasure.org");
1879                rxa.getRxa9_AdministrationNotes(0).getCe2_Text().setValue("This is a note");
1880
1881                rxa.getRxa10_AdministeringProvider(0).getXcn1_IDNumber().setValue("825");
1882                rxa.getRxa10_AdministeringProvider(0)
1883                                .getXcn2_FamilyName()
1884                                .getFn1_Surname()
1885                                .setValue("Bouvier");
1886                rxa.getRxa10_AdministeringProvider(0).getXcn3_GivenName().setValue("Marge");
1887                rxa.getRxa10_AdministeringProvider(0)
1888                                .getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof()
1889                                .setValue("Q");
1890                rxa.getRxa10_AdministeringProvider(0)
1891                                .getXcn9_AssigningAuthority()
1892                                .getHd1_NamespaceID()
1893                                .setValue("http://acme.org/clinicians");
1894
1895                rxa.getRxa12_AdministeredPerTimeUnit().setValue("Day");
1896                rxa.getRxa20_CompletionStatus().setValue("CP");
1897
1898                populateRxr(admin.getRXR());
1899
1900                ((AbstractSegment) admin.get(admin.addNonstandardSegment("ZXC")))
1901                                .parse("ZXC|A|MEW^Kittens^http://acme.org/cats|0.5|mg^milligrams^http://unitsofmeasure.org");
1902
1903                if (hasMultipleComponents) {
1904                        if (bothComponentsAreCoded) {
1905                                ((AbstractSegment) admin.get(admin.addNonstandardSegment("ZXC")))
1906                                                .parse("ZXC|B|WAF^Puppies^http://acme.org/dogs|0.3|mg^milligrams^http://unitsofmeasure.org");
1907                        } else {
1908                                ((AbstractSegment) admin.get(admin.addNonstandardSegment("ZXC")))
1909                                                .parse("ZXC||^Duckies|0.2|mg^milligrams^http://unitsofmeasure.org");
1910                        }
1911                }
1912
1913                return ras;
1914        }
1915
1916        public QBP_Q21 createQbpQ21() throws HL7Exception {
1917                QBP_Q21 qbp = new QBP_Q21();
1918                populateMsh(qbp.getMSH(), "QBP^Q23^QBP");
1919                populateQpd(qbp.getQPD());
1920                qbp.getRCP().getRcp1_QueryPriority().setValue("I");
1921                return qbp;
1922        }
1923
1924        private void populateQpd(QPD theQpd) throws HL7Exception {
1925                // QPD-1: Message Query Name
1926                theQpd.getQpd1_MessageQueryName().getCe1_Identifier().setValue("IHE PIX Query");
1927
1928                // QPD-2: Query Tag
1929                theQpd.getQpd2_QueryTag().setValue("QRY1248968460880");
1930
1931                // QPD-3: Patient Identifier
1932                theQpd.getQpd3_UserParametersInsuccessivefields().parse("PD12345^^^PIF&1.2.840.114158.2012.11.01.1&ISO");
1933        }
1934
1935        public void populateXcn(XCN theXCN) throws DataTypeException {
1936                theXCN.getXcn1_IDNumber().setValue("777");
1937                theXCN.getXcn2_FamilyName().getFn1_Surname().setValue("Jones");
1938                theXCN.getXcn3_GivenName().setValue("Lisa");
1939                theXCN.getXcn4_SecondAndFurtherGivenNamesOrInitialsThereof().setValue("Frances Little Piglet");
1940                theXCN.getXcn5_SuffixEgJRorIII().setValue("Jr");
1941                theXCN.getXcn6_PrefixEgDR().setValue("DR");
1942                theXCN.getXcn7_DegreeEgMD().setValue("MD");
1943                theXCN.getXcn9_AssigningAuthority().getHd1_NamespaceID().setValue("http://acme.org/clinicians");
1944        }
1945}