Skip to content
Draft
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
70 changes: 68 additions & 2 deletions src/main/java/oscar/oscarRx/util/RxUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,56 @@ public static void instrucParser(RxPrescriptionData.Prescription rx) {
takeMax = amountFrequency;
}


String originalTakeMinForStrengthCheck = takeMin;
boolean takeMinCorrectedForStrength = false;

if (!takeMin.equals("0") && !takeMin.isEmpty()) {
try {
float parsedTakeMinValue = Float.parseFloat(takeMin.trim());
if (parsedTakeMinValue > 10.0f) {
if (checkIfStrengthVal(takeMin, instructions)) {
takeMin = "1";
takeMinCorrectedForStrength = true;
}
}
} catch (NumberFormatException e) {
logger.error(e.getMessage());
}
}

if (takeMinCorrectedForStrength && takeMax.equals(originalTakeMinForStrengthCheck)) {
takeMax = "1";
} else if (!takeMax.equals("0") && !takeMax.isEmpty() && !takeMax.equals(takeMin)) {
try {
float parsedTakeMaxValue = Float.parseFloat(takeMax.trim());
if (parsedTakeMaxValue > 10.0f) {
if (checkIfStrengthVal(takeMax, instructions)) {
takeMax = "1";
if (originalTakeMinForStrengthCheck.equals("0")) {
takeMin = "1";
}
}
}
} catch (NumberFormatException e) {
logger.error(e.getMessage());
}
}


if (takeMin.equals("0")) {
boolean hasFrequency = !frequency.isEmpty();
boolean hasDurationOrExistingQuantity = !duration.equals("0") ||
(rx.getQuantity() != null && !rx.getQuantity().trim().isEmpty() && !rx.getQuantity().trim().equals("0") && !rx.getQuantity().trim().equalsIgnoreCase("null"));

if (hasFrequency && hasDurationOrExistingQuantity) {
takeMin = "1";
if (takeMax.equals("0")) {
takeMax = "1";
}
}
}

//calculate the number of pills to have per frequency which is used to calculate the duration later on.
//from frequency code we can deduce a duration unit.
//check if a durationunit is already specified, if not, use that, if yes,check if they are equal,if not output an warning and use specified.
Expand Down Expand Up @@ -875,14 +925,14 @@ public static void instrucParser(RxPrescriptionData.Prescription rx) {
if (!isUnitNameUsed && quantity != 0) {
rx.setQuantity(Integer.toString(quantity));
}

rx.setSpecial(instructions);

if (rx.isCustomNote()) {
rx.setQuantity(null);
rx.setUnitName(null);
}

rx.setPolicyViolations(policyViolations);

p("below set special");
Expand All @@ -902,6 +952,22 @@ public static void instrucParser(RxPrescriptionData.Prescription rx) {
return;
}

/**
* Checks if the specified strength value is present in the instruction string.
* The method uses a regular expression to determine if the strength value, followed
* by a valid unit (e.g., mg, g, mcg, ml, etc.), exists in the given instructions.
*
* @param val The strength value to check.
* @param instruction The instructions text to search in.
* @return true if the strength value followed by its unit exists in the instructions;
* false otherwise.
*/
private static boolean checkIfStrengthVal(String val, String instruction) {
Pattern strengthPattern = Pattern.compile(
"\\b" + Pattern.quote(val.trim()) + "\\s*(mg|g|mcg|ml|iu|meq|unit)", Pattern.CASE_INSENSITIVE);
return strengthPattern.matcher(instruction).find();
}

public static boolean isStringToNumber(String s) {//see if string contains decimal or integer
boolean retBool = false;
Pattern p1 = Pattern.compile("\\d*\\.*\\d+");
Expand Down
40 changes: 40 additions & 0 deletions src/main/webapp/oscarRx/SearchDrug3.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,46 @@ function updateQty(element){
}});
return true;
}

const methods = ["Take", "Apply", "Rub well in"];
const routes = ["PO", "SL", "IM", "Subcut", "PATCH", "TOP", "INH", "SUPP", "right eye", "left eye", "both eyes"];
const frequencies = ["BID", "TID", "QID", "once daily", "twice daily", "3x daily", "4x daily", "weekly"];
const numbers = ["1/4", "1/2", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
const durations = ["day", "days", "week", "weeks", "month", "months", "3 months"];

let placeholderInterval;

function getRandom(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}

function generateExample() {
return getRandom(methods) + " " +
getRandom(routes) + " " +
getRandom(frequencies) + " " +
getRandom(numbers) + " for " +
getRandom(durations);
}

function startShowingSampleInstructions(element, randId) {
element.placeholder = "e.g. " + generateExample();
element._placeholderInterval = setInterval(() => {
element.placeholder = "e.g. " + generateExample();
}, 2000);

document.getElementById("disp_instruct_link_" + randId).classList.add('ripple-wrap');
document.getElementById("disp_instruct_img_" + randId).classList.add('ripple-icon', 'pulse-icon');
}


function stopShowingSampleInstructions(element, randId) {
clearInterval(element._placeholderInterval);
element._placeholderInterval = null;

document.getElementById("disp_instruct_link_" + randId).classList.remove('ripple-wrap');
document.getElementById("disp_instruct_img_" + randId).classList.remove('ripple-icon', 'pulse-icon');
}

function parseIntr(element){
var elemId=element.id;
var ar=elemId.split("_");
Expand Down
Loading