From cd123a4b95d268b4cafdbc1b56471406f5d6aca6 Mon Sep 17 00:00:00 2001 From: Patrick LaRocque Date: Wed, 18 Sep 2024 09:54:41 -0400 Subject: [PATCH 1/2] Update NCPDP SCRIPT support to be a single end point --- .../{RxFillStatusBody.java => Body.java} | 17 +++++- .../org/hl7/codex/rems/script/Message.java | 21 ++++++- .../rems/script/NcpdpScriptController.java | 56 ++++++++++++++++--- .../org/hl7/codex/rems/script/RxFillBody.java | 15 ----- .../hl7/codex/rems/script/RxFillMessage.java | 26 --------- .../rems/script/RxFillStatusMessage.java | 36 ------------ 6 files changed, 82 insertions(+), 89 deletions(-) rename src/main/java/org/hl7/codex/rems/script/{RxFillStatusBody.java => Body.java} (50%) delete mode 100644 src/main/java/org/hl7/codex/rems/script/RxFillBody.java delete mode 100644 src/main/java/org/hl7/codex/rems/script/RxFillMessage.java delete mode 100644 src/main/java/org/hl7/codex/rems/script/RxFillStatusMessage.java diff --git a/src/main/java/org/hl7/codex/rems/script/RxFillStatusBody.java b/src/main/java/org/hl7/codex/rems/script/Body.java similarity index 50% rename from src/main/java/org/hl7/codex/rems/script/RxFillStatusBody.java rename to src/main/java/org/hl7/codex/rems/script/Body.java index 51d946b..67921b8 100644 --- a/src/main/java/org/hl7/codex/rems/script/RxFillStatusBody.java +++ b/src/main/java/org/hl7/codex/rems/script/Body.java @@ -1,10 +1,21 @@ package org.hl7.codex.rems.script; +import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlElement; -public class RxFillStatusBody { +@XmlRootElement(name="Body") +public class Body { + private RxFill rxFill; private Status status; + @XmlElement(name="RxFill") + public RxFill getRxFill() { + return rxFill; + } + public void setRxFill(RxFill rxFill) { + this.rxFill = rxFill; + } + @XmlElement(name="Status") public Status getStatus() { return status; @@ -13,11 +24,11 @@ public void setStatus(Status status) { this.status = status; } - public RxFillStatusBody() { + public Body() { this.status = null; } - public RxFillStatusBody(Status status) { + public Body(Status status) { this.status = status; } } diff --git a/src/main/java/org/hl7/codex/rems/script/Message.java b/src/main/java/org/hl7/codex/rems/script/Message.java index 56c9ce3..9842cdb 100644 --- a/src/main/java/org/hl7/codex/rems/script/Message.java +++ b/src/main/java/org/hl7/codex/rems/script/Message.java @@ -5,7 +5,18 @@ @XmlRootElement(name="Message") public class Message { - protected Header header; + private Header header; + private Body body; + + public Message() { + this.header = null; + this.body = null; + } + + public Message(Header header, Body body) { + this.header = header; + this.body = body; + } @XmlElement(name="Header") public Header getHeader() { @@ -14,4 +25,12 @@ public Header getHeader() { public void setHeader(Header header) { this.header = header; } + + @XmlElement(name="Body") + public Body getBody() { + return body; + } + public void setBody(Body body) { + this.body = body; + } } diff --git a/src/main/java/org/hl7/codex/rems/script/NcpdpScriptController.java b/src/main/java/org/hl7/codex/rems/script/NcpdpScriptController.java index b91bc3c..6191285 100644 --- a/src/main/java/org/hl7/codex/rems/script/NcpdpScriptController.java +++ b/src/main/java/org/hl7/codex/rems/script/NcpdpScriptController.java @@ -34,14 +34,35 @@ public class NcpdpScriptController { * @param payload - the object used to serialize the XML in the request body. * @return - an object containing the NCPDP Script Status to return. */ - @PostMapping(value = "/script/rxfill", produces = {APPLICATION_XML}, consumes = {APPLICATION_XML}) + @PostMapping(value = "/ncpdp/script", produces = {APPLICATION_XML}, consumes = {APPLICATION_XML}) @ResponseBody - public RxFillStatusMessage getScriptResponse(@RequestBody RxFillMessage payload) { - logger.info("NcpdpScriptController::getScriptResponse /script/rxfill"); + public Message handleScriptMessage(@RequestBody Message payload) { + logger.info("NcpdpScriptController::handleScriptMessage /ncpdp/script"); Header header = payload.getHeader(); - RxFillBody body = payload.getBody(); - FillStatus.DispensedStatusEnum dispensedStatus = body.getRxFill().getFillStatus().getStatus(); + Body body = payload.getBody(); + + if (body.getRxFill() != null) { + logger.info("NcpdpScriptController::handleScriptMessage RxFill Message"); + handleRxFillMessage(body.getRxFill(), header); + } else if (body.getStatus() != null) { + logger.info("NcpdpScriptController::handleScriptMessage Status Message"); + } else { + logger.info("NcpdpScriptController::handleScriptMessage Unsupported NCPDP SCRIPT Message"); + } + + // build the status to return + Header statusHeader = new Header(header.getFrom().value, header.getTo().value, + header.getMessageId(), header.getPrescriberOrderNumber()); + Status status = new Status("000", null, null, null); + Body statusBody = new Body(); + statusBody.setStatus(status); + Message statusMessage = new Message(statusHeader, statusBody); + return statusMessage; + } + + private void handleRxFillMessage(RxFill rxFill, Header header) { + FillStatus.DispensedStatusEnum dispensedStatus = rxFill.getFillStatus().getStatus(); logger.info(" PrescriberOrderNumber: " + header.getPrescriberOrderNumber()); logger.info(" Dispensed Status: " + dispensedStatus); @@ -86,16 +107,35 @@ public RxFillStatusMessage getScriptResponse(@RequestBody RxFillMessage payload) dispenseDetails.setRequestId(dispenseId); medicationDispenseDao.update(medicationDispense, dispenseDetails); logger.info(" Created new MedicationDispense: " + dispenseId); - } + } + } + + + /** + * A custom endpoint that handles NCPDP Script messages. + * @param payload - the object used to serialize the XML in the request body. + * @return - an object containing the NCPDP Script Status to return. + */ +/* + @PostMapping(value = "/script/rxfill", produces = {APPLICATION_XML}, consumes = {APPLICATION_XML}) + @ResponseBody + public StatusMessage getScriptResponse(@RequestBody RxFillMessage payload) { + logger.info("NcpdpScriptController::getScriptResponse /script/rxfill"); + + Header header = payload.getHeader(); + RxFillBody body = payload.getBody(); + + handleRxFillMessage(body.getRxFill(), header); // build the status to return Header statusHeader = new Header(header.getFrom().value, header.getTo().value, header.getMessageId(), header.getPrescriberOrderNumber()); Status status = new Status("000", null, null, null); - RxFillStatusBody statusBody = new RxFillStatusBody(status); - RxFillStatusMessage statusMessage = new RxFillStatusMessage(statusHeader, statusBody); + StatusBody statusBody = new StatusBody(status); + StatusMessage statusMessage = new StatusMessage(statusHeader, statusBody); return statusMessage; } +*/ private MedicationDispense.MedicationDispenseStatus convertRxFillDispensedStatusToMedicationDispenseStatus(FillStatus.DispensedStatusEnum dispensedStatus) { switch(dispensedStatus) { diff --git a/src/main/java/org/hl7/codex/rems/script/RxFillBody.java b/src/main/java/org/hl7/codex/rems/script/RxFillBody.java deleted file mode 100644 index 09d9414..0000000 --- a/src/main/java/org/hl7/codex/rems/script/RxFillBody.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.hl7.codex.rems.script; - -import javax.xml.bind.annotation.XmlElement; - -public class RxFillBody { - private RxFill rxFill; - - @XmlElement(name="RxFill") - public RxFill getRxFill() { - return rxFill; - } - public void setRxFill(RxFill rxFill) { - this.rxFill = rxFill; - } -} diff --git a/src/main/java/org/hl7/codex/rems/script/RxFillMessage.java b/src/main/java/org/hl7/codex/rems/script/RxFillMessage.java deleted file mode 100644 index f8e8219..0000000 --- a/src/main/java/org/hl7/codex/rems/script/RxFillMessage.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hl7.codex.rems.script; - -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlElement; - -@XmlRootElement(name="Message") -public class RxFillMessage { - protected Header header; - private RxFillBody body; - - @XmlElement(name="Header") - public Header getHeader() { - return header; - } - public void setHeader(Header header) { - this.header = header; - } - - @XmlElement(name="Body") - public RxFillBody getBody() { - return body; - } - public void setBody(RxFillBody body) { - this.body = body; - } -} diff --git a/src/main/java/org/hl7/codex/rems/script/RxFillStatusMessage.java b/src/main/java/org/hl7/codex/rems/script/RxFillStatusMessage.java deleted file mode 100644 index 2158897..0000000 --- a/src/main/java/org/hl7/codex/rems/script/RxFillStatusMessage.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.hl7.codex.rems.script; - -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlElement; - -@XmlRootElement(name="Message") -public class RxFillStatusMessage { - protected Header header; - private RxFillStatusBody body; - - public RxFillStatusMessage() { - this.header = null; - this.body = null; - } - - public RxFillStatusMessage(Header header, RxFillStatusBody body) { - this.header = header; - this.body = body; - } - - @XmlElement(name="Header") - public Header getHeader() { - return header; - } - public void setHeader(Header header) { - this.header = header; - } - - @XmlElement(name="Body") - public RxFillStatusBody getBody() { - return body; - } - public void setBody(RxFillStatusBody body) { - this.body = body; - } -} From b099b9d4d7e535fc4f1dc461fe72c3e8e4a807ec Mon Sep 17 00:00:00 2001 From: Patrick LaRocque Date: Wed, 18 Sep 2024 23:07:47 -0400 Subject: [PATCH 2/2] Add error return when unsupported message is received. --- .../java/org/hl7/codex/rems/script/Body.java | 19 ++++++ .../java/org/hl7/codex/rems/script/Error.java | 19 ++++++ .../rems/script/NcpdpScriptController.java | 58 +++++++------------ 3 files changed, 60 insertions(+), 36 deletions(-) create mode 100644 src/main/java/org/hl7/codex/rems/script/Error.java diff --git a/src/main/java/org/hl7/codex/rems/script/Body.java b/src/main/java/org/hl7/codex/rems/script/Body.java index 67921b8..5f5fa51 100644 --- a/src/main/java/org/hl7/codex/rems/script/Body.java +++ b/src/main/java/org/hl7/codex/rems/script/Body.java @@ -7,6 +7,7 @@ public class Body { private RxFill rxFill; private Status status; + private Error error; @XmlElement(name="RxFill") public RxFill getRxFill() { @@ -24,11 +25,29 @@ public void setStatus(Status status) { this.status = status; } + @XmlElement(name="Error") + public Error getError() { + return error; + } + public void setError(Error error) { + this.error = error; + } + public Body() { + this.rxFill = null; this.status = null; + this.error = null; + } + + public Body(RxFill rxFill) { + this.rxFill = rxFill; } public Body(Status status) { this.status = status; } + + public Body(Error error) { + this.error = error; + } } diff --git a/src/main/java/org/hl7/codex/rems/script/Error.java b/src/main/java/org/hl7/codex/rems/script/Error.java new file mode 100644 index 0000000..6651d73 --- /dev/null +++ b/src/main/java/org/hl7/codex/rems/script/Error.java @@ -0,0 +1,19 @@ +package org.hl7.codex.rems.script; + +public class Error { + public String Code; + public String DescriptionCode; + public String Description; + + public Error() { + this.Code = null; + this.DescriptionCode = null; + this.Description = null; + } + + public Error(String code, String descriptionCode, String description) { + this.Code = code; + this.DescriptionCode = descriptionCode; + this.Description = description; + } +} diff --git a/src/main/java/org/hl7/codex/rems/script/NcpdpScriptController.java b/src/main/java/org/hl7/codex/rems/script/NcpdpScriptController.java index 6191285..c58b3b1 100644 --- a/src/main/java/org/hl7/codex/rems/script/NcpdpScriptController.java +++ b/src/main/java/org/hl7/codex/rems/script/NcpdpScriptController.java @@ -42,23 +42,36 @@ public Message handleScriptMessage(@RequestBody Message payload) { Header header = payload.getHeader(); Body body = payload.getBody(); + Boolean returnSuccess = false; + String errorMessage = ""; + if (body.getRxFill() != null) { logger.info("NcpdpScriptController::handleScriptMessage RxFill Message"); handleRxFillMessage(body.getRxFill(), header); + returnSuccess = true; } else if (body.getStatus() != null) { - logger.info("NcpdpScriptController::handleScriptMessage Status Message"); + errorMessage = "Status Message NOT supported"; + logger.info("NcpdpScriptController::handleScriptMessage " + errorMessage); } else { - logger.info("NcpdpScriptController::handleScriptMessage Unsupported NCPDP SCRIPT Message"); + errorMessage = "Unsupported NCPDP SCRIPT Message"; + logger.info("NcpdpScriptController::handleScriptMessage " + errorMessage); } - // build the status to return - Header statusHeader = new Header(header.getFrom().value, header.getTo().value, + Body returnBody; + if (returnSuccess) { + // build the status to return + Status status = new Status("000", null, null, null); + returnBody = new Body(status); + } else { + // build the error to return + Error error = new Error("900", "1000", errorMessage); + returnBody = new Body(error); + } + + Header returnHeader = new Header(header.getFrom().value, header.getTo().value, header.getMessageId(), header.getPrescriberOrderNumber()); - Status status = new Status("000", null, null, null); - Body statusBody = new Body(); - statusBody.setStatus(status); - Message statusMessage = new Message(statusHeader, statusBody); - return statusMessage; + Message returnMessage = new Message(returnHeader, returnBody); + return returnMessage; } private void handleRxFillMessage(RxFill rxFill, Header header) { @@ -110,33 +123,6 @@ private void handleRxFillMessage(RxFill rxFill, Header header) { } } - - /** - * A custom endpoint that handles NCPDP Script messages. - * @param payload - the object used to serialize the XML in the request body. - * @return - an object containing the NCPDP Script Status to return. - */ -/* - @PostMapping(value = "/script/rxfill", produces = {APPLICATION_XML}, consumes = {APPLICATION_XML}) - @ResponseBody - public StatusMessage getScriptResponse(@RequestBody RxFillMessage payload) { - logger.info("NcpdpScriptController::getScriptResponse /script/rxfill"); - - Header header = payload.getHeader(); - RxFillBody body = payload.getBody(); - - handleRxFillMessage(body.getRxFill(), header); - - // build the status to return - Header statusHeader = new Header(header.getFrom().value, header.getTo().value, - header.getMessageId(), header.getPrescriberOrderNumber()); - Status status = new Status("000", null, null, null); - StatusBody statusBody = new StatusBody(status); - StatusMessage statusMessage = new StatusMessage(statusHeader, statusBody); - return statusMessage; - } -*/ - private MedicationDispense.MedicationDispenseStatus convertRxFillDispensedStatusToMedicationDispenseStatus(FillStatus.DispensedStatusEnum dispensedStatus) { switch(dispensedStatus) { case DISPENSED: