/*
 * HP-CareVue 9000 HL7 specials for HL7 v2.2
 *
 * Copyright (c) 1995, 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.
 */

:- module(carevue,[]).
:- package(carevue).

% this is HP CareVue HL7 dialect, so we are based on HL7

:- use_package(hl7).

% the "discharge disposition" code is used with UKBF definitions

:- use_package(ukbf).

% CareVue makes changes to these ADT messages:

hpcv_event(a01).
hpcv_event(a02).
hpcv_event(a03).
hpcv_event(a08).
hpcv_event(a11).
hpcv_event(a12).
hpcv_event(a13).

% The changes are basically addition of a `ZDM' segment

segment(zdm, "hp configuable demographics", hp).
field(zdm, 1, "zdm 1", st, '', '', '', '', '').
field(zdm, 2, "zdm 2", st, '', '', '', '', '').
field(zdm, 3, "zdm 3", st, '', '', '', '', '').
field(zdm, 4, "zdm 4", st, '', '', '', '', '').
field(zdm, 5, "zdm 5", st, '', '', '', '', '').
field(zdm, 6, "zdm 6", st, '', '', '', '', '').
field(zdm, 7, "zdm 7", st, '', '', '', '', '').
field(zdm, 8, "zdm 8", st, '', '', '', '', '').
field(zdm, 9, "zdm 9", st, '', '', '', '', '').
field(zdm, 10, "zdm 10", st, '', '', '', '', '').
field(zdm, 11, "zdm 11", st, '', '', '', '', '').
field(zdm, 12, "zdm 12", st, '', '', '', '', '').
field(zdm, 13, "zdm 13", st, '', '', '', '', '').
field(zdm, 14, "zdm 14", st, '', '', '', '', '').
field(zdm, 15, "zdm 15", st, '', '', '', '', '').
field(zdm, 16, "zdm 16", st, '', '', '', '', '').
field(zdm, 17, "zdm 17", st, '', '', '', '', '').
field(zdm, 18, "zdm 18", st, '', '', '', '', '').
field(zdm, 19, "zdm 19", st, '', '', '', '', '').
field(zdm, 20, "zdm 20", st, '', '', '', '', '').
field(zdm, 21, "zdm 21", st, '', '', '', '', '').
field(zdm, 22, "zdm 22", st, '', '', '', '', '').
field(zdm, 23, "zdm 23", st, '', '', '', '', '').
field(zdm, 24, "zdm 24", st, '', '', '', '', '').
field(zdm, 25, "zdm 25", st, '', '', '', '', '').
field(zdm, 26, "zdm 26", st, '', '', '', '', '').
field(zdm, 27, "zdm 27", st, '', '', '', '', '').
field(zdm, 28, "zdm 28", st, '', '', '', '', '').
field(zdm, 29, "zdm 29", st, '', '', '', '', '').
field(zdm, 30, "zdm 30", st, '', '', '', '', '').
field(zdm, 31, "zdm 31", st, '', '', '', '', '').
field(zdm, 32, "zdm 32", st, '', '', '', '', '').

% We completely redefine the "swap patients" message, since inserting 
% a ZDM segment is not so easy.

message(adt, a17, Des,
	[msh, evn,
	pid, pv1, opt(pv2),
	opt(rep(obx)),
	opt(zdm),
	pid, pv1, opt(pv2),
	opt(rep(obx)),
	opt(zdm)]) :- hl7:message(adt, a17, Des, _).

% the others get a ZDM place appended

message(adt, Event, Des, Def) :- hpcv_event(Event),
	hl7:message(adt, Event, Des, OrigDef),
	append(OrigDef, [opt(zdm)], Def).

table(0112, "discharge disposition", '').
value(0112, B,C,D) :- ukbf:value(0112, B,C,D).
value(0112, 'HOME',     "hp home", '').
value(0112, 'AMA',      "hp against medical advice", '').
value(0112, 'DECEASED', "hp deceased", '').
value(0112, 'FACILITY', "hp facility", '').
value(0112, 'OTHER',    "hp other", '').

% all the rest is copied unchanged

message(A,B,C,D) :- hl7:message(A,B,C,D).
segment(A,B,C) :- hl7:segment(A,B,C).
field(A,B,C,D,E,F,G,H,I) :- hl7:field(A,B,C,D,E,F,G,H,I).
data_type(A,B,C) :- hl7:data_type(A,B,C).
ctyp_imp(A,B) :- hl7:ctyp_imp(A,B).
table(A,B,C) :- hl7:table(A,B,C).
value(A,B,C,D) :- hl7:value(A,B,C,D).
value(A,B,C,D) :- A \= 0112, ukbf:value(A,B,C,D).

