[med-svn] [gnumed-server] 01/03: Imported Upstream version 21.10
Andreas Tille
tille at debian.org
Tue Nov 8 17:09:32 UTC 2016
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to branch master
in repository gnumed-server.
commit c2398beaef7a0ec0defa5a7d1e8597c7b04b404f
Author: Andreas Tille <tille at debian.org>
Date: Tue Nov 8 17:41:19 2016 +0100
Imported Upstream version 21.10
---
server/doc/schema/gnumed-entire_schema.html | 2 +-
.../v20-v21/dynamic/v21-release_notes-dynamic.sql | 31 +--
.../v21-clin-get_hints_for_patient-fixup.sql | 310 +++++++++++----------
3 files changed, 175 insertions(+), 168 deletions(-)
diff --git a/server/doc/schema/gnumed-entire_schema.html b/server/doc/schema/gnumed-entire_schema.html
index 967cdf5..c6321db 100644
--- a/server/doc/schema/gnumed-entire_schema.html
+++ b/server/doc/schema/gnumed-entire_schema.html
@@ -112,7 +112,7 @@
<body>
<!-- Primary Index -->
- <p><br><br>Dumped on 2016-09-12</p>
+ <p><br><br>Dumped on 2016-11-07</p>
<h1><a name="index">Index of database - gnumed_v21</a></h1>
<ul>
diff --git a/server/sql/v20-v21/dynamic/v21-release_notes-dynamic.sql b/server/sql/v20-v21/dynamic/v21-release_notes-dynamic.sql
index a05d886..042ba69 100644
--- a/server/sql/v20-v21/dynamic/v21-release_notes-dynamic.sql
+++ b/server/sql/v20-v21/dynamic/v21-release_notes-dynamic.sql
@@ -17,26 +17,25 @@ INSERT INTO dem.message_inbox (
) VALUES (
(select pk from dem.staff where db_user = 'any-doc'),
(select pk_type from dem.v_inbox_item_type where type = 'memo' and category = 'administrative'),
- 'Release Notes for GNUmed 1.6.9 (database v21.9)',
- 'GNUmed 1.6.9 Release Notes:
+ 'Release Notes for GNUmed 1.6.10 (database v21.10)',
+ 'GNUmed 1.6.10 Release Notes:
- 1.6.9
+ 1.6.10
-FIX: faulty detection of dynamic hint applicability
-FIX: exception on Orthanc port out of bounds
-FIX: setting address from list in receiver selection widget
-FIX: no EMR user interaction when updating active encounter display
-FIX: faulty by-day measurements display after patient change
+FIX: more faults with dynamic hint detection
+FIX: exception on verifying substance intake EA
+FIX: failure to download studies from early Orthanc versions
+FIX: failure to create BMP when no allergy check date available
-IMPROVED: start-end formatting of substance intake
-IMPROVED: select unicode character from SOAP STC context menu
-IMPROVED: edit test results by context menu from lists
-IMPROVED: AMTS data file generation (v2 -> v2.3)
-IMPROVED: color of focussed line in STC-based SOAP editor
-IMPROVED: information in Hx box of patient overview plugin
+IMPROVED: LaTeX formatting of current medications
-NEW: placeholder $<if_not_empty>$
+NEW: placeholders $<bill_adr_*>$ for accessing the address of a bill
+NEW: --wxp=2|3 command line option
+
+ 21.10
+
+FIX: clin.get_hints_for_patient()
');
-- --------------------------------------------------------------
-select gm.log_script_insertion('v21-release_notes-dynamic.sql', '21.9');
+select gm.log_script_insertion('v21-release_notes-dynamic.sql', '21.10');
diff --git a/server/sql/v20-v21/fixups/v21-clin-get_hints_for_patient-fixup.sql b/server/sql/v20-v21/fixups/v21-clin-get_hints_for_patient-fixup.sql
index 12b2b9c..367c86e 100644
--- a/server/sql/v20-v21/fixups/v21-clin-get_hints_for_patient-fixup.sql
+++ b/server/sql/v20-v21/fixups/v21-clin-get_hints_for_patient-fixup.sql
@@ -22,22 +22,88 @@ where
grant select on staging.journal_without_suppressed_hints to group "gm-staff";
-- --------------------------------------------------------------
+drop function if exists clin.hint_suppression_exists(IN _pk_identity integer, IN _pk_hint integer, OUT _o_exists BOOLEAN, OUT _o_md5 TEXT, OUT _o_rationale TEXT) cascade;
+
+create function clin.hint_suppression_exists(IN _pk_identity integer, IN _pk_hint integer, OUT _o_exists BOOLEAN, OUT _o_md5 TEXT, OUT _o_rationale TEXT)
+ returns RECORD
+ language 'plpgsql'
+ as '
+--DECLARE
+-- _md5_suppressed text;
+-- _old_rationale4suppression text;
+BEGIN
+ SELECT
+ md5_sum,
+ rationale
+ INTO
+ _o_md5,
+ _o_rationale
+ FROM clin.suppressed_hint WHERE
+ fk_hint = _pk_hint
+ AND
+ fk_encounter IN (
+ SELECT pk FROM clin.encounter WHERE fk_patient = _pk_identity
+ );
+ IF FOUND THEN
+ _o_exists := TRUE;
+ ELSE
+ _o_exists := FALSE;
+ END IF;
+END;';
+
+-- --------------------------------------------------------------
+drop function if exists clin.run_hint_query(IN _title text, IN _query text, OUT _o_applies boolean, OUT _o_title TEXT) cascade;
+
+create function clin.run_hint_query(IN _title text, IN _query text, OUT _o_applies boolean, OUT _o_title TEXT)
+ returns RECORD
+ language 'plpgsql'
+ as '
+BEGIN
+ BEGIN
+ EXECUTE _query INTO STRICT _o_applies;
+ EXCEPTION
+ --WHEN insufficient_privilege THEN RAISE WARNING ''auto hint query failed: %'', _query;
+ WHEN others THEN
+ RAISE WARNING ''auto hint query failed: %'', _query;
+ -- only available starting with PG 9.2:
+ --GET STACKED DIAGNOSTICS
+ -- _exc_state = RETURNED_SQLSTATE,
+ -- _exc_msg = MESSAGE_TEXT,
+ -- _exc_detail = PG_EXCEPTION_DETAIL,
+ -- _exc_hint = PG_EXCEPTION_HINT,
+ -- _exc_context = PG_EXCEPTION_CONTEXT;
+ --RAISE WARNING ''SQL STATE: %'', _exc_state;
+ --RAISE WARNING ''MESSAGE: %'', _exc_msg;
+ --RAISE WARNING ''DETAIL: %'', _exc_detail;
+ --RAISE WARNING ''HINT: %'', _exc_hint;
+ --RAISE WARNING ''CONTEXT: %'', _exc_context;
+ -- workaround for 9.1:
+ RAISE WARNING ''SQL STATE: %'', SQLSTATE;
+ RAISE WARNING ''MESSAGE: %'', SQLERRM;
+ _o_applies := NULL;
+ _o_title := (''ERROR checking for ['' || _title || ''] !'')::TEXT;
+ RETURN;
+ END;
+ _o_title := _title;
+END;';
+
+-- --------------------------------------------------------------
drop function if exists clin.get_hints_for_patient(integer) cascade;
+drop function if exists clin.get_hints_for_patient(IN _pk_identity integer) cascade;
-create function clin.get_hints_for_patient(integer)
+create function clin.get_hints_for_patient(IN _pk_identity integer)
returns setof ref.v_auto_hints
language 'plpgsql'
as '
DECLARE
- _pk_identity ALIAS FOR $1;
_hint ref.v_auto_hints%rowtype;
_query text;
- _sanitized_query text;
- _md5_suppressed text;
- _rationale4suppression text;
_suppression_exists boolean; -- does not mean that the suppression applies
+ _md5_at_suppression text;
+ _old_rationale4suppression text;
_hint_currently_applies boolean; -- regardless of whether suppressed or not
_hint_recommendation text;
+ _title text;
-- _exc_state text;
-- _exc_msg text;
-- _exc_detail text;
@@ -47,172 +113,114 @@ BEGIN
-- loop over all defined hints
FOR _hint IN SELECT * FROM ref.v_auto_hints WHERE is_active LOOP
+ --raise NOTICE ''checking hint for patient %: %'', _pk_identity, _hint.title;
+
-- is the hint suppressed ?
- SELECT
- md5_sum,
- rationale
- INTO
- _md5_suppressed,
- _rationale4suppression
- FROM clin.suppressed_hint WHERE
- fk_hint = _hint.pk_auto_hint
- AND
- fk_encounter IN (
- SELECT pk FROM clin.encounter WHERE fk_patient = _pk_identity
- );
- IF FOUND THEN
- _suppression_exists := TRUE;
- ELSE
- _suppression_exists := FALSE;
- END IF;
+ SELECT (clin.hint_suppression_exists(_pk_identity, _hint.pk_auto_hint)).*
+ INTO STRICT _suppression_exists, _md5_at_suppression, _old_rationale4suppression;
-- does the hint currently apply ? (regardless of whether it is suppressed)
_query := replace(_hint.query, ''ID_ACTIVE_PATIENT'', _pk_identity::text);
- BEGIN
- EXECUTE _query INTO STRICT _hint_currently_applies;
- EXCEPTION
- --WHEN insufficient_privilege THEN RAISE WARNING ''auto hint query failed: %'', _query;
- WHEN others THEN
- RAISE WARNING ''auto hint query failed: %'', _query;
- -- only available starting with PG 9.2:
- --GET STACKED DIAGNOSTICS
- -- _exc_state = RETURNED_SQLSTATE,
- -- _exc_msg = MESSAGE_TEXT,
- -- _exc_detail = PG_EXCEPTION_DETAIL,
- -- _exc_hint = PG_EXCEPTION_HINT,
- -- _exc_context = PG_EXCEPTION_CONTEXT;
- --RAISE WARNING ''SQL STATE: %'', _exc_state;
- --RAISE WARNING ''MESSAGE: %'', _exc_msg;
- --RAISE WARNING ''DETAIL: %'', _exc_detail;
- --RAISE WARNING ''HINT: %'', _exc_hint;
- --RAISE WARNING ''CONTEXT: %'', _exc_context;
- -- workaround for 9.1:
- RAISE WARNING ''SQL STATE: %'', SQLSTATE;
- RAISE WARNING ''MESSAGE: %'', SQLERRM;
- _hint.title := ''ERROR checking for ['' || _hint.title || ''] !'';
- _hint.hint := _query;
- RETURN NEXT _hint;
- -- process next hint
- CONTINUE;
- END;
-
- -- does it _really_ apply ?
- -- re-run against staging.journal_without_suppressed_hints which does
- -- not contain suppressed hints -- because it may have applied only
- -- because clin.v_emr_journal does contain formatted suppressed hints
- IF _hint_currently_applies THEN
- _sanitized_query := replace(_query, ''clin.v_emr_journal'', ''staging.journal_without_suppressed_hints'');
- -- but only re-run if actually different
- IF _sanitized_query <> _query THEN
- BEGIN
- EXECUTE _sanitized_query INTO STRICT _hint_currently_applies;
- EXCEPTION
- --WHEN insufficient_privilege THEN RAISE WARNING ''sanitized auto hint query failed: %'', _sanitized_query;
- WHEN others THEN
- RAISE WARNING ''sanitized auto hint query failed: %'', _sanitized_query;
- -- only available starting with PG 9.2:
- --GET STACKED DIAGNOSTICS
- -- _exc_state = RETURNED_SQLSTATE,
- -- _exc_msg = MESSAGE_TEXT,
- -- _exc_detail = PG_EXCEPTION_DETAIL,
- -- _exc_hint = PG_EXCEPTION_HINT,
- -- _exc_context = PG_EXCEPTION_CONTEXT;
- --RAISE WARNING ''SQL STATE: %'', _exc_state;
- --RAISE WARNING ''MESSAGE: %'', _exc_msg;
- --RAISE WARNING ''DETAIL: %'', _exc_detail;
- --RAISE WARNING ''HINT: %'', _exc_hint;
- --RAISE WARNING ''CONTEXT: %'', _exc_context;
- -- workaround for 9.1:
- RAISE WARNING ''SQL STATE: %'', SQLSTATE;
- RAISE WARNING ''MESSAGE: %'', SQLERRM;
- _hint.title := ''ERROR checking for ['' || _hint.title || ''] !'';
- _hint.hint := _sanitized_query;
- RETURN NEXT _hint;
- -- process next hint
- CONTINUE;
- END;
- END IF;
+ _query := replace(_query, ''clin.v_emr_journal'', ''staging.journal_without_suppressed_hints'');
+ SELECT (clin.run_hint_query(_hint.title, _query)).*
+ INTO STRICT _hint_currently_applies, _title;
+
+ -- error ?
+ IF _hint_currently_applies IS NULL THEN
+ --raise NOTICE '' error -> return'';
+ _hint.title := _title;
+ _hint.hint := _query;
+ RETURN NEXT _hint;
+ -- process next hint
+ CONTINUE;
END IF;
- IF _suppression_exists THEN
- -- is the hint definition still the same as at the time of suppression ?
- IF _md5_suppressed = _hint.md5_sum THEN
- -- yes, but does this hint currently apply ?
- IF _hint_currently_applies THEN
- -- suppressed, suppression valid, and hint applies: skip this hint
- CONTINUE;
- END IF;
- -- suppressed, suppression valid, hint does NOT apply:
- -- skip but invalidate suppression, because:
- -- * previously the hint applied and the user suppressed it,
- -- * then the patient changed such that the hint does not
- -- apply anymore (but the suppression is still valid),
- -- * when the patient changes again, the hint might apply again
- -- * HOWEVER - since the suppression would still be valid - the
- -- hint would magically get suppressed again (which is
- -- medically unsafe) ...
- -- after invalidation, the hint will no longer be suppressed,
- -- however - since it does not currently apply it - it will
- -- still not be returned until it applies again ...
- --
- -- -----------------------------------------------------------------------
- -- UNFORTUNATELY, the following is currently not _possible_ because
- -- we are running inside a READONLY transaction (due to inherent
- -- security risks when running arbitrary user queries [IOW the hint
- -- SQL] against the database) and we cannot execute a
- -- sub-transaction as READWRITE :-/
- --
- --UPDATE clin.suppressed_hint
- --SET md5_sum = ''invalidated''::text -- will not ever match any md5 sum
- --WHERE
- -- fk_encounter IN (
- -- SELECT pk FROM clin.encounter WHERE fk_patient = _pk_identity
- -- )
- -- AND
- -- fk_hint = _hint.pk_auto_hint;
- -- -----------------------------------------------------------------------
- --
- -- hence our our workaround is to, indeed, return the hint but
- -- tag it with a magic rationale, by means of which the client
- -- can detect it to be in need of invalidation:
- _hint.title := ''HINT DOES NOT APPLY BUT NEEDS INVALIDATION OF EXISTING SUPPRESSION ['' || _hint.title || ''].'';
- _hint.rationale4suppression := ''magic_tag::please_invalidate_suppression'';
- RETURN NEXT _hint;
- CONTINUE;
- END IF;
- -- suppression exists but hint definition must have changed
- -- does the new hint apply ?
- IF _hint_currently_applies THEN
- -- yes: ignore the suppression but provide previous
- -- rationale for suppression to the user
- _hint.rationale4suppression := _rationale4suppression;
- -- retrieve recommendation
- SELECT clin._get_recommendation_for_patient_hint(_hint.recommendation_query, _pk_identity) INTO STRICT _hint_recommendation;
- _hint.recommendation := _hint_recommendation;
- RETURN NEXT _hint;
+ -- hint does not apply
+ IF _hint_currently_applies IS FALSE THEN
+ -- does a (previously stored) suppression exist ?
+ IF _suppression_exists IS FALSE THEN
+ -- no, so skip this hint
+ --raise NOTICE '' does not apply -> skip'';
CONTINUE;
END IF;
- -- no, new hint does not apply, so ask for
- -- invalidation of suppression (see above)
+ --raise NOTICE '' does not apply but suppression invalid -> return for invalidation'';
+ -- hint suppressed but does NOT apply:
+ -- skip hint but invalidate suppression, because:
+ -- * previously the hint must have applied and the user suppressed it,
+ -- * then patient data (or hint definition) changed such that
+ -- the hint does not apply anymore (but the suppression is
+ -- still valid),
+ -- * when patient data changes again, the hint might apply again
+ -- * HOWEVER - since the suppression would still be valid - the
+ -- hint would magically get suppressed again (which is
+ -- medically unsafe) ...
+ -- after invalidation, the hint will no longer be suppressed,
+ -- however - since it does not currently apply - it will
+ -- still not be returned and shown until it applies again ...
+ --
+ -- -----------------------------------------------------------------------
+ -- UNFORTUNATELY, the following is currently not _possible_ because
+ -- we are running inside a READONLY transaction (due to inherent
+ -- security risks when running arbitrary user queries [IOW the hint
+ -- SQL] against the database) and we cannot execute a
+ -- sub-transaction as READWRITE :-/
+ --
+ --UPDATE clin.suppressed_hint
+ --SET md5_sum = ''invalidated''::text -- will not ever match any md5 sum
+ --WHERE
+ -- fk_encounter IN (
+ -- SELECT pk FROM clin.encounter WHERE fk_patient = _pk_identity
+ -- )
+ -- AND
+ -- fk_hint = _hint.pk_auto_hint;
+ -- -----------------------------------------------------------------------
+ --
+ -- hence our our workaround is to, indeed, return the hint but
+ -- tag it with a magic rationale, by means of which the client
+ -- can detect it to be in need of invalidation:
_hint.title := ''HINT DOES NOT APPLY BUT NEEDS INVALIDATION OF EXISTING SUPPRESSION ['' || _hint.title || ''].'';
- _hint.rationale4suppression := ''magic_tag::please_invalidate_suppression'';
+ _hint.rationale4suppression := ''magic_tag::does_not_apply::suppression_needs_invalidation'';
RETURN NEXT _hint;
CONTINUE;
END IF;
- -- hint is not suppressed
- -- does the hint currently apply ?
- IF _hint_currently_applies THEN
- -- yes: retrieve recommendation
+ --raise NOTICE '' applies'';
+
+ -- but is there a suppression ?
+ IF _suppression_exists IS FALSE THEN
+ --raise NOTICE '' return'';
+ -- no: retrieve recommendation
SELECT clin._get_recommendation_for_patient_hint(_hint.recommendation_query, _pk_identity) INTO STRICT _hint_recommendation;
_hint.recommendation := _hint_recommendation;
+ -- return hint
RETURN NEXT _hint;
+ CONTINUE;
END IF;
- -- no: ignore it and process next hint in LOOP
+
+ -- yes, is suppressed
+ --raise NOTICE '' is suppressed'';
+
+ -- is the suppression still valid ?
+ -- -> yes, suppression valid
+ IF _md5_at_suppression = _hint.md5_sum THEN
+ --raise NOTICE ''-> suppression valid, ignoring hint'';
+ -- hint applies, suppressed, suppression valid: skip this hint
+ CONTINUE;
+ END IF;
+
+ -- -> no, suppression not valid
+ -- hint definition must have changed so ignore the suppression but
+ -- provide previous rationale for suppression to the user
+ _hint.rationale4suppression := _old_rationale4suppression;
+ -- retrieve recommendation
+ SELECT clin._get_recommendation_for_patient_hint(_hint.recommendation_query, _pk_identity) INTO STRICT _hint_recommendation;
+ _hint.recommendation := _hint_recommendation;
+ RETURN NEXT _hint;
+ CONTINUE;
END LOOP;
RETURN;
END;';
-- --------------------------------------------------------------
-select gm.log_script_insertion('v21-clin-get_hints_for_patient-fixup.sql', '21.9');
+select gm.log_script_insertion('v21-clin-get_hints_for_patient-fixup.sql', '21.10');
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/gnumed-server.git
More information about the debian-med-commit
mailing list