diff --git a/Dockerfile b/Dockerfile index c5fa147..0ea2066 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ # Base image FROM gradle:6.9.0-jdk11 + # Set working directory so that all subsequent command runs in this folder WORKDIR /test-ehr # Copy app files to container @@ -7,5 +8,9 @@ COPY --chown=gradle:gradle . . RUN gradle build # Expose port to access the app EXPOSE 8080 + +#HealthCheck +HEALTHCHECK --interval=45s --start-period=60s --timeout=10m --retries=10 CMD curl --fail http://localhost:8080/test-ehr/r4/metadata || exit 1 + # Command to run our app CMD ./dockerRunnerProd.sh \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev index 383f535..46c3ad1 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,5 +1,6 @@ # Base image FROM gradle:6.9.0-jdk11 + # Set working directory so that all subsequent command runs in this folder WORKDIR /test-ehr # Copy app files to container @@ -8,5 +9,8 @@ RUN gradle build # Expose port to access the app EXPOSE 8080 EXPOSE 8081 + +HEALTHCHECK --interval=45s --start-period=60s --timeout=10m --retries=10 CMD curl --fail http://localhost:8080/test-ehr/r4/metadata || exit 1 + # Command to run our app CMD ./dockerRunnerDev.sh \ No newline at end of file diff --git a/Dockerfile.keycloak b/Dockerfile.keycloak index ff3b832..d790ba8 100644 --- a/Dockerfile.keycloak +++ b/Dockerfile.keycloak @@ -1,2 +1,11 @@ +FROM registry.access.redhat.com/ubi9 AS ubi-micro-build +RUN mkdir -p /mnt/rootfs +RUN dnf install --installroot /mnt/rootfs curl --releasever 9 --setopt install_weak_deps=false --nodocs -y && \ + dnf --installroot /mnt/rootfs clean all && \ + rpm --root /mnt/rootfs -e --nodeps setup + + FROM keycloak/keycloak:22.0.1 +COPY --from=ubi-micro-build /mnt/rootfs / +HEALTHCHECK --interval=30s --start-period=15s --timeout=10m --retries=10 CMD curl --fail http://localhost:8080 || exit 1 COPY ./src/main/resources/ClientFhirServerRealm.json /opt/keycloak/data/import/ClientFhirServerRealm.json \ No newline at end of file diff --git a/src/main/java/org/hl7/codex/rems/script/Body.java b/src/main/java/org/hl7/codex/rems/script/Body.java new file mode 100644 index 0000000..5f5fa51 --- /dev/null +++ b/src/main/java/org/hl7/codex/rems/script/Body.java @@ -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; + } +} 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/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..c58b3b1 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,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); @@ -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) { 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/RxFillStatusBody.java b/src/main/java/org/hl7/codex/rems/script/RxFillStatusBody.java deleted file mode 100644 index 51d946b..0000000 --- a/src/main/java/org/hl7/codex/rems/script/RxFillStatusBody.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.hl7.codex.rems.script; - -import javax.xml.bind.annotation.XmlElement; - -public class RxFillStatusBody { - private Status status; - - @XmlElement(name="Status") - public Status getStatus() { - return status; - } - public void setStatus(Status status) { - this.status = status; - } - - public RxFillStatusBody() { - this.status = null; - } - - public RxFillStatusBody(Status status) { - this.status = status; - } -} 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; - } -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9496a29..c9050b4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -106,7 +106,7 @@ hapi: # max_binary_size: 104857600 # max_page_size: 200 # retain_cached_searches_mins: 60 - # reuse_cached_search_results_millis: 60000 + reuse_cached_search_results_millis: 100 tester: home: name: Local Tester