/*
 * Copyright (c) 1996 Gunther Schadow.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

% The ASTM prolog database
%
% ONLY DEFINES WHAT RADIOMETER'S ABL500 AND 600 SERIES KNOWS ABOUT ASTM,
%
% This is *not* a complete definition of the ASTM E-31 standard, since
% I don't have a copy of the standard documents.
%
:- module(astm, []).
:- package(astm, 'ABL500').

%
% MULTI PROTOCOL MANAGEMENT DATA
%
header_segment(h).
trailer_segment(l).
special_segment(h).

%
% We need to import some data types from protogen common data types
%
:- use_package(protogen).
:- use_package(hl7).

%
% OVERHEAD LEFT FROM HL7
%
functional_area(astm, 1, "astm result report").

%
% THE ONE AND ONLY ASTM MESSAGE
%
message_type(astm, "astm result message", astm).
message(astm, '', "astm result message",
	[h,
	 rep(p,
	     rep(o,
		 rep(r)
		 )
	     ),
	 l]).

%
% SEGMENTS
%
segment(h, "header", astm).
field(h,  5, "sender",			za,  '', o, n,  0, 0).
field(h, 11, "comment",                 st,  '', o, n,  0, 0).
field(h, 13, "version id",		id,1008, o, n,  8, 0).
field(h, 14, "date/time of message",	ts,  '', o, n, 26, 0).

/* CLINFILE3
segment(q, "request patient information", astm).
field(q,  1, "sequence number",		si,  '', o, n,  0, 0).
field(q,  2, "lab assigned pat id",     id,  '', o, n,  0, 0).
*/

segment(p, "patient", astm).
field(p,  1, "sequence number",		si,  '', o, n,  0, 0).
field(p,  3, "lab assigned patient id",	id,  '', o, n, 16, 0).
field(p,  5, "patient name",		pn,  '', o, n,  0, 0).
field(p,  8, "sex",			id,   1, o, n,  1, 0).
field(p, 14, "patient age",		cq,  '', o, n,  0, 0).
field(p, 16, "patient height",		cq,  '', o, n,  0, 0).
field(p, 17, "patient weight",		cq,  '', o, n,  0, 0).
field(p, 26, "location",		id,  '', o, n, 12, 0).

segment(o, "order", astm).
field(o,  1, "sequence number",		si,  '', o, n,  0, 0).
field(o,  3, "instrument specimen id",	zi,  '', o, n,  0, 0).
field(o,  7, "specimen collection date/time",
					ts,  '', o, n, 26, 0).
field(o, 15, "specimen descriptor",	zs,  '', o, n,  0, 0).

segment(r, "result", astm).
field(r,  1, "sequence number",		si,  '', o, n,  0, 0).
field(r,  2, "universal test id",	zt,  '', o, n,  0, 0).
field(r,  3, "measurement value",	st,  '', o, n,  0, 0).
/* contains a number with
   preceeding '?' and '>' or '<' (preceeding or alone)
   undefined results by "....." .... how I love HL7 for its NULL value!
*/
field(r,  4, "units",			id,   3, o, n,  0, 0).
field(r,  6, "abnormal flag",		id,  78, o, n,  1, 0).
field(r,  8, "result status",		id,  85, o, n,  0, 0).
field(r, 10, "operator id",		id,  '', o, n, 12, 0).
field(r, 11, "date/time test started",	ts,  '', o, n, 26, 0).
field(r, 13, "instrument id",		id,1006, o, n,  3, 0).

/*
segment(m, "manufacturer information", astm).
field(m,  1, "sequence number",		si,  '', o, n,  0, 0).
field(m,  2, "message",		        id,  '', o, n,  0, 0).
*/

segment(l, "trailer", astm).
field(l,  1, "sequence number",		si,  '', o, n,  0, 0).
field(l,  2, "termination code",	id,1007, o, n,  0, 0).

%
% DATA TYPES
%
data_type(za, "sender name or id", '').
ctyp_imp(za, % sender name or id
	[[id,'brand'],
	 [id,'id']]).

