Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: PXRRUTIL

PXRRUTIL.m

Go to the documentation of this file.
  1. PXRRUTIL ;ISL/PKR - Utility routines for use by PXRR. ;3/20/97
  1. ;;1.0;PCE PATIENT CARE ENCOUNTER;**12**;Aug 12, 1996
  1. ;
  1. ;=======================================================================
  1. SORT(N,ARRAY,KEY) ;Sort an ARRAY with N elements into ascending order,
  1. ;return the number of unique elements. KEY is the piece of ARRAY on
  1. ;which to base the sort. The default is the first piece.
  1. ;
  1. I (N'>0)!(N=1) Q N
  1. N IC,IND
  1. I '$D(KEY) S KEY=1
  1. F IC=1:1:N S ^TMP($J,"SORT",$P(@ARRAY@(IC),U,KEY))=@ARRAY@(IC)
  1. S IND=""
  1. F IC=1:1 S IND=$O(^TMP($J,"SORT",IND)) Q:IND="" D
  1. . S @ARRAY@(IC)=^TMP($J,"SORT",IND)
  1. K ^TMP($J,"SORT")
  1. Q IC-1
  1. ;
  1. ;=======================================================================
  1. STRREP(STRING,TS,RS) ;Replace every occurence of the target string (TS)
  1. ;in STRING with the replacement string (RS).
  1. ;Example 9.19 (page 220) in "The Complete Mumps" by John Lewkowicz:
  1. ; F Q:STRING'[TS S STRING=$P(STRING,TS)_RS_$P(STRING,TS,2,999)
  1. ;fails if any portion of the target string is contained in the with
  1. ;string. Therefore a more elaborate version is required.
  1. ;
  1. N FROM,NPCS,STR
  1. ;
  1. I STRING'[TS Q STRING
  1. ;Count the number of pieces using the target string as the delimiter.
  1. S FROM=1
  1. F NPCS=1:1 S FROM=$F(STRING,TS,FROM) Q:FROM=0
  1. ;Extract the pieces and concatenate RS
  1. S STR=""
  1. F FROM=1:1:NPCS-1 S STR=STR_$P(STRING,TS,FROM)_RS
  1. S STR=STR_$P(STRING,TS,NPCS)
  1. Q STR
  1. ;