This is IBM eSQL, and the criteria were:
If order type is "CARDI" and patient location is "HOSPA" or "HOSPB" and the order type isn't "CARDI-EKG" or "CARDI-TT" send the message
If order type is "CARDI" and patient location is not "HOSPA" or " HOSPB " and the order type is not an EKG, TT, HM, PS, SC, TR, TT , send the message
Don't send anything else
The original code was:
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
DECLARE input REFERENCE TO Body;
DECLARE Processchk BOOLEAN 'UNKNOWN';
DECLARE hl7 NAMESPACE 'urn:hl7-org:v2xml';
DECLARE flag, pv1_3, obr_4, obr_18 CHAR;
SET flag = substring(input.hl7
BR.hl7:"OBR.4.UniversalServiceIdentifier".hl7:"CE.1" FROM 1 FOR 5);SET pv1_3 = substring(input.hl7
V1.hl7:"PV1.3.AssignedPatientLocation".hl7:"PL.1" FROM 1 FOR 5);SET obr_4 = substring(input.hl7
BR.hl7:"OBR.4.UniversalServiceIdentifier".hl7:"CE.1" FROM 1 FOR 9);SET obr_18 = substring(input.hl7
BR.hl7:"OBR.18.PlacerField1" FROM 1 FOR 5);IF (flag ='CARDI'
THENIF (pv1_3 = 'HOSPA' OR pv1_3 = 'HOSPB'
THENIF (CONTAINS(obr_4, 'CARDI-EKG'
OR CONTAINS(obr_4, 'CARDI-TT'
) THENSET Processchk = 'FALSE';
END IF;
ELSE
IF (CONTAINS(obr_4, 'CARDI-EKG'
ORCONTAINS(obr_4, 'CARDI-TRI'
ORCONTAINS(obr_4, 'CARDI-HM'
ORCONTAINS(obr_4, 'CARDI-PS'
ORCONTAINS(obr_4, 'CARDI-SC'
ORCONTAINS(obr_4, 'CARDI-TT'
ORCONTAINS(obr_4, 'CARDI-TR'
) THENSET Processchk = 'FALSE';
ELSE
SET Processchk = 'TRUE';
END IF;
END IF;
ELSE
SET Processchk = 'TRUE';
END IF;
RETURN Processchk;
END;
This basically passed any value through, whether it was "CARDI" or not.
I am going to try this, which passed the syntax check. I am sure there are way more efficient and elegant ways to do it, but I don't have the skill. I would rather have used NOT IN (1,2,3,4,5) on the bottom one instead of calling the same variable over and over, but I have not been able to make that work in the past.
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
DECLARE input REFERENCE TO Body;
DECLARE hl7 NAMESPACE 'urn:hl7-org:v2xml';
DECLARE Processchk, CHECK1, CHECK2 BOOLEAN 'FALSE';
DECLARE UID1, PATLOC, UID2 CHAR;
SET UID1 = substring(input.hl7
BR.hl7:"OBR.4.UniversalServiceIdentifier".hl7:"CE.1" FROM 1 FOR 5);SET UID2 = substring(input.hl7
BR.hl7:"OBR.4.UniversalServiceIdentifier".hl7:"CE.1" FROM 1 FOR 9);SET PATLOC = substring(input.hl7
V1.hl7:"PV1.3.AssignedPatientLocation".hl7:"PL.1" FROM 1 FOR 5);-- Check If CARDI and HOSPA or HOSPB and not CARDI-EKG and CARDI-TT
IF ((UID1 = 'CARDI'
AND(PATLOC = 'HOSPA' OR PATLOC = 'HOSPB'
AND(UID2 <> 'CARDI-EKG' AND UID2 <> 'CARDI-TT'
) THENSET CHECK1 = 'TRUE';
ELSE
SET CHECK1 = 'FALSE';
END IF;
-- Check If CARDI and not HOSPA and HOSPB and not EKG, TT, HM, PS, SC, or TR
IF ((UID1 = 'CARDI'
AND(PATLOC <> 'HOSPA' AND PATLOC <> 'HOSPB'
AND(UID2 <> 'CARDI-EKG' AND
UID2 <> 'CARDI-TT' AND
UID2 <> 'CARDI-HM' AND
UID2 <> 'CARDI-PS' AND
UID2 <> 'CARDI-SC' AND
UID2 <> 'CARDI-TR'
) THENSET CHECK2 = 'TRUE';
ELSE
SET CHECK2 = 'FALSE';
END IF;
-- Filter message unless CHECK1 OR CHECK2 are 'TRUE'
IF (CHECK1 OR CHECK2) THEN
SET Processchk = 'TRUE';
ELSE
SET Processchk = 'FALSE';
END IF;
RETURN Processchk;
END;
-----signature-----
Using the mirror of ridicule to force conservatives to
confront their own stupidity.
confront their own stupidity.