data_type(zi, "instrument specimen id", '').
ctyp_imp(zi, % instrument specimen id
	[[code(1005),'type'],
	 [si,'number']]).

data_type(zs, "specimen descriptor", '').
ctyp_imp(zs, % specimen descriptor
	[[code(1001),'type'],
	 [code(1002),'source']]).

data_type(zt, "universal test id", '').
ctyp_imp(zt, % universal test id
	[[id,'unused 1'],
	 [id,'unused 2'],
	 [id,'unused 3'],
	 [code(1003),'parameter name'],
	 [code(1004),'parameter type'],
	 [si,'sample number']]).	

%
% CODE TABLES
%
table(1001, "specimen type", user_defined). 
value(1001, 'Blood', "blood", 0).
value(1001, 'Gas', "gas", 0).
value(1001, 'Urine', "urine", 0).
value(1001, 'QC level 1', "quality check level 1", 0).
value(1001, 'QC level 2', "quality check level 2", 0).
value(1001, 'QC level 3', "quality check level 3", 0).
value(1001, 'QC level 4', "quality check level 4", 0).
value(1001, 'QC level 5', "quality check level 5", 0).
value(1001, 'QC level 6', "quality check level 6", 0).
value(1001, 'QC level 7', "quality check level 7", 0).
value(1001, 'QC level 8', "quality check level 8", 0).
value(1001, 'Gas cal 1', "gas calibration 1", 0).
value(1001, 'Gas cal 2', "gas calibration 2", 0).
value(1001, 'Cal 1', "calibration 1", 0).
value(1001, 'Cal 2', "calibration 2", 0).
value(1001, 'Total cal', "total calibration", 0).

table(1002, "specimen source", user_defined). 
value(1002, 'Arterial', "arterial", 0).
value(1002, 'Venous', "venous", 0).
value(1002, 'Capillary', "capillary", 0).
value(1002, 'Mixed-venous', "mixed venous", 0).
value(1002, 'Urine', "unrine", 0).
value(1002, 'Not specified', "not specified", 0).
value(1002, 'S2030', "control solution S2030", 0).
value(1002, 'S2040', "control solution S2040", 0).
value(1002, 'S2050', "control solution S2050", 0).
value(1002, 'S2060', "control solution S2060", 0).
value(1002, 'Non -R-', "non -r- control solution", 0).

