Open upsonp opened 5 months ago
Break down of the code:
Start by selecting all rows from both the Discrete Station Edits (BCS) and the Discrete Data Edits (BCD) tables that match the provided batch sequence and store the data in a 'validate' cursor to be iterated over.
FUNCTION VALIDATE_DISCRETE_DATA(batch_seq_in_par IN NUMBER) RETURN VARCHAR2
IS
CURSOR validate IS
SELECT S.MISSION_DESCRIPTOR, S.EVENT_COLLECTOR_EVENT_ID, S.EVENT_COLLECTOR_STN_NAME,
S.DIS_HEADR_START_DEPTH, S.DIS_HEADR_END_DEPTH, S.DIS_HEADR_SLAT, S.DIS_HEADR_ELAT,
S.DIS_HEADR_SLON, S.DIS_HEADR_ELON, S.DIS_HEADR_SDATE, S.DIS_HEADR_EDATE,
S.DIS_HEADR_STIME, S.DIS_HEADR_ETIME, S.DIS_HEADR_COLLECTOR_SAMPLE_ID, S.DATA_CENTER_CODE,
S.DIS_SAMPLE_KEY_VALUE, S.CREATED_DATE, D.MISSION_DESCRIPTOR, D.EVENT_COLLECTOR_EVENT_ID,
D.EVENT_COLLECTOR_STN_NAME, D.DIS_HEADER_START_DEPTH, D.DIS_HEADER_END_DEPTH,
D.DIS_HEADER_SLAT, D.DIS_HEADER_SLON, D.DIS_HEADER_SDATE, D.DIS_HEADER_STIME,
D.DIS_DETAIL_COLLECTOR_SAMP_ID, D.DIS_SAMPLE_KEY_VALUE, D.DATA_CENTER_CODE,
D.DIS_DETAIL_DATA_TYPE_SEQ, D.DATA_TYPE_METHOD, D.CREATED_DATE, D.DIS_DATA_NUM,
DIS_HEADR_GEAR_SEQ, dis_headr_SOUNDING, DIS_HEADR_COLLECTOR_DEPLMT_ID
FROM BCDISCRETESTATNEDITS S, BCDISCRETEDATAEDITS D
WHERE S.batch_seq =D.batch_seq
AND D.DIS_SAMPLE_KEY_VALUE = S.DIS_SAMPLE_KEY_VALUE
AND S.batch_seq = batch_seq_in_par
ORDER BY D.DIS_DATA_NUM;
Create a list of variables that all the data will be read into and used for validating each column of each row.
DIS_SAMPLE_KEY_VALUE_VS BCDISCRETESTATNEDITS.dis_sample_key_value%TYPE;
MISSION_DESCRIPTOR_vs BCDISCRETESTATNEDITS.mission_descriptor%TYPE;
EVENT_COLLECTOR_EVENT_ID_vs BCDISCRETESTATNEDITS.event_collector_event_id%TYPE;
EVENT_COLLECTOR_STN_NAME_vs BCDISCRETESTATNEDITS.event_collector_stn_name%TYPE;
-- added sept 22, 2000
DIS_HEADR_GEAR_SEQ_VS BCDISCRETESTATNEDITS.dis_headr_gear_seq%TYPE;
DIS_HEADR_SOUNDING_VS BCDISCRETESTATNEDITS.dis_headr_SOUNDING%TYPE;
collector_deplmt_id_VS BCDISCRETESTATNEDITS.DIS_HEADR_COLLECTOR_DEPLMT_ID%TYPE;
--
DIS_HEADR_SDATE_vs BCDISCRETESTATNEDITS.dis_headr_sdate%TYPE;
DIS_HEADR_EDATE_vs BCDISCRETESTATNEDITS.dis_headr_edate%TYPE;
DIS_HEADR_STIME_VS BCDISCRETESTATNEDITS.dis_headr_stime%TYPE;
DIS_HEADR_ETIME_VS BCDISCRETESTATNEDITS.dis_headr_etime%TYPE;
DIS_HEADR_SLAT_VS BCDISCRETESTATNEDITS.dis_headr_slat%TYPE;
DIS_HEADR_ELAT_VS BCDISCRETESTATNEDITS.dis_headr_elat%TYPE;
DIS_HEADR_SLON_VS BCDISCRETESTATNEDITS.dis_headr_slon%TYPE;
DIS_HEADR_ELON_VS BCDISCRETESTATNEDITS.dis_headr_elon%TYPE;
DIS_HEADR_START_DEPTH_VS BCDISCRETESTATNEDITS.dis_headr_start_depth%TYPE;
DIS_HEADR_END_DEPTH_VS BCDISCRETESTATNEDITS.dis_headr_end_depth%TYPE;
DIS_HEADR_COL_SPLE_ID_VS BCDISCRETESTATNEDITS.dis_headr_collector_sample_id%TYPE;
DATA_CENTER_CODE_VS BCDISCRETESTATNEDITS.data_center_code%TYPE;
PROCESS_FLAG_VS BCDISCRETESTATNEDITS.process_flag%TYPE;
BATCH_SEQ_VS BCDISCRETESTATNEDITS.batch_seq%TYPE;
DIS_SAMPLE_KEY_VALUE_VD BCDISCRETEDATAEDITS.dis_sample_key_value%TYPE;
MISSION_DESCRIPTOR_VD BCDISCRETEDATAEDITS.mission_descriptor%TYPE;
EVENT_COLLECTOR_EVENT_ID_VD BCDISCRETEDATAEDITS.event_collector_event_id%TYPE;
EVENT_COLLECTOR_STN_NAME_VD BCDISCRETEDATAEDITS.event_collector_stn_name%TYPE;
DIS_HEADER_SDATE_VD BCDISCRETEDATAEDITS.dis_header_sdate%TYPE;
DIS_HEADER_STIME_VD BCDISCRETEDATAEDITS.dis_header_stime%TYPE;
DIS_HEADER_SLAT_VD BCDISCRETEDATAEDITS.dis_header_slat%TYPE;
DIS_HEADER_SLON_VD BCDISCRETEDATAEDITS.dis_header_slon%TYPE;
DIS_HEADER_START_DEPTH_VD BCDISCRETEDATAEDITS.dis_header_start_depth%TYPE;
DIS_HEADER_END_DEPTH_VD BCDISCRETEDATAEDITS.dis_header_end_depth%TYPE;
DIS_DETAIL_COL_SAMP_ID_VD BCDISCRETEDATAEDITS.dis_detail_collector_samp_id%TYPE;
CREATED_DATE_VS BCDISCRETESTATNEDITS.created_date%TYPE;
CREATED_DATE_VD BCDISCRETEDATAEDITS.created_date%TYPE;
DATA_CENTER_CODE_VD BCDISCRETEDATAEDITS.data_center_code%TYPE;
PROCESS_FLAG_VD BCDISCRETEDATAEDITS.process_flag%TYPE;
BATCH_SEQ_VD BCDISCRETEDATAEDITS.batch_seq%TYPE;
DIS_DETAIL_DATA_TYPE_SEQ_VD BCDISCRETEDATAEDITS.dis_detail_data_type_seq%TYPE;
DATA_TYPE_METHOD_VD BCDISCRETEDATAEDITS.data_type_method%TYPE;
METHOD_V BCDATATYPES.method%TYPE;
DATA_TYPE_SEQ_V BCDATATYPES.data_type_seq%TYPE;
DIS_DATA_NUM_var BCDISCRETEDATAEDITS.dis_data_num%TYPE;
NEXT_DATA_NUM_var BCDISCRETEDATAEDITS.dis_data_num%TYPE;
collector_sample_id_var BCDISCRETEDATAEDITS.dis_detail_collector_samp_id%TYPE;
valid VARCHAR2(1);
data_sample_key_is_null_var VARCHAR2(1);
return_var VARCHAR2(600) := 'T';
orphaned_count_var NUMBER;
new_data_type_seq_var NUMBER;
null_header_check_var VARCHAR2(600);
child_count_var NUMBER;
data_count_var NUMBER;
Read each row from the validate cursor into the variables that were just created
BEGIN
data_sample_key_is_null_var := 'N';
OPEN VALIDATE;
LOOP
FETCH VALIDATE INTO MISSION_DESCRIPTOR_vs,EVENT_COLLECTOR_EVENT_ID_vs,
EVENT_COLLECTOR_STN_NAME_VS,DIS_HEADR_START_DEPTH_VS,
DIS_HEADR_END_DEPTH_VS, DIS_HEADR_SLAT_VS, DIS_HEADR_ELAT_VS,
DIS_HEADR_SLON_VS, DIS_HEADR_ELON_VS, DIS_HEADR_SDATE_VS,
DIS_HEADR_EDATE_VS, DIS_HEADR_STIME_VS, DIS_HEADR_ETIME_VS,
DIS_HEADR_COL_SPLE_ID_VS, DATA_CENTER_CODE_VS,
DIS_SAMPLE_KEY_VALUE_VS, CREATED_DATE_VS, MISSION_DESCRIPTOR_VD,
EVENT_COLLECTOR_EVENT_ID_VD,
EVENT_COLLECTOR_STN_NAME_VD, DIS_HEADER_START_DEPTH_VD,
DIS_HEADER_END_DEPTH_VD, DIS_HEADER_SLAT_VD,
DIS_HEADER_SLON_VD, DIS_HEADER_SDATE_VD,
DIS_HEADER_STIME_VD, DIS_DETAIL_COL_SAMP_ID_VD,
DIS_SAMPLE_KEY_VALUE_VD, DATA_CENTER_CODE_VD,
DIS_DETAIL_DATA_TYPE_SEQ_VD,DATA_TYPE_METHOD_VD, CREATED_DATE_VD, DIS_DATA_NUM_var,
DIS_HEADR_GEAR_SEQ_VS, DIS_HEADR_SOUNDING_VS, collector_deplmt_id_VS;
EXIT WHEN VALIDATE%notfound;
Create a string (null_header_check_var) by concatenating a bunch of columns together as a string.
I don't really understand way you would do this because the next check is to see if the string is null or blank, but if any of the queried columns exist then the null_header_check string won't be blank.
valid := 'Y';
-- Sept 22, 2000
-- check for null headr on the station side
-- If the statn header is null and the dis_sample key values match
-- then generate a fatal error
null_header_check_var := to_char(dis_headr_gear_seq_VS)||to_char(dis_headr_sdate_VS)||to_char(dis_headr_edate_VS)||
to_char(dis_headr_stime_VS)||to_char(dis_headr_etime_VS)||to_char(dis_headr_slat_VS)||
to_char(dis_headr_elat_VS)||to_char(dis_headr_slon_VS)||to_char(dis_headr_elon_VS)||
to_char(dis_headr_start_depth_VS)||to_char(dis_headr_end_depth_VS)||
to_char(dis_headr_sounding_VS)||collector_deplmt_id_VS;
Now we'll record columns that are null.
if the null_header_check_var string is null or blank and the sample ID is not null log a 4053 error in the BC Station Data Errors table.
IF (null_header_check_var IS NULL or null_header_check_var = ' ') and DIS_SAMPLE_KEY_VALUE_VS IS NOT NULL THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETESTATNEDITS', DIS_SAMPLE_KEY_VALUE_VS, 'DIS_SAMPLE_KEY_VALUE',
'4053', CREATED_DATE_VD, nvl(DIS_DETAIL_COL_SAMP_ID_VD,'X'), batch_seq_in_par);
valid := 'N';
END IF;
Check the DIS_DATA_NUM column equals the NEXT_DATA_NUM column, log a 4043 if they are equal. If they're not equal set the NEXT_DATA_NUM to the value of the DIS_DATA_NUM for the next iteration.
Not really a very good way to make sure the DIS_DATA_NUM values are unique, or are in sequence 😕, all it's doing is making sure the new DIS_DATA_NUM value wasn't the same as the previous row.
IF DIS_DATA_NUM_var = NEXT_DATA_NUM_var THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DIS_DATA_NUM',
'4043', CREATED_DATE_VD, nvl(DIS_DETAIL_COL_SAMP_ID_VD,'X'), batch_seq_in_par);
valid := 'N';
END IF;
NEXT_DATA_NUM_var := DIS_DATA_NUM_var;
Check if the Mission Descriptor. a. if null log a 4001 error.
IF MISSION_DESCRIPTOR_vD IS NULL THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'MISSION_DESCRIPTOR',
'4001', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS, 'X'), batch_seq_in_par);
valid := 'N';
ELSE
b. MISSION_DESCRIPTOR_VS is from the BCS table, MISSION_DESCRIPTOR_VD is from the BCD table. If they're not equal, there's a problem.
IF MISSION_DESCRIPTOR_vs != MISSION_DESCRIPTOR_vD THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'MISSION_DESCRIPTOR',
'4042', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
END IF;
Check the BCD event ID a. if null log a 40001 error
IF EVENT_COLLECTOR_EVENT_ID_vD IS NULL THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'EVENT_COLLECTOR_EVENT_ID',
'4001', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS, 'X'),batch_seq_in_par);
valid := 'N';
b. if not null make sure the BCS event ID matches the BCD event ID
ELSE
IF EVENT_COLLECTOR_EVENT_ID_vs != EVENT_COLLECTOR_EVENT_ID_vD THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'EVENT_COLLECTOR_EVENT_ID',
'4042', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
END IF;
Station Name a. is it null? 4001 error
IF EVENT_COLLECTOR_STN_NAME_VD IS NULL THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'EVENT_COLLECTOR_STN_NAME',
'4001', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS, 'X'),batch_seq_in_par);
valid := 'N';
b. make sure BCD station name matches BCS Station name
ELSE
IF EVENT_COLLECTOR_STN_NAME_VS != EVENT_COLLECTOR_STN_NAME_VD THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'EVENT_COLLECTOR_STN_NAME',
'4042', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
END IF;
Make sure the BCD starting depth matches the BCS starting Depth
IF DIS_HEADR_START_DEPTH_VS != DIS_HEADER_START_DEPTH_VD THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DIS_HEADER_START_DEPTH',
'4042', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
Make sure the BCD end depth matches the BCS end Depth
IF DIS_HEADR_END_DEPTH_VS != DIS_HEADER_END_DEPTH_VD THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DIS_HEADER_END_DEPTH',
'4042', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
Make sure the BCD start latitude matches the BCS start latitude
IF DIS_HEADR_SLAT_VS != DIS_HEADER_SLAT_VD THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DIS_HEADER_SLAT',
'4042', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
Make sure the BCD start longitude matches the BCS start longitude
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DIS_HEADER_SLON',
'4042', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
Make sure the BCD start date matches the BCS start date
IF DIS_HEADR_SDATE_VS != DIS_HEADER_SDATE_VD THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DIS_HEADER_SDATE',
'4042', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
Make sure the BCD start time matches the BCS start time
IF DIS_HEADR_STIME_VS != DIS_HEADER_STIME_VD THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DIS_HEADER_STIME',
'4042', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
BCD sample ID a. is the sample ID null
IF DIS_DETAIL_COL_SAMP_ID_VD IS NULL THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DIS_DETAIL_COLLECTOR_SAMP_ID',
'4001', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS, 'X'),batch_seq_in_par);
valid := 'N';
b. does the BCD sample ID match the
ELSE
IF DIS_HEADR_COL_SPLE_ID_VS != DIS_DETAIL_COL_SAMP_ID_VD THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DIS_DETAIL_COLLECTOR_SAMP_ID',
'4042', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
END IF;
Check that the BCS and BCD datacenter codes match
IF DATA_CENTER_CODE_VS != DATA_CENTER_CODE_VD THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DATA_CENTER_CODE',
'4042', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
If the Data Type Method and the Data Type Sequence are supplied <-- This is important
-- if both are supplied then make sure that the correspond to each other
IF DATA_TYPE_METHOD_VD IS NOT NULL AND
DIS_DETAIL_DATA_TYPE_SEQ_VD IS NOT NULL THEN
a. Jump to Data Type Validation #148
IF BATCH_VALIDATION_PKG.DATA_TYPE(DIS_DETAIL_DATA_TYPE_SEQ_VD, DATA_TYPE_METHOD_VD) = 'F' THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DATA_TYPE_SEQ',
'4051', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS,'X'),batch_seq_in_par);
valid := 'N';
END IF;
b. Dart will require a BioChem Data Type for anything it's uploading, so it's unlikely it will ever have a method and no data type, and method codes are part of the BioChem Data Type table.
-- if only the method is supplied then look it up in the data types table and assign the data_type_seq to the current
new_data_type_seq_var := NULL;
ELSIF DATA_TYPE_METHOD_VD IS NOT NULL AND
DIS_DETAIL_DATA_TYPE_SEQ_VD IS NULL THEN
-- select the data type seq associated with the method into a variable
select data_type_seq into new_data_type_seq_var from bcdatatypes
where upper(method)= upper(DATA_TYPE_METHOD_VD);
-- if the new_data_type_seq_var is still null then the method was not found in the bcdatatypes table log the error
-- else update the associates record in the dcdiscretedataedits table with the new data_type_seq found
if new_data_type_seq_var is null then
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DATA_TYPE_SEQ',
'4001', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS, 'X'),batch_seq_in_par);
valid := 'N';
else
update bcdiscretedataedits set DIS_DETAIL_DATA_TYPE_SEQ = new_data_type_seq_var
where DIS_DATA_NUM = DIS_DATA_NUM_var
and batch_seq = batch_seq_in_par;
end if;
c. If there's no method and no data type record an error
ELSIF DIS_DETAIL_DATA_TYPE_SEQ_VD IS NULL THEN
INSERT INTO BCSTATNDATAERRORS VALUES
('BCDISCRETEDATAEDITS', DIS_DATA_NUM_var, 'DATA_TYPE_SEQ',
'4001', CREATED_DATE_VD, nvl(DIS_HEADR_COL_SPLE_ID_VS, 'X'),batch_seq_in_par);
valid := 'N';
END IF;
ensure the sample ID is present
IF DIS_SAMPLE_KEY_VALUE_VS IS NOT NULL THEN
IF valid = 'N' THEN
UPDATE BCDISCRETESTATNEDITS
SET PROCESS_FLAG = 'SVE'
WHERE batch_seq = batch_seq_in_par
AND DIS_SAMPLE_KEY_VALUE = DIS_SAMPLE_KEY_VALUE_VS;
END IF;
END IF;
If anything failed in the previous steps mark the row as DVE (Data Value Error?), if there was no issue mark it as DVI (Data Value Insert?)
IF valid = 'N' THEN
return_var := 'F';
UPDATE BCDISCRETEDATAEDITS
SET PROCESS_FLAG = 'DVE'
WHERE batch_seq = batch_seq_in_par
AND DIS_DATA_NUM = DIS_DATA_NUM_var;
ELSE
UPDATE BCDISCRETEDATAEDITS
SET PROCESS_FLAG = 'DVI'
WHERE batch_seq = batch_seq_in_par
AND DIS_DATA_NUM = DIS_DATA_NUM_var;
END IF;
END LOOP;
We're done with the cursor at this point close it and commit updates
CLOSE validate;
commit;
The following section is for reporting purposes to tell the user what has failed validation.
Kind of important here I think, they're counting DIS_DATA_NUM in the BCS and BCD table where the sample ids match or are null in the BCS table, but they're also checking that the creation date in both the BCS and BCD tables match. This must be a check for BCD rows that didn't get validated 😕.
It's basically saying get rows where BCS.sample_ID==BCD.sample_ID or where the BCS.sample_ID are null where the BCS.creation_date==BCD.creation_date
-- count the orphaned data records
Select count(dis_data_num) into child_count_var
from bcdiscretestatnedits a, bcdiscretedataedits b
where
(a.dis_sample_key_value=b.dis_sample_key_value OR a.DIS_SAMPLE_KEY_VALUE IS NULL)
and a.created_date=b.created_date
and a.batch_seq = batch_seq_in_par;
Insert 1 into the data_count_var if the BCD table has a batch_seq_id matching the requested batch_seq_id.
select count(1) into data_count_var
from bcdiscretedataedits
where batch_seq = batch_seq_in_par;
If there are zero errors then '1 - 0' will be greater than zero. If there are any errors at all then this fails. I don't really understand this logic because data_count_var is always going to be 1 and this will always be zero or less if there are any orphaned records.
IF (data_count_var - child_count_var) > 0 THEN
-- set the orphaned data record's process flag
UPDATE BCDISCRETEDATAEDITS
SET process_flag = 'DVO'
WHERE (dis_sample_key_value NOT IN
(select dis_sample_key_value from bcdiscretestatnedits
where batch_seq = batch_seq_in_par)
OR DIS_SAMPLE_KEY_VALUE IS NULL)
AND batch_seq = batch_seq_in_par;
-- report orphaned data record error into the errors table
-- T Joyce Sept 20, 2000
INSERT INTO BCSTATNDATAERRORS SELECT
'BCDISCRETEDATAEDITS', DIS_DATA_NUM, 'DIS_SAMPLE_KEY_VALUE',
'4052', CREATED_DATE, nvl(DIS_DETAIL_COLLECTOR_SAMP_ID,'X'), batch_seq
FROM BCDISCRETEDATAEDITS
WHERE process_flag = 'DVO'
and batch_seq = batch_seq_in_par;
-- flag all the stations as errors
UPDATE BCDISCRETESTATNEDITS
SET process_flag = 'SVE'
WHERE batch_seq = batch_seq_in_par;
-- flag the remaining data records as errors
UPDATE BCDISCRETEDATAEDITS
SET process_flag = 'DVE'
WHERE batch_seq = batch_seq_in_par
AND process_flag!='DVO';
-- flag as fatal error
return_var:='F';
END IF;
Finally commit the changes and return the value indicating if rows for the requested batch ID passed
commit;
RETURN return_var;
EXCEPTION
WHEN OTHERS THEN
IF validate%ISOPEN THEN
CLOSE validate;
END IF;
return_var := 'VALIDATE_DISCRETE_DATA proc error: '||to_char(SQLCODE)||', '||SQLERRM||'.';
RETURN return_var;
END VALIDATE_DISCRETE_DATA;
-- ******************************************************************************************
END VALIDATE_DISCRETE_STATN_DATA;
Summary:
Not much needs to be done to Dart to apply this functions validation. Dart will ensure if values exist that the BCS and BCD tables use the same values. I guess we should run validation in dart to check that:
This issue is to dissect Biochem validation as part of issue #141
This is the validation code run by the biochem intake script on the Discrete Data Edits table (BCD). It can be found in the BioChem account on PTran under packages.
Edit: The authoritative version can be found on BiochemP