[507] | 1 | /*
|
---|
| 2 | * To change this template, choose Tools | Templates
|
---|
| 3 | * and open the template in the editor.
|
---|
| 4 | */
|
---|
| 5 | package gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte;
|
---|
| 6 |
|
---|
| 7 | import gov.hhs.fha.nhinc.common.nhinccommon.QualifiedSubjectIdentifierType;
|
---|
| 8 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.*;
|
---|
| 9 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.CSHelper;
|
---|
| 10 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.Configuration;
|
---|
| 11 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.CreationTimeHelper;
|
---|
| 12 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.IIHelper;
|
---|
| 13 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.InteractionIdHelper;
|
---|
| 14 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.SenderReceiverHelper;
|
---|
| 15 | import gov.hhs.fha.nhinc.common.patientcorrelationfacade.dte.helpers.UniqueIdHelper;
|
---|
| 16 | import java.util.List;
|
---|
| 17 | import javax.xml.bind.JAXBElement;
|
---|
| 18 | import javax.xml.namespace.QName;
|
---|
| 19 | import org.hl7.v3.*;
|
---|
| 20 | import java.util.Calendar;
|
---|
| 21 | import java.text.SimpleDateFormat;
|
---|
| 22 | import java.util.Date;
|
---|
| 23 |
|
---|
| 24 | /**
|
---|
| 25 | *
|
---|
| 26 | * @author rayj
|
---|
| 27 | */
|
---|
| 28 | public class PixAddBuilder {
|
---|
| 29 |
|
---|
| 30 | private static final String AcceptAckCodeValue = "AL";
|
---|
| 31 | private static final String ITSVersion = "XML_1.0";
|
---|
| 32 | private static final String InteractionIdExtension = "PRPA_IN201301UV";
|
---|
| 33 | private static final String MoodCodeValue = "EVN";
|
---|
| 34 | private static final String PatientClassCode = "PAT";
|
---|
| 35 | private static final String PatientStatusCode = "active";
|
---|
| 36 | private static final String ProcessingCodeValue = "P";
|
---|
| 37 | private static final String ProcessingModeCode = "T";
|
---|
| 38 | private static final String SubjectTypeCode = "SUBJ";
|
---|
| 39 | private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(PixAddBuilder.class);
|
---|
| 40 |
|
---|
| 41 | public static CreatePixAddResponseType createPixAdd(CreatePixAddRequestType createPixAddRequest) {
|
---|
| 42 | CreatePixAddResponseType createPixAddResponse = new CreatePixAddResponseType();
|
---|
| 43 | createPixAddResponse.setPRPAIN201301UV(createPixAdd(createPixAddRequest.getAddPatientCorrelationRequest()));
|
---|
| 44 | return createPixAddResponse;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public static PRPAIN201301UV createPixAdd(AddPatientCorrelationRequestType addPatientCorrelationRequest) {
|
---|
| 48 | log.info("begin createPixAdd");
|
---|
| 49 | PRPAIN201301UV message = null;
|
---|
| 50 |
|
---|
| 51 | List<QualifiedSubjectIdentifierType> qualifiedIds = addPatientCorrelationRequest.getQualifiedPatientIdentifier();
|
---|
| 52 | log.info("qualifiedIds is null? -> " + (qualifiedIds == null));
|
---|
| 53 | log.info("qualifiedIds.size()=" + (qualifiedIds.size()));
|
---|
| 54 |
|
---|
| 55 | message = createTransmissionWrapper(Configuration.getMyCommunityId(), null);
|
---|
| 56 | message.setControlActProcess(buildControlActProcess(qualifiedIds));
|
---|
| 57 |
|
---|
| 58 | log.info("end createPixAdd");
|
---|
| 59 | return message;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | private static PRPAIN201301UV createTransmissionWrapper(String senderId, String receiverId) {
|
---|
| 63 | PRPAIN201301UV message = new PRPAIN201301UV();
|
---|
| 64 |
|
---|
| 65 | message.setITSVersion(ITSVersion);
|
---|
| 66 | message.setId(UniqueIdHelper.createUniqueId());
|
---|
| 67 | message.setCreationTime(CreationTimeHelper.getCreationTime());
|
---|
| 68 | message.setInteractionId(InteractionIdHelper.createInteractionId(InteractionIdExtension));
|
---|
| 69 |
|
---|
| 70 | message.setProcessingCode(CSHelper.buildCS(ProcessingCodeValue));
|
---|
| 71 | message.setProcessingModeCode(CSHelper.buildCS(ProcessingModeCode));
|
---|
| 72 | message.setAcceptAckCode(CSHelper.buildCS(AcceptAckCodeValue));
|
---|
| 73 |
|
---|
| 74 | message.getReceiver().add(SenderReceiverHelper.CreateReceiver(receiverId));
|
---|
| 75 | message.setSender(SenderReceiverHelper.CreateSender(senderId));
|
---|
| 76 |
|
---|
| 77 | return message;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | private static PRPAIN201301UVMFMIMT700701UV01ControlActProcess buildControlActProcess(List<QualifiedSubjectIdentifierType> qualifiedIds) {
|
---|
| 81 | log.info("begin buildControlActProcess");
|
---|
| 82 |
|
---|
| 83 | PRPAIN201301UVMFMIMT700701UV01ControlActProcess controlActProcess = new PRPAIN201301UVMFMIMT700701UV01ControlActProcess();
|
---|
| 84 | controlActProcess.setMoodCode(MoodCodeValue);
|
---|
| 85 |
|
---|
| 86 | PRPAIN201301UVMFMIMT700701UV01Subject1 subject = new PRPAIN201301UVMFMIMT700701UV01Subject1();
|
---|
| 87 | subject.getTypeCode().add(SubjectTypeCode);
|
---|
| 88 | PRPAIN201301UVMFMIMT700701UV01RegistrationEvent registrationEvent = buildRegistrationEvent(qualifiedIds);
|
---|
| 89 | subject.setRegistrationEvent(registrationEvent);
|
---|
| 90 |
|
---|
| 91 | controlActProcess.getSubject().add(subject);
|
---|
| 92 |
|
---|
| 93 | log.info("end buildControlActProcess");
|
---|
| 94 | log.info("controlActProcess.getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getId().size()=" + controlActProcess.getSubject().get(0).getRegistrationEvent().getSubject1().getPatient().getId().size());
|
---|
| 95 |
|
---|
| 96 | return controlActProcess;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | private static PRPAIN201301UVMFMIMT700701UV01RegistrationEvent buildRegistrationEvent(List<QualifiedSubjectIdentifierType> qualifiedIds) {
|
---|
| 100 | log.info("begin buildRegistrationEvent");
|
---|
| 101 |
|
---|
| 102 | PRPAIN201301UVMFMIMT700701UV01RegistrationEvent registrationEvent = new PRPAIN201301UVMFMIMT700701UV01RegistrationEvent();
|
---|
| 103 | registrationEvent.getId().add(IIHelper.IIFactoryCreateNull());
|
---|
| 104 | registrationEvent.setStatusCode(CSHelper.buildCS("active"));
|
---|
| 105 |
|
---|
| 106 | PRPAIN201301UVMFMIMT700701UV01Subject2 subject1 = new PRPAIN201301UVMFMIMT700701UV01Subject2();
|
---|
| 107 | PRPAMT201301UVPatient patient = new PRPAMT201301UVPatient();
|
---|
| 108 | patient.setClassCode(PatientClassCode);
|
---|
| 109 | patient.setStatusCode(CSHelper.buildCS(PatientStatusCode));
|
---|
| 110 |
|
---|
| 111 | log.info("adding qualifiedSubjectIdentifiers");
|
---|
| 112 | for (QualifiedSubjectIdentifierType qualifiedId : qualifiedIds) {
|
---|
| 113 | II ii = IIHelper.IIFactory(qualifiedId);
|
---|
| 114 | patient.getId().add(ii);
|
---|
| 115 | log.info("adding a qualifiedSubjectIdentifier");
|
---|
| 116 | }
|
---|
| 117 | log.info("patient.getId().size()=" + patient.getId().size());
|
---|
| 118 |
|
---|
| 119 | log.info("building patientPerson");
|
---|
| 120 | JAXBElement<PRPAMT201301UVPerson> patientPersonElement;
|
---|
| 121 | PRPAMT201301UVPerson patientPerson = new PRPAMT201301UVPerson();
|
---|
| 122 |
|
---|
| 123 | PNExplicit patientName = new PNExplicit();
|
---|
| 124 | patientName.getNullFlavor().add("NA");
|
---|
| 125 | patientPerson.getName().add(patientName);
|
---|
| 126 |
|
---|
| 127 | QName xmlqname = new QName("urn:hl7-org:v3", "patientPerson");
|
---|
| 128 | patientPersonElement = new JAXBElement<PRPAMT201301UVPerson>(xmlqname, PRPAMT201301UVPerson.class, patientPerson);
|
---|
| 129 |
|
---|
| 130 | patient.setPatientPerson(patientPersonElement);
|
---|
| 131 | subject1.setPatient(patient);
|
---|
| 132 | registrationEvent.setSubject1(subject1);
|
---|
| 133 |
|
---|
| 134 | log.info("end buildRegistrationEvent");
|
---|
| 135 | log.info("registrationEvent.getSubject1().getPatient().getId().size()=" + registrationEvent.getSubject1().getPatient().getId().size());
|
---|
| 136 |
|
---|
| 137 | return registrationEvent;
|
---|
| 138 | }
|
---|
| 139 | }
|
---|