table(1003, "parameter name", user_defined).
value(1003, 'AaDpO2', "AaDpO2", 0).
value(1003, 'AaDpO2,T', "AaDpO2,T", 0).
value(1003, 'ABE', "ABE", 0).
value(1003, 'a/ApO2', "a/ApO2", 0).
value(1003, 'a/ApO2,T', "a/ApO2,T", 0).
value(1003, 'Anion gap(K+)', "Anion gap(K+)", 0). 
value(1003, 'Anion gap', "Anion gap", 0).
value(1003, 'B', "B", 0).
value(1003, 'Ca++', "Ca++", 0).
value(1003, 'Ca(7.4)', "Ca(7.4)", 0).
value(1003, 'Cl-', "Cl-", 0).
value(1003, 'COHb', "COHb", 0).
value(1003, 'CO2', "CO2", 0).
value(1003, 'CQ', "CQ", 0).
value(1003, 'cx', "cx", 0).
value(1003, 'DO2',"DO2", 0).
value(1003, 'FIO2', "FIO2", 0).
value(1003, 'Glu', "Glucose", 0).
value(1003, 'HbF', "HbF", 0).
value(1003, 'HCO3-', "HCO3-", 0).
value(1003, 'Hct', "Hct", 0).
value(1003, 'K+', "K+", 0).
value(1003, 'MetHb', "MetHb", 0).
value(1003, 'Na+', "Na+", 0).
value(1003, 'O2', "O2", 0).
value(1003, 'O2CAP', "O2CAP", 0).
value(1003, 'O2Hb', "O2Hb", 0).
value(1003, 'pCO2', "pCO2", 0).
value(1003, 'pCO2(T)', "pCO2(T)", 0).
value(1003, 'pH', "pH", 0).
value(1003, 'pH(st)', "pH(st)", 0).
value(1003, 'pH(T)', "pH(T)", 0).
value(1003, 'pO2', "pO2", 0).
value(1003, 'pO2(A)', "pO2(A)", 0).
value(1003, 'pO2(A),T', "pO2(A),T", 0).
value(1003, 'pO2(T)', "pO2(T)", 0).
value(1003, 'pO2(uv)', "pO2(uv)", 0).
value(1003, 'px', "px", 0).
value(1003, 'Qt', "Qt", 0).
value(1003, 'Qx', "Qx", 0).
value(1003, 'p50(act)', "p50(act)", 0).
value(1003, 'p50(act),T', "p50(act),T", 0).
value(1003, 'p50(st)', "p50(st)", 0).
value(1003, 'RHb', "RHb", 0).
value(1003, 'RI', "RI", 0).
value(1003, 'RI,T', "RI,T", 0).
value(1003, 'RQ', "RQ", 0).
value(1003, 'SBC', "SBC", 0).
value(1003, 'SBE', "SBE", 0).
value(1003, 'Shunt', "Shunt", 0).
value(1003, 'Shunt,T', "Shunt,T", 0).
value(1003, 'sO2', "sO2", 0).
value(1003, 'T', "T", 0).
value(1003, 'tCO2(B)', "tCO2(B)", 0).
value(1003, 'tCO2(P)', "tCO2(P)", 0).
value(1003, 'tHb', "tHb", 0).
value(1003, 'tO2', "tO2", 0).
value(1003, 'VO2', "VO2", 0).
value(1003, 'SHb', "SHb", 0).
value(1003, '0', "operator record", 0).
value(1003, '1', "system record, general", 0).
value(1003, '2', "system record from last calibration", 0).
value(1003, '3', "system record from last measurement", 0).
value(1003, '4', "sample record", 0).
value(1003, '5', "transducer record from last calibration", 0).
value(1003, '6', "transducer record from last measurement", 0).
value(1003, '7', "transducer record from last flush", 0).
value(1003, '8', "transducer record from last manual calibration", 0).
value(1003, '9', "system record from last manual calibration", 0).

table(1004, "parameter type", user_defined).
value(1004, c, "calculated", 0).
value(1004, d, "default", 0).
value(1004, e, "estimated", 0).
value(1004, i, "input", 0).
value(1004, m, "measured", 0).
value(1004, ' ', "undefined", 0).
value(1004, 'High', "calibration high", 0).  
value(1004, 'Low', "calibration low", 0).
value(1004, 'DriftH', "calibration drift high", 0).
value(1004, 'DriftL', "calibration drift low", 0).
value(1004, 'Status', "calibration status", 0).
value(1004, 'Sens', "calibration sensitivity", 0).
value(1004, 'Zero', "calibration zero", 0).
value(1004, '0', "general", 0).
value(1004, '1', "flush", 0).
value(1004, '2', "measure-ment", 0).
value(1004, '3', "maintenance", 0).
value(1004, '4', "cali-bration", 0).
value(1004, '5', "manual calibration", 0).
value(1004, '6', "qc measurement", 0).
value(1004, '7', "hbf determination", 0).

table(1005, "instrument specimen type", user_defined).
value(1005, 'Sample #', "sample", 0).
value(1005, 'QC #', "quality check", 0).
value(1005, 'Cal #', "calibration", 0).
value(1005, 'Error', "Error", 0).

table(1006, "instrument id", user_defined).
value(1006, osm, "haemoximeter", 0).
value(1006, kna, "sodium potassium analyzer", 0).
value(1006, ica, "free calcium analyzer", 0).

table(1007, "termination code", user_defined).
value(1007, n, "normal termination", 0).
value(1007, t, "sender abort", 0).

table(1008, "astm version id", user_defined).
value(1008, '1', "version 1", 0).
