1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.transform.subdisc;
|
---|
6 |
|
---|
7 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
8 | import org.hl7.v3.*;
|
---|
9 | import org.apache.commons.logging.Log;
|
---|
10 | import org.apache.commons.logging.LogFactory;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | *
|
---|
14 | * @author Jon Hoppesch
|
---|
15 | */
|
---|
16 | public class HL7AckTransforms {
|
---|
17 |
|
---|
18 | private static Log log = LogFactory.getLog(HL7AckTransforms.class);
|
---|
19 |
|
---|
20 | public static MCCIIN000002UV01 createAckMessage(String localDeviceId, II origMsgId, String msgText, String senderOID, String receiverOID) {
|
---|
21 | MCCIIN000002UV01 ackMsg = new MCCIIN000002UV01();
|
---|
22 |
|
---|
23 | // Validate input parameters
|
---|
24 | if (NullChecker.isNullish(senderOID)) {
|
---|
25 | log.error("Failed to specify a sender OID");
|
---|
26 | return null;
|
---|
27 | }
|
---|
28 |
|
---|
29 | if (NullChecker.isNullish(receiverOID)) {
|
---|
30 | log.error("Failed to specify a receiver OID");
|
---|
31 | return null;
|
---|
32 | }
|
---|
33 |
|
---|
34 | // Create the Ack message header fields
|
---|
35 | ackMsg.setITSVersion(HL7Constants.ITS_VERSION);
|
---|
36 | ackMsg.setId(HL7MessageIdGenerator.GenerateHL7MessageId(localDeviceId));
|
---|
37 | ackMsg.setCreationTime(HL7DataTransformHelper.CreationTimeFactory());
|
---|
38 | ackMsg.setInteractionId(HL7DataTransformHelper.IIFactory(HL7Constants.INTERACTION_ID_ROOT, "MCCIIN000002UV01"));
|
---|
39 | ackMsg.setProcessingCode(HL7DataTransformHelper.CSFactory("T"));
|
---|
40 | ackMsg.setProcessingModeCode(HL7DataTransformHelper.CSFactory("T"));
|
---|
41 | ackMsg.setAcceptAckCode(HL7DataTransformHelper.CSFactory("NE"));
|
---|
42 |
|
---|
43 | // Create the Sender
|
---|
44 | ackMsg.setSender(HL7SenderTransforms.createMCCIMT000200UV01Sender(senderOID));
|
---|
45 |
|
---|
46 | // Create the Receiver
|
---|
47 | ackMsg.getReceiver().add(HL7ReceiverTransforms.createMCCIMT000200UV01Receiver(receiverOID));
|
---|
48 |
|
---|
49 | // Create Acknowledgement section if an original message id or message text was specified
|
---|
50 | if (NullChecker.isNotNullish(msgText) ||
|
---|
51 | (origMsgId != null && NullChecker.isNotNullish(origMsgId.getRoot()) && NullChecker.isNotNullish(origMsgId.getExtension()))) {
|
---|
52 | log.debug("Adding Acknowledgement Section");
|
---|
53 | ackMsg.getAcknowledgement().add(createAcknowledgement(origMsgId, msgText));
|
---|
54 | }
|
---|
55 |
|
---|
56 | return ackMsg;
|
---|
57 | }
|
---|
58 |
|
---|
59 | public static MCCIMT000200UV01Acknowledgement createAcknowledgement(II msgId, String msgText) {
|
---|
60 | MCCIMT000200UV01Acknowledgement ack = new MCCIMT000200UV01Acknowledgement();
|
---|
61 |
|
---|
62 | ack.setTypeCode(HL7DataTransformHelper.CSFactory("CA"));
|
---|
63 |
|
---|
64 | if (msgId != null) {
|
---|
65 | ack.setTargetMessage(createTargetMessage(msgId));
|
---|
66 | }
|
---|
67 |
|
---|
68 | if (msgText != null) {
|
---|
69 | ack.getAcknowledgementDetail().add(createAckDetail(msgText));
|
---|
70 | }
|
---|
71 |
|
---|
72 | return ack;
|
---|
73 | }
|
---|
74 |
|
---|
75 | public static MCCIMT000200UV01TargetMessage createTargetMessage(II msgId) {
|
---|
76 | MCCIMT000200UV01TargetMessage targetMsg = new MCCIMT000200UV01TargetMessage();
|
---|
77 |
|
---|
78 | if (msgId != null) {
|
---|
79 | log.debug("Setting original message id, root: " + msgId.getRoot() + ", extension: " + msgId.getExtension());
|
---|
80 | targetMsg.setId(msgId);
|
---|
81 | }
|
---|
82 |
|
---|
83 | return targetMsg;
|
---|
84 | }
|
---|
85 |
|
---|
86 | public static MCCIMT000200UV01AcknowledgementDetail createAckDetail(String msgText) {
|
---|
87 | MCCIMT000200UV01AcknowledgementDetail ackDetail = new MCCIMT000200UV01AcknowledgementDetail();
|
---|
88 |
|
---|
89 |
|
---|
90 | if (NullChecker.isNotNullish(msgText)) {
|
---|
91 | // Set the acknowledge message text
|
---|
92 | EDExplicit msg = new EDExplicit();
|
---|
93 |
|
---|
94 | log.debug("Setting ack message text: " + msgText);
|
---|
95 | msg.getContent().add(msgText);
|
---|
96 | ackDetail.setText(msg);
|
---|
97 | }
|
---|
98 | return ackDetail;
|
---|
99 | }
|
---|
100 | }
|
---|