Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NCPDP SCRIPT support to be a single end point #76

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/main/java/org/hl7/codex/rems/script/Body.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.hl7.codex.rems.script;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;

@XmlRootElement(name="Body")
public class Body {
private RxFill rxFill;
private Status status;
private Error error;

@XmlElement(name="RxFill")
public RxFill getRxFill() {
return rxFill;
}
public void setRxFill(RxFill rxFill) {
this.rxFill = rxFill;
}

@XmlElement(name="Status")
public Status getStatus() {
return status;
}
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;
}
}
19 changes: 19 additions & 0 deletions src/main/java/org/hl7/codex/rems/script/Error.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
21 changes: 20 additions & 1 deletion src/main/java/org/hl7/codex/rems/script/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
}
54 changes: 40 additions & 14 deletions src/main/java/org/hl7/codex/rems/script/NcpdpScriptController.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,48 @@ 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();

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) {
errorMessage = "Status Message NOT supported";
logger.info("NcpdpScriptController::handleScriptMessage " + errorMessage);
} else {
errorMessage = "Unsupported NCPDP SCRIPT Message";
logger.info("NcpdpScriptController::handleScriptMessage " + errorMessage);
}

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());
Message returnMessage = new Message(returnHeader, returnBody);
return returnMessage;
}

private void handleRxFillMessage(RxFill rxFill, Header header) {
FillStatus.DispensedStatusEnum dispensedStatus = rxFill.getFillStatus().getStatus();

logger.info(" PrescriberOrderNumber: " + header.getPrescriberOrderNumber());
logger.info(" Dispensed Status: " + dispensedStatus);
Expand Down Expand Up @@ -86,15 +120,7 @@ public RxFillStatusMessage getScriptResponse(@RequestBody RxFillMessage payload)
dispenseDetails.setRequestId(dispenseId);
medicationDispenseDao.update(medicationDispense, dispenseDetails);
logger.info(" Created new MedicationDispense: " + dispenseId);
}

// 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);
return statusMessage;
}
}

private MedicationDispense.MedicationDispenseStatus convertRxFillDispensedStatusToMedicationDispenseStatus(FillStatus.DispensedStatusEnum dispensedStatus) {
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/org/hl7/codex/rems/script/RxFillBody.java

This file was deleted.

26 changes: 0 additions & 26 deletions src/main/java/org/hl7/codex/rems/script/RxFillMessage.java

This file was deleted.

23 changes: 0 additions & 23 deletions src/main/java/org/hl7/codex/rems/script/RxFillStatusBody.java

This file was deleted.

36 changes: 0 additions & 36 deletions src/main/java/org/hl7/codex/rems/script/RxFillStatusMessage.java

This file was deleted.

Loading