/****************************************************************************
** Leistungsorientierte Krankenanstaltenfinanzierung (LKF)                 **
** Scoring-C-Sourcen V2026.1                                               **
** (C) 2026 BMASGPK                                                        **
*****************************************************************************
** lkfint5.h - interne Schnittstellendefinitionen                          **
**                                                                         **
**		 Alex.Holzer@chello.at                                             **
**       Bernhard.Pesec@dothealth.at                                       **
***************************************************************************/

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "lkf5defs.h"


//#define SUPPORT_OLD_TREEFILESTRUCTURE 1
//#define SIM2025_DEACTIVATE_ERRORS 1

#define STERNKR_NEW_MODEL    2013

#define SATZART_O_MODEL      2022
#define SATZART_A_MODEL      2025

#define LKF_MIN_MELMEL_BOOST_MODEL 2022

#define LKF_DATETIME_STRICT_MODEL 2024

/*****************************************************************************
** Patienten-Struktur                                                       **
*****************************************************************************/

/* String-Laengen */
#define LKF_AUFENTHALT_KANR_LEN          6
#define LKF_AUFENTHALT_KANR_LEN_AB2017  20

#define LKF_AUFENTHALT_PATID_LEN        10
#define LKF_AUFENTHALT_PATID_LEN_AB2017 12
#define LKF_AUFENTHALT_LONGID_LEN        64
#define LKF_AUFENTHALT_LONGID_LEN_AB2017 72

#define LKF_AUFENTHALT_DIAG_LEN          6
#define LKF_AUFENTHALT_DIAG_LEN_AB2017   7
#define LKF_AUFENTHALT_ABTFC_LEN	     8
#define LKF_AUFENTHALT_DAT_LEN           8
#define LKF_AUFENTHALT_ZEIT_LEN          4
#define LKF_AUFENTHALT_NEWMEL_LEN		 5
#define LKF_AUFENTHALT_ORIGMEL_LEN		10
#define LKF_AUFENTHALT_MELANZ_LEN        4
#define LKF_AUFENTHALT_ORIGMELANZ_LEN	 4
#define LKF_AUFENTHALT_ABT_INTSATZ_LEN_FONDS	39
#define LKF_AUFENTHALT_ABT_INTSATZ_LEN_NICHTFONDS 17
#define LKF_AUFENTHALT_ABTPOS_LEN		 2
#define LKF_AUFENTHALT_ABTPOS_LEN_2017   3

/* Satzarten-Dimensionen */

#define MAX_X_SATZART_NUM     7 /* V21.0 */
#define MAX_M_SATZART_NUM     8
#define MAX_I_SATZART_NUM	  3
#define MAX_I_SATZART_NUM2011 12
#define MAX_L_SATZART_NUM	  4
#define MAX_K_SATZART_NUM	 16
#define MAX_G_SATZART_NUM	  2
#define MAX_S_SATZART_NUM	  11
#define MAX_B_SATZART_NUM     6
#define MAX_X_SATZART_NUM     7
#define MAX_O_SATZART_NUM     2 /* V2021.3 */
#define MAX_A_SATZART_NUM     1 /* V2026.0 */
// #define LKF_AMB2025_ADD_HD 1

/* String-Datentypen */
typedef char FUNK_LIST_STRING	[114]; /* V21.0 - 114 statt 58 */
typedef char KA_LIST_STRING		[40]; /* V12.0 - statt bisher 28 */
typedef char KTR_LIST_STRING	[40]; /* V14.2 */
typedef char KOST_LIST_STRING	[59];
typedef char LAND_LIST_STRING	[28];
typedef char PLZ_LIST_STRING	[36];
typedef char SPEZ_LIST_STRING   [35];
typedef char ICD_LIST_STRING    [150]; /* V2022.0 */
typedef char STERNKR_LIST_STRING[27];
typedef char MEL_ARRAY_STRING   [36];
typedef char MEL_KA_STRING		[10]; /* ab V13.0: Laenge von 9 auf 10 erhoeht */
typedef char MEL_MEL_STRING		[16]; /* ab V8.0: Laenge von 9 auf 12 erhoeht, ab V13.0: Laenge 16 */
typedef char MEL_DIAG_STRING	[5];  /* ab V6.0: MELDIAG-Struktur */
typedef char DIAG_MEL_STRING    [12]; /* V18.0 */
typedef char DIAG_DIAG_STRING   [14];
typedef char MEL_LIST_STRING	[73];
typedef char GGART_STRING       [3]; /* V9.0 */
typedef char GGLEIST_STRING		[3]; /* V9.0 */

typedef char OEMELKA_STRING     [14]; /* V11.1; Format KANR6[6], MEL[4], Erbringbar[1] */
									  /* V13.0: Neues Format KANR6[6] MEL[5], Erbringbar[1] */

typedef char OEKASO_STRING      [8]; /* V13.0 */

typedef char GKZ_LIST_STRING    [6]; /* V21.0 */

typedef char PLZ_GEMCO_STRING   [10]; /* V21.2 */

typedef char ATCLIST_STRING     [64]; /* V21.0 */

/* V8.0: Dynamische Zeilenverwaltung */

typedef struct {
	char *pBuf;						/* Buffer */
	unsigned long *plOffsets;		/* Offsets der Zeilen */
	unsigned long lBufLen;			/* Buffer-Laenge */
	unsigned long lLineCount;		/* Belegte Laenge von plOffsets */
	unsigned long lLineAlloc;		/* Reservierte Laenge von plOffsets */
	unsigned long lBufAlloc;		/* Reservierte Buffer-Länge */
	unsigned long lBufExtend;		/* Erweiterungs-Groesse fuer Buffer-Laenge (in Bytes) */
	unsigned long lLineExtend;		/* Erweiterungs-Groesse fuer Offset-Laenge (in Long-Words) */
} LKF_LINE_BUFFER;


/* V8.1: Konstanten für Typ-Felder in Datensatz-Beschreibung */

#define TYP_NUM		      0	
#define TYP_ALPHA         1
#define TYP_DAT			  2
#define TYP_ZEIT		  3
#define TYP_FLOAT		  4
#define TYP_NUM_NEG		  5
#define TYP_NUM_NEG1000	  6
#define TYP_FLOAT_P2      7
#define TYP_ALPHA_TRUNC  11
#define TYP_FLOAT_NEG     8 /* V2026.1 */
#define MAX_FELDINDEX    100
#define MAX_SATZART_LEN 1120
#define MAX_INTBUFLEN    128

/* V8.1: Error Functions */

#define LKF_CHECKFUNC_NONE				0 /* ok */
#define LKF_CHECKFUNC_EXISTS			1 /* ok, wenn Feld nicht leer ist */ 
#define LKF_CHECKFUNC_FORMAT			2 /* ok, wenn Feld das richtige Format hat */
#define LKF_CHECKFUNC_STRINGLIST		3 /* ok, wenn Feld einen Wert aus einer String-Liste hat */
#define LKF_CHECKFUNC_INTRANGE			4 /* ok, wenn Feld in einem Integer-Bereich liegt */
#define LKF_CHECKFUNC_BOOL01			5 /* ok, wenn Feld "0" oder "1" ist */
#define LKF_CHECKFUNC_FUNCTION			6 /* ok, wenn angeg. Funktion 0 liefert */
#define LKF_CHECKFUNC_EXISTS_NOT0		9 /* ok, wenn das Feld nicht leer und nicht 0 ist / V9.2 */
#define LKF_CHECK_BYPASS_EMPTY		  256 /* ok, wenn leer */
#define LKF_CHECK_NURFONDSKA		  512 /* Error wird nur fuer Fonds-KHs ausgelöst */

#define LKF_ENTART_REVERS '4' /* V18.0 */

/* LKF_SATZART_ERRORDEF - definiert einen Error / Warning */

typedef struct LKF_SATZART_ERRORDEF LKF_SATZART_ERRORDEF;

typedef struct LKF_SATZART_ERROR_PROPERTIES
{
	int nFonds;
	int nNichtFonds;
	unsigned int nAlternateModelljahr;
	const struct LKF_SATZART_ERROR_PROPERTIES *pAlternateProperties;
    int nAlternateErrorModelljahr; /* V2023.0 */
    const LKF_SATZART_ERRORDEF *pAlternateError; /* V2023.0 */
} LKF_SATZART_ERROR_PROPERTIES;


typedef struct LKF_SATZART_ERRORDEF {
	unsigned int nCode;                /* Error Code */
	unsigned int nFacility;			   /* Error Facility */
	unsigned int nSeverity;            /* Error Severity */
	unsigned int nAddInfo;			   /* Additional Error Info */
	unsigned int nOldCode;			   /* Optional 2nd Error Number */
    const char	 sText[164];		   /* Error-Meldung */
	const LKF_SATZART_ERROR_PROPERTIES *pProperties; /* Spezielle Eigenschaften */
} LKF_SATZART_ERRORDEF;

/* LKF_SATZART_ERRORCHECK - definiert eine Check-Funktionalität */

typedef struct LKF_SATZART_ERRORCHECK {
	unsigned int                         nFunction;   /* Error-Check Funktion */
	const void							*pCheckInfo;  /* Parameter fuer Check-Funktion */
	const LKF_SATZART_ERRORDEF          *pErrorDef;   /* Error-Definition, wenn nicht ok */
	const struct LKF_SATZART_ERRORCHECK *pNextErr;    /* Nächster Error-Check, wenn Fehler */
	const struct LKF_SATZART_ERRORCHECK *pNextSuc;    /* Nächster Error-Check, wenn ok */
	unsigned int						 nModellJahr; /* Modelljahr, ab dem die alternative Ueberpruefung gilt */
	const struct LKF_SATZART_ERRORCHECK *pAlternateCheck; /* Alternative Error-Ueberpruefung */
} LKF_SATZART_ERRORCHECK;

typedef struct 
{
	const void *pTarget;
	const char *sComment;
} LKF_SATZART_ERRORCHECK_COMMENT;

struct LKF_CONTEXT_ERRORFORMAT {
	unsigned int fieldcount;   /* Anzahl Felder pro Zeile */
	unsigned int *fields;	   /* Felder ("CHECKFIELD_"-Konstanten) */
};


/* Strukturen für Satzarten-Beschreibung */

typedef struct SATZART_FELD {
	int                           nFieldNum;		/* Feldnummer */
	int                           nType;			/* Feldtyp */
	unsigned int                  nPos;				/* Position innerhalb des Satzes */
	unsigned int                  nLen;				/* Laenge */
	const LKF_SATZART_ERRORCHECK *pCheckInfo;		/* Error-Check-Information */
	int                           nScoreInfo;		/* Numerische Zusatzinformation */
	const char                   *sFeldName;		/* Name des Feldes */
	int                           nAltModelljahr;	/* Modelljahr, ab dem eine alternative Definition gilt */
	const struct SATZART_FELD	 *pAlternateDef;	/* Alternative Definition */
} SATZART_FELD; /* Beschreibt ein Feld in einer Satzart */

typedef struct {
	const char  *sPrefix;			/* Erkennungs-Prefix des Satzes */
	int          nStarts;			/* Start-Position des Satzes */
	unsigned int nCount;			/* Anzahl Key-Felder */
    unsigned int nSignificantCount; /* V21.2: Anzahl signifikanter Felder */
	const int   *nErrorIdentFields;	/* Array von Feldnummern, die den eindeutigen Schlüssel eines Satzes bilden */
	const char  *sTitle;			/* Bezeichnung der Satzart */
	const LKF_SATZART_ERRORCHECK *pCheck; /* Check-Routinen auf Satzart-Ebene (ohne Feld) */
	const SATZART_FELD Felder[60];	/* Felder; fixe Dimension fuer gcc etc.) */
} SATZART; /* Beschreibt eine Satzart */

typedef struct SATZART_INFO {
	const SATZART      *pSatzart;				/* Statische Satzart-Information */
	const SATZART_FELD *ppRef[MAX_FELDINDEX];	/* Referenz der Felder über Feldnummer */
    unsigned int       feldIndex[MAX_FELDINDEX]; /* V21.0 */
	unsigned int       nLength;					/* Anzahl Felder */
    int                nMaxIndex;               /* V21.0: Hoechster gueltiger Index in ppRef */
    const struct SATZART_INFO *pCompatibility;  /* V21.0: alte Version (compat.) */
} SATZART_INFO; /* Zusatzinformationen zur Satzart, die dynamisch ermittelt werden */

struct LKF_SATZART_DEFS {
	int    jahr;						/* Modell-Jahr */
	const SATZART **ppSatzarten;				/* Liste aller statischen Satzart-Informationen */
	SATZART_INFO *pSatzartInfo;					/* Liste aller dynamischen Satzart-Informationen */
	unsigned int    nCount;						/* Anzahl Satzarten */
	const SATZART_INFO **ppI;					/* Alle I-Satzarten */
	const SATZART_INFO **ppK;					/* Alle K-Satzarten */
	const SATZART_INFO **ppG;					/* Alle G-Satzarten */
	const SATZART_INFO **ppL;					/* Alle L-Satzarten */
	const SATZART_INFO **ppS;					/* Alle S-Satzarten */
	const SATZART_INFO **ppB;                   /* Alle B-Satzarten */
    const SATZART_INFO **ppX;                   /* V21.0: Alle X-Satzarten */
    const SATZART_INFO **ppO;                   /* V2021.3: O-Satzarten */
    const SATZART_INFO **ppA;                   /* V2026.0: A-Satzarten */
	SATZART_INFO *pL01Internal;					/* L01-Interne Struktur / V17.0 */
    
    const SATZART_INFO **ppCompatible;          /* V21.0: Alte Satzarten */
    unsigned int nCompatibleCount;                        /* V21.0 */
    
}; /* Verzeichnis aller Satzarten */

/* LKF_SATZART_ERRORINFO_USAGE - definiert die Anwendung eines Errors */

struct LKF_SATZART_ERRORINFO_USAGE
{
	const LKF_SATZART_ERRORCHECK *pErrorCheck;
	const SATZART *pSatzart;
	const SATZART_FELD *pFeld;
} ;

/* LKF_SATZART_ERRORINFO - gibt Informationen ueber einen Error */

struct LKF_SATZART_ERRORINFO 
{
	LKF_CONTEXT *pContext;
	unsigned int nCount;
	unsigned int nAlloc;
	LKF_SATZART_ERRORINFO_USAGE *pUsage;
	const LKF_SATZART_ERRORDEF *pError;
	char sErrorCode[6];
	unsigned int nOccurrences;
	int nFonds;
	int nNichtFonds;
} ;

/* LKF_SATZART_ERRORINFO_LIST - Liste von Error-Informationen */

struct LKF_SATZART_ERRORINFO_LIST
{
	LKF_CONTEXT *pContext;
	unsigned int nListOptions;
	unsigned int nAlloc;
	unsigned int nCount;
	LKF_SATZART_ERRORINFO *pErrors;
} ;

/* V21.0: LKF_EXPANDED_LINE Struktur */

typedef struct {
    char *fieldBuf;
    unsigned int fieldCount;
	unsigned int significantFieldCount;
    unsigned int bufLen;
    unsigned int bufPos;
    char **fields;
    char **fieldsById;
    char *postFix;
    int satzartNr;
    const SATZART_INFO *pSatzartInfo;
    const LKF_CONTEXT *pContext; /* V2019.0 */
} LKF_EXPANDED_LINE;

typedef struct {
    const SATZART_FELD *pFeld;
    const SATZART_INFO *pSatzart;
    const LKF_SATZART_ERRORDEF *pError;
    const char *fieldPos;
    long fieldLen;
    char *addIdent;
    const char *replaceIdent;
} LKF_EXPANDED_LINE_INFO;

typedef struct {
    LKF_CONTEXT *pContext;
    unsigned int lineCount;
    unsigned int lineAlloc;
    unsigned int lineExtend;
    LKF_EXPANDED_LINE **lines;
} LKF_EXPANDED_LINES;


/* Error-(Warning-)Speicherstrukturen */

#define LKF_ERRORFELD_LAENGE 32


struct LKF_SATZART_ERROR {
	const char					*pLine;			/* Zugehörige gemeldete Zeile (nicht für MBDS) */
	unsigned int				nAddInfo;		/* Zusatzinformation (nur für MBDS) */
	const SATZART_INFO			*pSatzartInfo;	/* Satzart-Information */
	const SATZART_FELD			*pFeld;			/* Feld in der Satzart */
	const LKF_SATZART_ERRORDEF	*pErrorDef;		/* Error */
	LKF_AUFENTHALT		*pAufenthalt;	/* Zugehöriger Aufenthalt */
	int							nAufNextErrorIndex;	/* Nächster Error innerhalb des Aufenthalts */
	char						sErrorFeld[LKF_ERRORFELD_LAENGE]; /* Error-Zusatzinformation */
	char						sErrorCode[4];	/* für die Sortierung */
	unsigned int				nErrorLfdNr;	/* für die Sortierung */
	int							nAbtIndex;      /* AbtIndex des Errors */
	char						sTyp[2];        /* Berichtstyp */
    const LKF_EXPANDED_LINE     *pExpLine;      /* V21.0 */
    int                          mainErrorIndex;/* V2020.1 */
    char                         KANR[8];       /* V2020.2 - Standort fuer OSG */
} ;

typedef struct LKF_SATZART_ERRORS {
	unsigned int nAlloc;						/* Reservierte Größe für pErrors */
	unsigned int nCount;						/* Anzahl Errors */
	unsigned int nErrorCount;   /* V2019.1 */
	unsigned int nFatalCount;   /* V2019.1 */
	unsigned int nWarningCount; /* V2019.1 */
	unsigned int nInfoCount;    /* V2019.1 */
	LKF_SATZART_ERROR *pErrors;					/* Array von tatsächlichen Errors (Warnings) */
} LKF_SATZART_ERRORS; /* Liste von Errors */

#define LKF_LINE_BUFFER_LINEALLOC   10
#define LKF_LINE_BUFFER_BUFALLOC  4096
#define LKF_LINE_BUFFER_LINEEXTEND  10
#define LKF_LINE_BUFFER_BUFEXTEND 4096

typedef struct {
	char ABTFC	[LKF_AUFENTHALT_ABTFC_LEN];
	char ABTDAT	[LKF_AUFENTHALT_DAT_LEN];
	char ABTPOS [LKF_AUFENTHALT_ABTPOS_LEN_2017];
	long ABTVD; /* wird berechnet */
	char ABT_INTSATZ[LKF_AUFENTHALT_ABT_INTSATZ_LEN_FONDS+1]; /* Verwendung fuer Intensiv-Scoring */
	unsigned int nExtOffset;
	unsigned int lAbtDat; /* wird berechnet */
    long lAbtZeit; /* V21.4: wird berechnet */
	long ABTVD_KORR; /* wird berechnet */
    char ISNEONAT;   /* V19.0 */
    char ALTERSGRUPPE[4]; /* V19.0 */
	unsigned int abtposNumeric; /* V21.1 */
    
    /* V21.0 */
    char ABTZEIT[LKF_AUFENTHALT_ZEIT_LEN];
    char PHYS_ANW;
    char ENTDAT[LKF_AUFENTHALT_DAT_LEN];
    char ENTZEIT[LKF_AUFENTHALT_ZEIT_LEN];
    char ENTART;
    char FACHFC[LKF_AUFENTHALT_ABTFC_LEN];
    char PFLEGFC[LKF_AUFENTHALT_ABTFC_LEN];
    char FUCOAUFNR[12]; /* V21.1 */
    long tp100; /* V21.4 */
    long lp100;/* V21.4 */
    char ABT_IDENT[16]; /* V22.1 */
} LKF_AUFENTHALT_ABT;

#define LKF_MAX_AMB_ABT 50
#define LKF_MAX_AMB_GRP 50

typedef struct NPPLAUS_CONTEXT NPPLAUS_CONTEXT;

typedef struct {
	char DIAG	 [LKF_AUFENTHALT_DIAG_LEN_AB2017];
	char DIAGPOS [4];
	char DIAGTYP [2];
    char DIAGART;   /* V21.0 */
    char DIAGSTAT;
	unsigned int nExtOffset;
    long long diagLongKey; /* V2022.1 */
    char FUCOAUFNR[12]; /* V21.1 */
    char DIAG_IDENT[16]; /* V22.1 */
    int isHD; /* V2024.0 */
} LKF_AUFENTHALT_DIAG;

#define LKF_MELCHECKFLAG_DISABLE_WX3L       1
#define LKF_MELCHECKFLAG_WX3P_ACCEPTED      2
#define LKF_MELCHECKFLAG_WX3P_EX24          4 /* V2024.0 */

typedef struct {
	int  mel_nr;
	char MEL		 [LKF_AUFENTHALT_ORIGMEL_LEN + 1]; /* V21.2: Laenge 5 -> 11 */
	char ORIG_MEL	 [LKF_AUFENTHALT_ORIGMEL_LEN];
	char MELANZ		 [LKF_AUFENTHALT_MELANZ_LEN];
	char ORIG_MELANZ [LKF_AUFENTHALT_ORIGMELANZ_LEN];
	char MELDAT      [LKF_AUFENTHALT_DAT_LEN];
	char MELPOS      [4];
    char MEL_IDENT    [16]; /* V22.1 */
	char MEL_RELEVANT;
	int  meldat_nr;
	unsigned int nExtOffset;
	int  nMelIndex;
	unsigned int  nMelMelIndex;
	unsigned int  nMelMelNotAccepted;
	unsigned int nTagMelAnz;
	unsigned int nTagMelAnzRelevant;
	int          nIgnoreMel;
	char         cSeite;
    int          nMelAbtIndex;
    /* V21.0 */
    char MELZEIT[5];
    char FCLEIST[LKF_AUFENTHALT_ABTFC_LEN];
    char KALEIST[6];
    char FUCOAUFNR[12]; /* V21.1 */
    int melPlausFlags; /* V21.3 */
    unsigned int  punkteIndex; /* V22.1 */
    unsigned int  gruppeIndex; /* V22.3 */
    unsigned int  significantMELIndex; /* V24.0 */
    unsigned int  nOrigTagMelAnzRelevant;
    long melzu; /* V22.1 */
    char ambGruppe[10]; /* V22.3 */
    char ambKnoten; /* V22.3 */
    char punkteRelevant; /* V22.3 */
    long ambFixPunkte; /* V2019.2 */
    int ambtklmel; /* V2020.0 */
    long long melLongKey; /* V2022.1 */
    char melmelInfo[6]; /* V2023.0 */
    unsigned int nMelMelIndexSep; /* V2023.0 */
} LKF_AUFENTHALT_MEL;

struct LKF_ERROR_LIST {
	int code;
	int index;
	struct LKF_ERROR_LIST *next;
	int nNewError;
	LKF_CONTEXT *pContext;
    const LKF_AUFENTHALT *pAufenthalt;
};

typedef struct {
	char ldf_gruppe[8];
	char ldf_knoten[3];
	long LDFPTK;
	long LDFPLK;
	long SCULK;
	long SCUTK;
	long VDZU;
	long INTZU;
	long MELZU;
	long SCSPEZ;
	long SCGES;
} LKF_AUFENTHALT_SCORING_ORIG;

typedef struct {
	int           code;
	char          value[21]; /* V21.2: laenge 11->21 */
	char          kommentar[201];
	unsigned int  severity;
	char		  s4DigitCode[4];
	unsigned int  nHitCount;
    char          acceptedValue[21]; /* V2022.1 */
    unsigned int  followUpIndex;     /* V2022.1 */
} LKF_AUFENTHALT_AKWARN;

typedef struct {
	char kommentar[201];
} LKF_AUFENTHALT_KOMMENTAR;

typedef struct {
	long         lMelZu;
	int          nDynMelId;
	long         lDynMelDiff;
} MELZU_DATA;

typedef struct {
	int nDynMelId;
	long         lDynMelBonus;
	int lDynMelBonusId;
} MELMEL_OPT_DATA;

typedef struct {
    unsigned int mainMelId;
    unsigned int alternateCount;
    unsigned int *pAlternateIndices;
    MELZU_DATA *pMelzu;
} MELMEL_BOOST;

typedef struct {
	char gruppe[16];
	char diag[14];
	unsigned int anz;
	char knoten_char;
	int mel_id;
	short vd_u;
	short vd_o;
	double vd_mw;
	long leistungs_anteil;
	long MELZU;
    long MELZU_DIRECT; /* V2020.3 */
	long SCUTK;
	double SCUTK_DOUBLE;
	long SCULK;
	long LDFPTK;
	long LDFPLK;
	long VDZU;
	long SCGES;
	double melzu_reduziert;  /* ab Modell 2017: enthaelt den absoluten Wert statt prozentuell */
	int    melzu_voll;
	long lMelDat;
	double mel_median;
	int  nMelMelGrp;
	char bOp;
	MELZU_DATA *pMelZu;
	int TKLModus;
    unsigned int originalIndex;
    unsigned int subgruppeId;
    char subgruppe_ident[32];
    long *plCurMELZU;
} LKF_AUFENTHALT_SUBGRUPPE;

/* Struktur fuer Speicherung der Intensiv-Meldedaten eines Aufenthalts */

typedef struct LKF_INT_AUFENTHALT {
#ifdef SUPPORT_PRE2017
	unsigned int int01_count;			/* Anzahl I01-Saetze */
	unsigned int int02_count;			/* Anzahl I02-Saetze */
	unsigned int int03_count;			/* Anzahl I03-Saetze */
    const char **ppInt01Records;        /* I01-Saetze */
    const char **ppInt02Records;        /* I02-Saetze */
    const char **ppInt03Records;        /* I03-Saetze */
#endif
	unsigned int int11_count;			/* Anzahl I11-Saetze */
	unsigned int int12_count;			/* Anzahl I12-Saetze */
	const char **ppInt11Records;		/* I11-Saetze */
	const char **ppInt12Records;		/* I12-Saetze */
    
    LKF_EXPANDED_LINE **ppInt11;        /* I11-Saetze ab 2017 */
    LKF_EXPANDED_LINE **ppInt12;        /* I12-Saetze ab 2017 */
    
	unsigned int abt_count;				/* Anzahl gemeldeter Abteilungen */
	struct LKF_INT_SCORING_ABT **ppAbt; /* Gemeldete Daten nach Abteilung */
} LKF_INT_AUFENTHALT;

typedef char MELMEL_ERRORCODE[6];

typedef struct {
    unsigned int min_sternkr;
    unsigned int max_sternkr;
    int stern_Diagnose;
    const ICD_LIST_STRING *icd_list_string;
} DIAG_INFO;

/* V2023.0 - SCORING-Detail-Strukturen */

typedef struct {
    char         spezBereich[10];
    long         abtVD;
    long         spezPunkte;
    long         lp100;
    long         tp100;
} LKF_SCORINGDETAILS_ABT;

#define LKF_SCORINGDETAILS_COMMENTLEN      160
#define LKF_SCORINGDETAILS_MAXCOMMENTCOUNT 5

typedef struct {
    int inactive;    // 0 = active, 1 = group, 2 = active
    int subgruppeIndex;
    unsigned int abtIndex;
    int originalMelIndex;
    unsigned int comment_count;
    char comment[LKF_SCORINGDETAILS_MAXCOMMENTCOUNT][LKF_SCORINGDETAILS_COMMENTLEN];
} LKF_SCORINGDETAILS_GROUP;

typedef struct {
    LKF_AUFENTHALT *pAufenthalt;
    long vd;
    LKF_SCORINGDETAILS_GROUP *pCurrentGroup;
    unsigned int isDIAGGroup;
    LKF_SCORINGDETAILS_ABT   *pAbt;
    LKF_SCORINGDETAILS_GROUP *pGroup;
    LKF_SCORINGDETAILS_GROUP *pDiagGroup;
} LKF_SCORINGDETAILS;

#define LKF_AUFENTHALT_CATEGORY_LENGTH           12
#define LKF_AUFENTHALT_CATEGORY_COMMENT_LENGTH   28

typedef struct {
    char code[LKF_AUFENTHALT_CATEGORY_LENGTH];
    char comment[LKF_AUFENTHALT_CATEGORY_COMMENT_LENGTH];
} LKF_AUFENTHALT_CATEGORY;

/* LKF_AUFENTHALT - Struktur zur Speicherung eines gemeldeten Aufenthaltes */

struct LKF_AUFENTHALT {
	char	FLAG;
	char	KANR	[LKF_AUFENTHALT_KANR_LEN_AB2017];
	char	PATID	[LKF_AUFENTHALT_PATID_LEN_AB2017];
	char	GEBDAT	[LKF_AUFENTHALT_DAT_LEN];
	short	Alter;
	char	GESCHL;
	char	STAATB[3];
	char	STAATW[3];
	char	PLZW[6];
	char	AUFART;
	char    AUFDAT	[LKF_AUFENTHALT_DAT_LEN];

	char	AUFART2;
	char    KANR_VON[6];
	char    KANR_AN[6];

	long    lAufDat;
	long    lEntDat;

	LKF_AUFENTHALT_ABT *abt;
	unsigned int abt_anz;
	unsigned int abt_alloc;

	long	GESVD;				/* wird berechnet */
	long	GESVD_KORR;			/* Tage, um die die Gesamtverweildauer bei der Berechnung korrigiert wurde (zB wegen 19*-Abteilungen) */
	char	ENTART;
	char	ENTDAT	[LKF_AUFENTHALT_DAT_LEN];
    char	HD		[LKF_AUFENTHALT_DIAG_LEN];
 /*
 LKF_AUFENTHALT_DIAG *hdiag;
    unsigned int hdiag_alloc;
*/
	
	LKF_AUFENTHALT_DIAG *diag;
	unsigned int diag_anz;
    unsigned int hdiag_anz;
	unsigned int diag_alloc;

	STERNKR_LIST_STRING **sternkr;
    DIAG_INFO **diagInfo;

	LKF_AUFENTHALT_MEL *mel;
	unsigned int mel_anz;
	unsigned int mel_alloc;

	char	KOST[2];
	char	GRP[8];
	char	KNT[2];
	short	VDU;
	short	VDO;
	double	VDMW;
	long	LDFPTK;
	long	LDFPLK;
	long	SCUTK;
	long	SCULK;
	long	VDZU;
	long	INTZU;
	long	MELZU;
	long	SCSPEZ;
	long	SCGES;

	long    SCUTK_TKL;
	long    SCUTK_NOTKL;
	long    SCGES_TKL;

	LKF_AUFENTHALT_AKWARN *akwarn;
	unsigned int akwarn_anz;
	unsigned int akwarn_alloc;
	
	LKF_CONTEXT *pScoringContext;
	int kanr;

	LKF_ERROR_LIST *pFirstError, *pLastError;
	LKF_ERROR_LIST *pFirstWarning, *pLastWarning;
	LKF_ERROR_LIST *pFirstInfo, *pLastInfo;

	short error_flag;
	int plaus_warn, plaus_err, akwarn_count, akerr_count;
	int plaus_info, akinfo_count;

	LKF_ERROR_LIST *pFirstMeldeDiag, *pLastMeldeDiag;
	int melde_count;

	int psych_mode; /* 1...tagesklinisch, 2... tagesstrukt., 0...other */
    int psych_flag; /* V21.2 */

	LKF_AUFENTHALT_SUBGRUPPE *subgruppe;
	unsigned int pat_subgruppen;
	unsigned int subgruppe_alloc;
	unsigned short max_index;

	int optimizeable;
	int optimized_subgruppe;
	double optimized_percentage;

	unsigned int nr;

	char ORIG_PLAUS;
	LKF_AUFENTHALT_SCORING_ORIG *pOrig;
	int status;

	LKF_AUFENTHALT_KOMMENTAR *kommentar;
	unsigned int kommentar_anz;
	unsigned int kommentar_alloc;

	int mark;

	LKF_INT_AUFENTHALT *pIntAufenthalt;
	LKF_LINE_BUFFER *pLineBuffer;

	int nSatzartFirstError;
	int nSatzartNextError;

	unsigned int nSatzartFlags;

	char UCASE_PATID [LKF_AUFENTHALT_LONGID_LEN_AB2017+2];

	char *psLineExt;
	unsigned int nLineExtCount;
	unsigned int nLineExtAlloc;

	unsigned int nM01ExtOffset;
	unsigned int nM06ExtOffset;
	unsigned int nM05ExtOffset;
	unsigned int nM08ExtOffset; /* V16.1 */


	int nStatus;

	unsigned int nMelMelCount;
	unsigned char *pMelMel;
    MELMEL_ERRORCODE *pMelMelInfo;
	double SCUTK_DOUBLE;

	int TKLModus;

	unsigned int acceptedMEL;
    char ALTERSGRUPPE[4];        /* V19.0 */
    
    long lGebDat;  /* V19.0 */
    
    /* V21.0 */
    int isAmb;
    char ABTFC_VON[8];
    char ABTFC_AN[8];
    
    char BEHANDLUNGSART;
    
    char TRANSPORTART;
    char GEMEINDEZIFFER[5];
    
    char AUFZEIT[4];
    char ENTZEIT[4];
    char ABRECH_RELEVANT;
    char KOST_UE[3];
    char ABRECH_QUARTAL[5];
    
    LKF_EXPANDED_LINES *pIntensiv;
    
    int indexInContext; /* V21.3 */
    
    int melabt_ok; /* V2019.0 */
    
    int maxMelIndex;
    
    LKF_SCORINGDETAILS *pScoringDetails; /* V2022.1 */
    
    unsigned int category_alloc;         /* V2025.0 */
    unsigned int category_count;         /* V2025.0 */
    LKF_AUFENTHALT_CATEGORY *pCategory;  /* V2025.0 */
};

#define ACCEPTED_MEL_LH020   1
#define ACCEPTED_MEL_DB020   (1<<1)
#define ACCEPTED_MEL_AJ140   (1<<2)
#define ACCEPTED_MEL_AK010   (1<<3)
#define ACCEPTED_MEL_LH010   (1<<4)
#define ACCEPTED_MEL_LH021   (1<<5)


#define AUFENTHALT_MELMELINDEX(pAufenthalt,i,j) (((pAufenthalt)->mel_anz) * (unsigned int)(i) + (unsigned int)(j))
#define MELMELGROUP_DYN  1
#define MELMELGROUP_WIN  2
#define MELMELGROUP_LOSE 3
/* Spezielle Parameter für Check-Funktionen */

typedef struct 
{
	unsigned int nStringCount;	
	const char  *psValues[40]; /* fixe Dimension fuer gcc etc.) */
} LKF_SATZART_ERRORCHECK_STRINGLIST; /* Parameter für LKF_CHECKFUNC_STRINGLIST (Wert muß ein Wert aus der Liste sein) */

typedef struct
{
	int nMin;
	int nMax;
} LKF_SATZART_ERRORCHECK_INTRANGE; /* Parameter für LKF_CHECKFUNC_INTRANGE (Wert muß in einem Ganzzahl-Bereich liegen) */


typedef struct
{
	char sAbtFC[10];
    const char   *pK01, *pK08, *pK09, *pK10, *pG01, *pA01;
	unsigned int  nK01Len, nK08Len,  nK09Len,  nK10Len, nG01Len, nA01Len;
	char sIntKost[10];
	int nHasM02;
	int nHasM02Jahr;        /* M02-Satz mit Entlassungsdatum ab 1.1. */
	int nHasM02Toleranz;	/* M02-Satz mit Entlassungsdatum ab 15.1. */
	int nVerbleibPat;
	int nBelagstage;
    int lLatestEntDat;
} LKF_KK_CONTEXT_ABTEILUNG;

#define MAX_BERICHT_TYP  4
#define MAX_BERICHT_E   42 /* V2026.1 */
#define MAX_BERICHT_U   24 /* V2019.2 */
#define MAX_BERICHT_Z    6
#define MAX_BERICHT_V   23
#define MAX_BERICHT_K	19

typedef struct
{
	double ev[MAX_BERICHT_E];
	double uv[MAX_BERICHT_U];
	double zv[MAX_BERICHT_Z];
	double vv[MAX_BERICHT_V];
	double kv[MAX_BERICHT_K];
	double ulgfv[MAX_BERICHT_U];
	double r01v;
	int    eok[MAX_BERICHT_E];
	int    uok[MAX_BERICHT_U];
	int    zok[MAX_BERICHT_Z];
	int    vok[MAX_BERICHT_V];
	int    kok[MAX_BERICHT_K];
	int	   ulgfok[MAX_BERICHT_U];
	int    r01ok;
	char   cBerichtsTyp;
} LKF_BERICHT_DATEN;

typedef struct 
{
	const SATZART_INFO *ppKKSatzarten[MAX_K_SATZART_NUM];
	unsigned int pSatzartCount[MAX_K_SATZART_NUM];
	const char **pppSatzartRecords[MAX_K_SATZART_NUM];
    const LKF_EXPANDED_LINE **pppExpandedLines[MAX_K_SATZART_NUM];
    
	unsigned int *ppSatzartRecordLen[MAX_K_SATZART_NUM];

	const SATZART_INFO *ppGGSatzarten[MAX_G_SATZART_NUM];
	unsigned int pGGSatzartCount[MAX_G_SATZART_NUM];
	const char **pppGGSatzartRecords[MAX_G_SATZART_NUM];
	unsigned int *ppGGSatzartRecordLen[MAX_G_SATZART_NUM];
    const LKF_EXPANDED_LINE **pppGGExpandedLines[MAX_G_SATZART_NUM];

	const SATZART_INFO *ppBSatzarten[MAX_B_SATZART_NUM];
	unsigned int pBSatzartCount[MAX_B_SATZART_NUM];
	const char **pppBSatzartRecords[MAX_B_SATZART_NUM];
	unsigned int *ppBSatzartRecordLen[MAX_B_SATZART_NUM];
    const LKF_EXPANDED_LINE **pppBBExpandedLines[MAX_B_SATZART_NUM];

    /* V2026.0 */
    const SATZART_INFO *ppASatzarten[MAX_A_SATZART_NUM];
    unsigned int pASatzartCount[MAX_A_SATZART_NUM];
    const char **pppASatzartRecords[MAX_A_SATZART_NUM];
    unsigned int *ppASatzartRecordLen[MAX_A_SATZART_NUM];
    const LKF_EXPANDED_LINE **pppAExpandedLines[MAX_A_SATZART_NUM];

    
	LKF_KK_CONTEXT_ABTEILUNG *pKKAbteilung;
	unsigned int nAbtCount;
	unsigned int nAbtAlloc;

	unsigned int nCurrentCheckSatzart;
	LKF_KK_CONTEXT_ABTEILUNG *pAktAbteilung;

	int lMBDSStatOk;
	int lBelagsTage;
	int lAufnahmen;
	int lEntlassungen;
	int lVerstorbene;
	int lVerbleib;
    
    int lStatInitialized;

	int lHasUnterUeber;
	LKF_BERICHT_DATEN *pBericht[MAX_BERICHT_TYP];
    LKF_CONTEXT *pContext;
} LKF_KK_CONTEXT;


#define LKF_TRACE_FILENAME_LEN   512

typedef struct
{
	int  nMBDSSeverity;
	int  nIntSeverity;
	int  nKasKoreSeverity;
	char sPATID[LKF_AUFENTHALT_LONGID_LEN_AB2017+1];
	int  bSaveProtocol;
	int  bSafeFile;
	char sFileName[LKF_TRACE_FILENAME_LEN];
	FILE *fp;
	int  bFirst;
    LKFTRACE_DELEGATE traceDelegate; /* V2021.2 */

} LKF_TRACE_SETTINGS;

typedef struct
{
	LKF_CONTEXT    *pContext;
	LKF_AUFENTHALT *pAufenthalt;
	int				si_einheit;
	int				fio2;
	unsigned int    lAbtAufDat;
	unsigned int    lAbtEntDat;
	unsigned int    lLetzteMeldung;
	int			    lSerumBikarbonat;
	char		    cSAPSAufnahmeart;
	unsigned int    nWorstSeverity;
	LKF_KK_CONTEXT *pKKContext;
	int				lCheckFlags;
	char			sErrorAdditionalInfo[128];
	int				nAbtIndex;
	int				bKKTraceDetail;
	int				bKKTraceInfo;
	int				nTraceFacility;
	unsigned int    nBerichtsIndex;
	char			cBerichtsIndexTyp;
	char			sBerichtsTyp[4];
	const LKF_SATZART_ERRORCHECK *pCurrentCheck;
	LKF_BERICHT_DATEN *pAktBericht;

} LKF_CHECK_CONTEXT; /* Context-Information für den Datenintegritäts-Check */

#define CHECKFLAG_SKIP_LINE			1

typedef int (*LKF_SATZART_ERRORCHECK_FUNCTION)(const char *ds, unsigned int len, const SATZART_FELD *pFeld, const LKF_SATZART_ERRORCHECK *pCheck, LKF_CHECK_CONTEXT *check_context);


#define LKF_SATZART_ERRORS_INITIAL 10
#define LKF_SATZART_ERRORS_ADD     20



#define LKF_AUFENTHALT_EXTEND_ABT				3 /* V2026.1 -  memory opt. for large files */
#define LKF_AUFENTHALT_EXTEND_DIAG			    3 /* V2026.1 -  memory opt. for large files */
#define LKF_AUFENTHALT_EXTEND_MEL			    3 /* V2026.1 -  memory opt. for large files */
#define LKF_AUFENTHALT_EXTEND_PAT			 1000
#define LKF_EXTEND_KA                           5

#define LKF_ACCEPTED_MELABT2017                 1 /* V21.4 */

/***********************************************************************************
** Interne Strukturen des Intensiv-Scoring                                        **
***********************************************************************************/
typedef struct {
	int oxygen_index;
	int score;
	int errorstatus;
    int scoreParts[LKF_INT11_MAX_SCORE_FIELDNR + 1]; /* V2019.1 */
} INT01_SCORING_RESULT;

typedef struct {
	int t28_score;
	int errorstatus;
	int ignoreduplicate;
} INT02_SCORING_RESULT;

typedef struct {
	int triss_gcs_total;
	int triss_iss;
	int errorstatus;
} INT03_SCORING_RESULT;

typedef struct LKF_INT_SCORING_ABT 
{
	LKF_AUFENTHALT *pAufenthalt;			/* Zugehoeriger Aufenthalt */
	LKF_AUFENTHALT_ABT *pAbt;			/* Abteilungsdaten */
	char  DISDATE[8];						/* Abgangsdatum aus Abteilungsstammdaten */
	int			 nStartDatum;				/* Start-Datum als Int-Wert */
	int			 nEndDatum;					/* End-Datum als Int-Wert */
	unsigned int nMonat;					/* Monat innerhalb des Abrechnungsjahrs */
	unsigned int nStunden;					/* Stunden (99 bei Mehrtagespatienten) */
	unsigned int nAlter;					/* Alter des Patienten */
#ifdef SUPPORT_PRE2017
	const char **ppInt01Records;			/* Int01-Datensaetze */
	unsigned int nInt01Count;				/* Anzahl Int01-Datensaetze */
	const char **ppInt02Records;			/* Int02_Datensatz */
	unsigned int nInt02Count;				/* Anzahl Int02-Datensaetze */
	const char **ppInt03Records;			/* Int03_Datensatz */
	unsigned int nInt03Count;				/* Anzahl Int03-Datensaetze */
#endif
	unsigned int nIntAbtIndex;				/* Index der zugehörigen Int-Scoring-Abteilung */
	INT01_SCORING_RESULT *pInt01Results;	/* Resultate Int01-Scoring */
	INT02_SCORING_RESULT *pInt02Results;	/* Resultate Int02-Scoring */
	INT03_SCORING_RESULT *pInt03Results;	/* Resultate Int03-Scoring */

	unsigned int nInt11Count;				/* Anzahl Int11-Datensaetze */
	const char **ppInt11Records;			/* Int11-Datensaetze */
	unsigned int nInt12Count;				/* Anzahl Int12-Datensaetze */
	const char **ppInt12Records;			/* Int12-Datensaetze */

	unsigned int nInt01ResultCount;
	unsigned int nInt02ResultCount;
	unsigned int nInt03ResultCount;
    
    LKF_EXPANDED_LINE **ppInt11;            /* Int11-Datensaetze ab Modell 2017 */
    LKF_EXPANDED_LINE **ppInt12;            /* Int12-Datensaetze ab Modell 2017 */

} LKF_INT_SCORING_ABT;

typedef struct {
	unsigned int nInt;
	unsigned int nNeo;
	unsigned int nPed;
	unsigned int nError;
} LKF_INTABT_MONAT;

typedef struct {
	char ABTFC[8];					/* Abteilungs-Funktionscode */
	LKF_INTABT_MONAT Monate[12];	/* Monatsstatistik */
	unsigned int nAufCount;			/* Anzahl gemeldeter Aufenthalte */
	unsigned int nCountPeriode;		/* Anzahl erwarteter Saetze innerhalb der Periode */
	unsigned int nCountKleiner16;	/* Anzahl Saetze mit Alter < 16 Jahren */
	unsigned int nTissTageGesamt;	/* Anzahl TISS-Tage gesamt */
	unsigned int nTissTageFehlend;  /* Fehlende TISS-Tage */
	unsigned int nTISS28Count;      /* TISS28-Count */
	unsigned int nTISS28FCount;		/* TISS28-Count fehlender Saetze */
	unsigned int nTISS28Score;      /* TISS28-Score */
	unsigned int nTISS28FScore;		/* TISS28-Score fehlender Saetze */
	unsigned int nEinstufung;		/* Einstufung */
	unsigned int nTissTagefMW;		/* TISS-Tage fuer Mittelwert */
	unsigned int nTatsBetten;		/* Tatsaechliche Betten */
	unsigned int nMindestStd;		/* Mindeststunden für 0-Tages-Patienten */
	int			 bCompleteTiss;		/* Ersatz-Bewertung bei fehlendem TISS-Satz */
	double       fTissMw;			/* TISS-Mittelwert */
	double		 fKorrFaktor;		/* Korrektur-Faktor */
	char		 sKommentar[80];	/* Kommentar */
	char		 sErhebDatVon[8];	/* Erhebungsdatum von */
	char		 sErhebDatBis[8];	/* Erhebungsdatum bis */
} LKF_INTABT;


#define ABTCOUNT_INITIAL		20
#define ABTCOUNT_EXTEND			20

typedef struct LKF_INT_SCORING {
	LKF_CONTEXT *pContext;			/* LKF-Context-Struktur */
	LKF_INT_SCORING_ABT *pAbt;		/* Abteilungsspezifische Daten des Intensiv-Scoring */
	unsigned int nAbtAlloc;			/* Anzahl angelegte Datensaetze in pAbt */
	unsigned int nAbtCount;			/* Anzahl tatsaechliche Datensaetze in pAbt */
	const SATZART_INFO *pInt01;		/* Struktur der Intensiv-Satzart 1 */
	const SATZART_INFO *pInt02;		/* Struktur der Intensiv-Satzart 2 */
	const SATZART_INFO *pInt03;		/* Struktur der Intensiv-Satzart 3 */
	const SATZART_INFO *pInt11;		/* Struktur der Intensiv-Satzart 11 */
	const SATZART_INFO *pInt12;		/* Struktur der Intensiv-Satzart 12 */
	const SATZART_INFO *pM02;       /* Struktur der Intensiv-Daten des Abteilungsdatensatzes */
	LKF_INTABT *pIntAbt;	        /* Intensiv-Abteilung und Punkte (nach Intensiv-Scoring) */
	unsigned int nIntAbtCount;		/* Anzahl tatsaechliche Datensaetze in pIntAbt */
	unsigned int nMindestStd;		/* IntScor-Parameter: Mindest-Stunden für 0-Tages-Patienten */
	unsigned int bCompleteTiss;		/* IntScor-Parameter: fehlende TISS-Tage auffüllen J/N ? */
	char		 dStartDatum[10];	/* IntScor-Parameter: Beginn der Periode */
	char		 dEndDatum[10];		/* IntScor-Parameter: Ende der Periode */
	int			 nStartDatum;		/* Start-Datum als Int-Wert */
	int			 nEndDatum;			/* End-Datum als Int-Wert */
	int			 bTraceDetail;		/* Trace-Detail-Einstellung */
	int			 bTraceInfo;		/* Trace-Info-Einstellung */
	int          bTraceInput;		/* Trace-Input-Einstellung */
	char         cAufArtSaps;       /* SAPS3-SAPS-Aufart */
} LKF_INT_SCORING;



/*******************************************************************************
** Definition der Stammdaten                                                  **
*******************************************************************************/


#define MAX_KNOTEN		  40

typedef struct LKF_KNOTEN {
	char knoten[8];
    char langtext[256];
	int knoten_anz;
	short nfl[MAX_KNOTEN];
	double median[MAX_KNOTEN];
	short vd_u[MAX_KNOTEN];
	short vd_o[MAX_KNOTEN];
	double vd_mw[MAX_KNOTEN];
	double tk_anteil[MAX_KNOTEN];              /* ab Modell 2017: enthaelt den absoluten Wert statt prozentuell */
	double lk_anteil[MAX_KNOTEN];              /* ab Modell 2017: enthaelt den absoluten Wert statt prozentuell */
    double lk_filterSplit[MAX_KNOTEN];
    double lk_nichtFilter[MAX_KNOTEN];
	char splitmerkmal[MAX_KNOTEN][5];
	short merkmals_typ[MAX_KNOTEN];
	char mk[MAX_KNOTEN][8];                    /* diesem Feld werden nur char 8 strings zugewiesen*/
	char knoten_char[MAX_KNOTEN];
	short Intervall[2][6];
	double melzu_reduziert[MAX_KNOTEN];        /* ab Modell 2017: enthaelt den absoluten Wert statt prozentuell */
} LKF_KNOTEN;


#define LKF_MEL_FLAG_REVISION       1
#define LKF_MEL_FLAG_NOAUFDATE      2
#define LKF_MEL_FLAG_NOAUFDATE2017  4

#define LKF_MELMELINFOSTRING_LEN    10

typedef struct LKF_MEL_CUSTOM_CHECK {
    int (*checkFunction)(LKF_AUFENTHALT *, unsigned int i, int nMelAbtIndex);
    const LKF_SATZART_ERRORDEF *pError;
    const char *description;
    struct LKF_MEL_CUSTOM_CHECK *nextTrue;
    struct LKF_MEL_CUSTOM_CHECK *nextFalse;
} LKF_MEL_CUSTOM_CHECK;

typedef struct MEL_CUSTOM_CHECKFUNCTION_DESCRIPTION {
    int (*checkFunction)(LKF_AUFENTHALT *, unsigned int i, int nMelAbtIndex);
    const char *description;
} MEL_CUSTOM_CHECKFUNCTION_DESCRIPTION;

typedef struct {
	char MEL[LKF_AUFENTHALT_NEWMEL_LEN];
	int mel_anz;
	int mel_warn;
	unsigned int mel_diag_ug;
	unsigned int mel_diag_og;
	unsigned int flags; /* V7.2: fuer NP-Plaus */

	int isValid;

	unsigned int nBDmin; 
	unsigned int nBDmax;
	char cGeschlecht;
	char cAmbulant;
	char cBdgr0;
	char cTKL;
    char cAmbModus2;
	int nAltermin;
	int nAltermax;

	char sGruppe[10];
    char sAmbGruppe[10]; /* V21.0: Ambulante Gruppe */
	char sLGR[6];
    char sAmbLeistGrp[6]; /* V21.0 Ambulante Leistungsgruppe */
    int amb_melanz_warn;  /* V21.0 */
    int amb_melanz_error; /* V21.0 */
    char cStatVerpflichtend; /* V21.0 */
    char cDiagVerpflichtend; /* V21.0 */
    char cBettFC; /* V2019.1 */

	int tag_mel_anz;
	int tag_mel_warn;

	char cOp;
	char cSeite;
    char cLE; /* V2024.1 */
	char cDisableLimitCheck; /* V18.2 */
    
    char cPhysAnw; /* V2022.0 */
    
    int melflags;        /* V19.0 */
    int ambFixPunkte; /* V2019.0 */
    
    char sText[102]; /* V2022.0 */
    
    unsigned int melmelInfoCount; /* V2024.0 */
    unsigned int melmelInfoAlloc; /* V2024.0 */
    char *melmelInfo; /* V2024.0 */
    
    const LKF_MEL_CUSTOM_CHECK *pCustomCheck;
    
} MEL_ARRAY_STRUC;

typedef struct {
	int mel_max;
	int mel_min;
	char hdg_min[3];
	char hdg_max[3];
	char hdg4_min;
	char hdg4_max;
} MEL_DIAG_STRUC6;

#define NPPLAUS_KOMBKZ_LEN 10

typedef struct {
	char DIAG[LKF_AUFENTHALT_DIAG_LEN+1];
	char KOMBKZ[NPPLAUS_KOMBKZ_LEN+1];
	long FlagsNeonIntBeh; /* Flags fuer Neonatologie Intensivbehandlung */
	long FlagsNeonIntUeb; /* Flags fuer Neonatologie Intensivueberwachung */
	long FlagsPaedIntBeh; /* Flags fuer Paediatrische Intensivbehandlung */
	long FlagsPaedIntUeb; /* Flags fuer Paediatrische Intensivueberwachung */
} NPPLAUS_STRUC;


#define LKF_WARNING_OFFSET 200 /* V18.0 */

typedef struct {
	unsigned int errordef_count;					 /* Anzahl enthaltene Errors */
	const LKF_SATZART_ERRORDEF **ppErrorDef;		 /* Errors */

	unsigned int errordefindex_count;				 /* Referenz auf Errors per Index - maximale Anzahl */
	const LKF_SATZART_ERRORDEF **ppErrorDefIndex;	 /* Errors per Index */

	unsigned int min_error,
				 max_error, 
				 min_warning, 
				 max_warning;

} LKF_ERRORGROUP; /* Definiert eine Gruppe von Errors (Warnings) */

/* STAMM2001 - Abspeicherung der Stammdaten zu einem Modelljahr */

#define MEL_INDEX_LIST_COUNT 16 /* V22.0 */
#define MEL_NPPLAUS_IB3      0
#define MEL_NPPLAUS_IB11     1
#define MEL_NPPLAUS_IB13     2
#define MEL_NPPLAUS_PU5      3
#define MEL_NPPLAUS_PB4      4
#define MEL_NPPLAUS_PB5      5
#define MEL_PLAUS_PSYCH1     7
#define MEL_PLAUS_PSYCH2     8
#define CONSTMEL_LIST1		 9
#define CONSTMEL_LIST2      10
#define MEL_NICHTREDUZIERT  11
#define CONSTMEL_LIST3      12
#define CONSTMEL_LIST4      13
#define MEL_LEIST50_LIST    14
#define CONSTMEL_LIST5      15

#define CONSTMEL_AM030_7501 ((CONSTMEL_LIST1<<8)+0)
#define CONSTMEL_AM020_7506 ((CONSTMEL_LIST1<<8)+1)
#define CONSTMEL_AA040_7401 ((CONSTMEL_LIST1<<8)+2)
#define CONSTMEL_AM040_7316 ((CONSTMEL_LIST1<<8)+3)
#define CONSTMEL_AM050_7321 ((CONSTMEL_LIST1<<8)+4)
#define CONSTMEL_LH020_1255 ((CONSTMEL_LIST1<<8)+5)
#define CONSTMEL_DB020      ((CONSTMEL_LIST1<<8)+6)
#define CONSTMEL_TEST_7591  ((CONSTMEL_LIST1<<8)+7)
#define CONSTMEL_TEST_7592  ((CONSTMEL_LIST1<<8)+8)
#define CONSTMEL_AM060_7596 ((CONSTMEL_LIST2<<8)+0)
#define CONSTMEL_AM070_7597 ((CONSTMEL_LIST2<<8)+1)
#define CONSTMEL_AM080_7598 ((CONSTMEL_LIST2<<8)+2)
#define CONSTMEL_AM090_7601 ((CONSTMEL_LIST2<<8)+3) 
#define CONSTMEL_AM110      ((CONSTMEL_LIST2<<8)+4) 
#define CONSTMEL_ZZ020_7250 ((CONSTMEL_LIST3<<8)+0)
#define CONSTMEL_AJ140      ((CONSTMEL_LIST3<<8)+1)
#define CONSTMEL_AK010      ((CONSTMEL_LIST3<<8)+2)
#define CONSTMEL_LH010      ((CONSTMEL_LIST3<<8)+3)
#define CONSTMEL_LH021      ((CONSTMEL_LIST3<<8)+4)
#define CONSTMEL_AM100		((MEL_PLAUS_PSYCH2<<8)+1)
#define CONSTMEL_AM120      ((CONSTMEL_LIST4<<8)+0)
#define CONSTMEL_AM130      ((CONSTMEL_LIST4<<8)+1)
#define CONSTMEL_ZZ050      (CONSTMEL_LIST5<<8)
#define CONSTMEL_AM140      ((CONSTMEL_LIST5<<8)+1)
#define CONSTMEL_AM150      ((CONSTMEL_LIST5<<8)+2)

#define IS2017ORLATER(pAufenthalt) ((pAufenthalt)->pScoringContext->modelljahr >= 2017)
#define SAFEIS2017ORLATER(pAufenthalt) ((pAufenthalt) && (pAufenthalt)->pScoringContext && (pAufenthalt)->pScoringContext->modelljahr >= 2017)
#define SAFEIS2018ORLATER(pAufenthalt) ((pAufenthalt) && (pAufenthalt)->pScoringContext && (pAufenthalt)->pScoringContext->modelljahr >= 2018)
#define SAFEEXPORTMELPOS(pAufenthalt) ((pAufenthalt) && (pAufenthalt)->pScoringContext && ((pAufenthalt)->pScoringContext->flags & LKFCONTEXT_EXPORT_MELPOS))
#define FILL_ALTERSGRUPPE(pAufenthalt) ((pAufenthalt)->pScoringContext->modelljahr >= 2017) /* V21.2 */

typedef struct {
	SPEZ_LIST_STRING *spez_list;
	unsigned int spez_gesamt;

	LAND_LIST_STRING *land_list;
	unsigned int land_gesamt;
	LAND_LIST_STRING *landAT;

	PLZ_LIST_STRING *plz_list;
	unsigned int plz_gesamt;

	FUNK_LIST_STRING *funk_list;
	unsigned int funk_gesamt;
	int *funk_quick;

	KOST_LIST_STRING *kost_list;
	char **kost_list2;
	unsigned int kost_gesamt;

	KA_LIST_STRING *ka_list;
	unsigned int ka_gesamt;
	
	KTR_LIST_STRING *ktr_list;
 	unsigned int ktr_gesamt;

	KA_LIST_STRING *ka_list_alternate;
	unsigned int ka_alternate_gesamt;

	ICD_LIST_STRING *icd_list;
	unsigned int icd_gesamt;
    DIAG_INFO *diag_info;                  /* V18.0 */

	NPPLAUS_STRUC *pNPPlaus;
	unsigned int npplaus_gesamt;

	STERNKR_LIST_STRING *sternkr_list;
	unsigned int sternkr_gesamt;

	MEL_ARRAY_STRUC *mel_array;
	unsigned int mel_list_gesamt;

	MEL_KA_STRING *mel_tkl;
	unsigned int   mel_tkl_gesamt;    
	int mel_tkl_fehler;

	MEL_KA_STRING *mel_ka;
	unsigned int mel_ka_gesamt;

	MEL_MEL_STRING *mel_mel;
	unsigned int mel_mel_gesamt;

	MEL_DIAG_STRING *mel_diag;
	MEL_DIAG_STRUC6 *mel_diag6;

	unsigned int mel_diag_gesamt;

	OEMELKA_STRING *oe_mel_ka;
	unsigned int oe_mel_ka_gesamt;

		/* V18.0 - DIAGMEL */
	DIAG_MEL_STRING *diag_mel;
	unsigned int diag_mel_gesamt;

	/* V18.0 - DIAGDIAG */
	DIAG_DIAG_STRING *diag_diag;
	unsigned int diag_diag_gesamt;

    /* V21.0 - GEMEINDEZIFFER */
    GKZ_LIST_STRING *gkz_list;
    unsigned int gkz_list_gesamt;
    
    /* V2026.0 - ATCLIST */
    ATCLIST_STRING *atc_list;
    unsigned int atc_list_gesamt;
    
    /* V21.2 - PLZ-GEMCO */
    PLZ_GEMCO_STRING *plz_gemco_list;
    unsigned int plz_gemco_gesamt;

	char *input_path;

	char errortext[512]; /* V2019.3 - Text laenger */

	/* Caching der Haupt- und MEL-Gruppen */
	LKF_KNOTEN **ppKnoten;      
	unsigned int knoten_alloc;
	unsigned int knoten_gesamt;

	LKF_ERRORGROUP *pMBDSErrors;

	unsigned int lGGArtAnz, lGGLeistAnz;
	GGART_STRING   *sGGArt;
	GGLEIST_STRING *sGGLeist;

	LKF_SATZART_ERRORINFO_LIST *pAllErrors;

	int nNPDisabled; /* wenn keine NP-Dateien vorhanden sind, ist die Abrechnung nur für Nicht-Fonds-Haus gestattet */
	int nOSGDisabled; /* wenn die Stammdaten-Datei OEMELKA.dat nicht vorhanden ist, ist die OEMELKA-Überprüfung nicht möglich */

	int *ppMelIndexLists[MEL_INDEX_LIST_COUNT];

	OEKASO_STRING *oekaso;
	unsigned int oekaso_gesamt;

	unsigned int nModellJahr;
    
    STAMM_ADD_LINE_FUNC stammAddLineFunc;
    STAMM_FILE_PATH_FUNC stammFilePathFunc;
    LKF_CONTEXT *pScoringContext;
    
    char *melmelInfoBuffer;
} STAMM2001;

typedef struct {
    FILE *fp;
    STAMM2001 *pStamm;
    char fileName[32];
    char error[1024];
    int add;
	char* fileContent;
	int fileContentPos;
	int fileContentLen;
} STAMM_FILE;

/****************************************************************************
** Statistik-Strukturen (stat5.c)                                          **
****************************************************************************/

typedef struct
{
	unsigned int nFieldNr;				/* Statistik-Feld-Nummer */
	const char *sShort;					/* Kurzbeschreibung des Auswertungsfelds */
    const char *sDescription;			/* Beschreibung des Auswertungsfelds */
} LKF_STAT_FIELD; /* Beschreibt ein Statistik-Feld */

typedef struct 
{
	unsigned int nCount;				/* Anzahl Felder in der Statistik-Feldgruppe */
	const LKF_STAT_FIELD *pFields[10];	/* Felder in der Statistik-Feldgruppe; V12.1 - fixe Dimension fuer gcc etc.) */
} LKF_STAT_FIELDGROUP; /* Beschreibt eine Statistik-Feldgruppe */

typedef struct
{
	char sInfo[20];							/* Interne Information (zB ABTFC für Abteilungs-Zähler) */
	const LKF_STAT_FIELDGROUP *pFieldGroup; /* Zugehörige Feldgruppe */
	unsigned int *pCounter;					/* Die zugehörigen Counter */
} LKF_STAT_COUNTER; /* Statistik-Zähler einer Kategorie */

typedef struct
{
	unsigned int nCount;             /* Anzahl Bereiche für Aggregation */
	unsigned int nType;		         /* 0 = Integer-Grenzen, 1 = Diskrete Werte */
	const int  *pIntGrenzen;         /* Integer-Grenzen */
	const char **sCharWerte;	     /* Diskrete-Zeichenwerte */
	const char **sDescription;       /* Beschreibung der einzelnen aggregierten Werte */ 
} LKF_STAT_AGGREGATION_INFO; /* Beschreibt die Information über Grenzen einer Aggregation */

typedef struct
{
	const LKF_STAT_AGGREGATION_INFO *pAggregationInfo;	/* Beschreibung der Aggregation */
	const LKF_STAT_FIELDGROUP       *pFieldGroup;		/* Field Group */
	unsigned int					nCount;				/* Anzahl Counter-Strukturen */
	LKF_STAT_COUNTER				**ppCounter;		/* Zähler */
} LKF_STAT_AGGREGATION; /* Struktur für aggregierte Ergebnisse */

typedef struct
{

	unsigned int nIgnoreErrors;							 /* Alle Aufenthalte werden berechnet, auch wenn sie nach Plaus-Check fehlerhaft sind */
	unsigned int nIgnoreMark;							 /* Alle Aufenthalte werden berechnet, auch wenn sie nicht markiert sind */

	const LKF_STAT_FIELDGROUP *pKADef;					 /* Definition der Krankenanstalt-Statistiken */
	const LKF_STAT_FIELDGROUP *pAbtDef;					 /* Definition der Abteilungs-Statistiken */

	const LKF_STAT_FIELDGROUP *pAlterDef;				 /* Altersdefinitionen */
	const LKF_STAT_FIELDGROUP *pHauptWohnsitzDef;		 /* Hauptwohnsitzdefinition */
	const LKF_STAT_AGGREGATION_INFO *pAlterAggr;		 /* Alters-Aggregatsdefinition */
	const LKF_STAT_AGGREGATION_INFO *pHauptWohnsitzAggr; /* Hauptwohnsitz-Aggregatsdefinition */

	int KAFieldId[LKF_STAT_MAXSTATFIELD+1];			     /* Ids der Statistik-Felder im Ergebnis für KA-Stat*/
	int AbtFieldId[LKF_STAT_MAXSTATFIELD+1];			 /* Ids der Statistik-Felder im Ergebnis für Abteilungen */
	int AlterFieldId[LKF_STAT_MAXSTATFIELD+1];		     /* Ids der Statistik-Felder im Ergebnis für Alter */
	int HauptWohnsitzFieldId[LKF_STAT_MAXSTATFIELD+1];   /* Ids der Statistik-Felder im Ergebnis für Hauptwohnsitz */

	LKF_STAT_COUNTER *pKACounter;						 /* Krankenanstalt-Statistiken */
	
	unsigned int nAbtCount;								 /* Anzahl Abteilungen */
	unsigned int nAbtAlloc;								 /* Reservierte Abteilungen */
	LKF_STAT_COUNTER **ppAbtCounter;					 /* Statistiken pro Abteilung */

	LKF_STAT_AGGREGATION *pAlter;						 /* Alters-Statistiken */
	LKF_STAT_AGGREGATION *pHauptWohnsitz;				 /* Hauptwohnsitz-Statistiken */

	unsigned int lFirstDay;								 /* Erster Tag des Jahres */
	unsigned int lLastDay;								 /* Letzter Tag des Jahres */

	int nModelljahr;                                     /* Modelljahr */
    
    LKF_CONTEXT *pContext;

} LKF_STAT;												 /* Speicherung aller statistischen Daten */

typedef struct {
    unsigned int category_alloc;
    unsigned int category_anz;
    LKF_CASESTAT_CATEGORY *pCategories;
} LKF_CASESTAT;

/****************************************************************************
** Definition des SCORING-CONTEXTS                                         **
****************************************************************************/

typedef struct {
	char		 abt_fc[8];  /* Funktionscode der Abteilung */
	unsigned int abt_bd;     /* Belagsdauer-Summe der Abteilungen */
	unsigned int abt_patanz; /* Anzahl Patienten der Abteilung */
	unsigned int abt_error;  /* Aufgetretene Fehlermeldungen pro Abteilung */
} STAT_ABTEILUNG;

typedef struct {
	char ka[5];
	unsigned int anz;
	unsigned int filter_anz;

	double	LDFPTK;
	double	LDFPLK;
	double	SCUTK;
	double	SCULK;
	double	VDZU;
	double	INTZU;
	double	MELZU;
	double	SCSPEZ;
	double	SCGES;

	double  SCGES_INLKF;
	double  SCGES_EXLKF;

	double SCUTK_TKL;
	double SCGES_INLKF_TKL;
	double SCGES_EXLKF_TKL;

	long optimizeable;
	long optimized;
	double optimized_actpunkte;
	double optimized_maxpunkte;


	long error_anz;
	long warning_anz;
	long akwarn_anz;
	long akerr_anz;

	long info_anz;
	long akinfo_anz;

	long melde_count;

	unsigned int *error_counts, *warning_counts;
	unsigned int error_code_min, error_code_max; 
	unsigned int warning_code_min, warning_code_max;

	STAT_ABTEILUNG *abt;
	unsigned int abt_gesamt;
	unsigned int abt_alloc;

    double SCGES_AMB; /* V21.0 */
    
} STAT_KA; /* Statistiken zu einer Krankenanstalt (vor Modell 2004 wurden mehrfach gemeldete KAs unterstützt) */

typedef struct LKF_CONTEXT_ABTEILUNG
{
	unsigned int nEintrag;
	char sAbtFC[10];
	char sKst8[10];
	char sKANR6[8]; /* KANR der Abteilung inklusive Standort (6stellig) */
} LKF_CONTEXT_ABTEILUNG;

typedef struct
{
	unsigned int nLine;
	const SATZART_FELD *pFeld;
	const LKF_SATZART_ERRORDEF *pErrorDef;
	const SATZART_INFO *pSatzartInfo;
    char text[32];
} LKF_IMPORTERROR_STRUC; /* Speichert einen beim Import entdeckten Fehler */


typedef struct
{
	const char *mel;
    const char *melkz;
	int         ok;
} LKF_CONTEXT_SPEZMEL;

typedef struct
{ /* V2020.0 */
    unsigned int spezmelindex;
    char ka[4];
} LKF_CONTEXT_OTHERKA_SPEZMEL;

typedef struct {
    char abtfc[10];
    int lAmbCounter[4];
} LKF_CONTEXT_ABTFC_STAT;

/* V21.0: Memory-Management */

#define LKF_MEMORYBLOCK_LENGTH 100000
#define LKF_MEMORYBLOCK_EXTEND     10

typedef struct {
    char *buf;
    unsigned int offset;
    unsigned int len;
} LKF_MEMORYBLOCK;

typedef struct {
    char fileName[20];
    unsigned int lineCount;
    char *buf;
    unsigned int *lineOffsets;
} LKF_CONTEXT_DATFILE;

#define LKF_MAX_IMPORTERRORS 100 /* V19.0 */

struct LKF_CONTEXT {
	int modelljahr;

	int  cmb_jahr;
	char period_type;
	int  period_val;
	int  lfdnr;

	int  flags;

	LKF_AUFENTHALT **ppAufenthalt;
	unsigned int patient_alloc;
	unsigned int patient_anz;

	STAT_KA *ka;
	unsigned int ka_gesamt;
	unsigned int ka_alloc;

	STAMM2001 *pStamm2001;

	unsigned int plaus_count;
	unsigned int scor_count;
	unsigned int plaus_work_count;
	unsigned int scor_work_count;

	unsigned int custom_field_anz;
	unsigned int *custom_fields;
	char custom_char;
	int custom_flags;

	/* Private Kost-List */ 
	KOST_LIST_STRING *kost_list;
	char **kost_list2;
	unsigned int kost_gesamt;
    unsigned int kost_alloc;
	int kost_sorted;

	/* Private Spez-List */
	SPEZ_LIST_STRING *spez_list;
	unsigned int spez_gesamt;
	unsigned int spez_alloc;
	int spez_sorted;

	/* Private MEL-KA-List */
	MEL_KA_STRING *mel_ka;
	unsigned int mel_ka_gesamt;
	unsigned int mel_ka_alloc;
	int mel_ka_sorted;
    
    /* V2021.3: Private OEMELKA-List */
    OEMELKA_STRING *oemelka;
    unsigned int oemelka_gesamt;
    unsigned int oemelka_alloc;
    int oemelka_sorted;

	/* Satzart D - Systeminfo */
	char systeminfo[400];

	/* Errortext */
	char errortext[512]; /* V2019.3 - Text laenger */
    char outOfMemory[512];
	/* V7.2: NPPlaus */
	char sNPPlausTraceFilename[1024];
	FILE *npplaus_tracefile;

	LKF_LINE_BUFFER *pLineBuffer;
    LKF_EXPANDED_LINES *pExpLineBuffer;
	LKF_SATZART_ERRORS *pSatzartErrors;
	unsigned int nInputErrorCount;

	unsigned int nFilteredErrors;
	LKF_SATZART_ERROR **ppFilteredErrors;
	LKF_SATZART_ERRORINFO_LIST *pFilterErrorInfo;
    LKF_SATZART_ERRORINFO_LIST *pFullErrorCounters; /* V21.5 */
    unsigned int sumErrorCount;   /* V21.5 */
    unsigned int sumWarningCount; /* V21.5 */

	NPPLAUS_CONTEXT *pNPPlausContext;

    unsigned int Count_X[MAX_X_SATZART_NUM];    /* V21.0: X-Records */
	unsigned int Count_M[MAX_M_SATZART_NUM];	/* Counter fuer MBDS-Saetze */
	unsigned int Count_I[MAX_I_SATZART_NUM2011];	/* Counter fuer Intensiv-Saetze */
	unsigned int Count_L[MAX_L_SATZART_NUM];	/* Counter fuer Spez. Saetze */
	unsigned int Count_K[MAX_K_SATZART_NUM];	/* Counter fuer K-Saetze */
	unsigned int Count_G[MAX_G_SATZART_NUM];	/* Counter fuer Grossgeraete-Saetze */
	unsigned int Count_S[MAX_S_SATZART_NUM];	/* Counter fuer Summen-Saetze */
	unsigned int Count_B[MAX_B_SATZART_NUM];
    unsigned int Count_O[MAX_O_SATZART_NUM];
    unsigned int Count_A[MAX_A_SATZART_NUM];
    unsigned int nReplaceSummensatz;

	LKF_INT_SCORING *pIntScoring; 

	LKF_CONTEXT_ERRORFORMAT *pErrorFormats[LKF_FAC_ALLOC]; 

	unsigned int compatibility;

	char KANR[8]; 
	int  nHasFAT0; /* V12.0 */
	int  nHasFAT1; /* V12.0 */
	int  nHasFAT5; /* V12.0 */
    unsigned int nSumImportErrors; /* V19.0 */
    
	LKF_LINE_BUFFER *pErrorLineBuffer; 
	LKF_CHECK_CONTEXT *pCheckContext;

	LKF_IMPORTERROR_STRUC *pImportError; 
	unsigned int nImportErrorAlloc;		 
	unsigned int nImportErrorCount;		 

	const LKF_SATZART_DEFS *pSatzartDefs; 
    const SATZART_INFO *pX01;
    const SATZART_INFO *pX02;
    const SATZART_INFO *pX03;
    const SATZART_INFO *pX04;
    const SATZART_INFO *pX05;
    const SATZART_INFO *pX06;
    const SATZART_INFO *pX07;

	LKF_STAT *pLKFStat; 

	MEL_KA_STRING *mel_tkl; 
	unsigned int   mel_tkl_gesamt; 
	unsigned int   mel_tkl_alloc; /* V11.0 */
	int mel_tkl_sorted; 

	LKF_TRACE_SETTINGS *pTraceSettings; /* V10.1 */
	LKF_LINE_BUFFER    *pTraceLineBuffer; /* V10.1 */

	int nTraceAufenthalt; /* V10.1 */
	int nTraceAufenthaltIntScor; /* V11.0 */
	int nCurrentFacility; /* 10.2 */

	LKF_CONTEXT_ABTEILUNG *pAbt; /* V11.0 */
	unsigned int nAbtAlloc;		 /* V11.0 */
	unsigned int nAbtAnz;        /* V11.0 */

	unsigned int isKTR;          /* V14.2 */

	unsigned int spezMelCount;     /* V16.0 */
	LKF_CONTEXT_SPEZMEL *spezMels; /* V16.0 */
    
    LKF_CONTEXT_OTHERKA_SPEZMEL *otherKASpezMel;
    unsigned int otherspezalloc;
    unsigned int otherspezcount;
    
    LKF_CONTEXT_ABTFC_STAT *abtFCStat;  /* V2020.1 */
    unsigned int abtfcstatalloc;        /* V2020.1 */
    unsigned int abtfcstatcount;        /* V2020.1 */
    
    int isBM; /* V19.0 */
    int standortInfo; /* V19.0 */
    const SATZART_FELD **patidPos; /* V19.0 */
    unsigned int m02_intlen; /* V19.0 */
    
#ifdef USE_LKF_MEMORYBLOCK
    unsigned int memoryblock_alloc;
    unsigned int memoryblock_count;
    LKF_MEMORYBLOCK *pMemoryBlocks;
    LKF_MEMORYBLOCK *pCurrentBlock;
#endif

    int utf8_mode;
    char sErrorBuf[256];
    
    int model2017errors; /* V21.0 */
        
    LKF_CONTEXT_DATFILE *pDatFile; /* V21.2 */
    
    int scoring_stat_initialized;
    int lAmbCounter[4]; /* V22.0 / V2019.0 -> 4 */
    
    STAMM_ADD_LINE_FUNC stammAddLineFunc;
    STAMM_FILE_PATH_FUNC stammFilePathFunc;
    int privateStamm;

	int importedILines;
	int failedILines;
	int zuordnungILine;
    
    int noStamm;
    
    LKF_CASESTAT *pCaseStats;
    
    unsigned int counter0;
    unsigned int counter1;
    unsigned int counter2;
    
    int executionCalled;
};

struct LKF_METADATA {
    unsigned int modelYear;
    char path[512];
    STAMM2001 *pStamm;
};

#define LKF_CONTEXT_EXTEND_ABT     20

struct LKF_ANONYMISATION_CONTEXT {
    LKF_CONTEXT *targetContext;
    char KANR[8];
    int aufaddyears;
    int dates;
    int nextKey;
    int k01only;
    
    char STAATW[4];
    char STAATB[4];
    char PLZW[8];
    char GEMCODE[6];
    
    int ambToStat;
    int statToAmb;
};


/**********************************************************
** Diverse Dimensionen                                   **
**********************************************************/

#define MAX_MEL_DIAG     60000

/* V14.0 - Unterbrechung stat. Aufenthalte */
#define UNTERBRECHUNG_ABTFC "10000000"
#define UNTERBRECHUNG_LEN   6

typedef struct {
    int flags;
    
    LKFMEMORY_DELEGATE memory_delegate;
    int delegateFlags;
    
    size_t availableMemory;
    size_t usedMemory;
    char breakingFunction[256];
    int breakingCount;
    int breakingHitCount;
    
    char logFileName[128];
    
    long long open_ptr;
    int linecount;
    long long open_memory;

    int called;
    FILE *fp;
    
} LKF_MEMORYSETTINGS;


#define LKF_MEMORYSETTINGS_LOG              1
#define LKF_MEMORYSETTINGS_BOUNDS_CHECK    32

#define LKF_MEMORYSETTINGS_DEBUG_MEMORY     4
#define LKF_MEMORYSETTINGS_LIMIT            512

//#define LKF_MEMORY_USEDIRECT 1


#ifdef LKF_MEMORY_USEDIRECT
#define LKF_MALLOC(ctx,k,l)        malloc(l)
#define LKF_CALLOC(ctx,k,nr,siz)   calloc((nr), (siz))
#define LKF_REALLOC(ctx,k,p,siz)   realloc((p), (siz))
#define LKF_FREE(ctx,k,p)          free (p)
#else
#define LKF_MALLOC(ctx,k,l)            lkf_malloc((ctx),(k),(l))
#define LKF_CALLOC(ctx,k,nr,siz)    lkf_calloc((ctx),(k),(nr),(siz))
#define LKF_REALLOC(ctx,k,p,siz)    lkf_realloc((ctx),(k),(p),(siz))
#define LKF_FREE(ctx,k,p)            lkf_free((ctx),(k),(p))
#endif



void *lkf_malloc (LKF_CONTEXT *pContext, const char *key, size_t siz);
void *lkf_calloc (LKF_CONTEXT *pContext, const char *key, size_t siz, size_t nr);
void *lkf_realloc (LKF_CONTEXT *pContext, const char *key, void *p, size_t siz);
void lkf_free (LKF_CONTEXT *pContext, const char *key, void *p);

/* Basis-Routinen (utils5.c) **************************************************/
#define IsBlank(t,l) IsEmpty(t,l) /* V5.1 */
int IsEmpty (const char *text, int len);
#define GetInt lkf_GetInt
int GetLength (const char *src, int len);
int GetDate8 (const char *text, int *year, int *month, int *day);
int GetDate8Strict (const char *text, int *year, int *month, int *day); /* V2025.0 */
void UCase(char *ps, int len);
void CopyUCase (char *dest, const char *src, unsigned int len);
void CopyUCaseLTrim (char *dest, const char *src, unsigned int len);
void Util_FC_Nullen(char *pDest, const char *pSrc);
void Util_Datum_Nullen(char *pDest, const char *pSrc);
int Util_Datum_Format (const char *datum);
long Util_Diff_Tage(LKF_AUFENTHALT *pAufenthalt, short abtidx);
long Util_Alter (LKF_AUFENTHALT *pAufenthalt);
long Util_Alter_Abteilung (LKF_AUFENTHALT *pAufenthalt, const char *abtdat); 
int DayOfYear (int year, int month, int day);
int SmallerDate8 (const char *date1, const char *date2);
int GetYearDiffDate8 (const char *date1, const char *date2);
long DatJul (int year, int month, int day);
int simLTrim(char *pDes, const char *pSrc, int srclen);
int simTrim (char *pDes, const char *pSrc, int srclen);
int UtilICDIndex (const char *icd_text);
int HasBlanks (const char *src, unsigned int len);
int TrimEqual (const char *str, int len, const char *cmp);
double simVal(const char *str, int strlen);
int CompareUCase (const char *cand, const char *patt, int len);
long simCLng(double dNumber);
int TrimCompare (const char *str, int len, const char *cmp, char krit);
int TrimWildcardEqual (const char *str, int len, const char *cmp);
int expand_string (const char *src, int len, char *buf);
const char *get_string_ext (const char *src, unsigned int offset); /* V11.1 */
void CopyLTrim (char *dest, const char *src, unsigned int len); /* V6.0 */
int lkf_mel_chronodays (LKF_AUFENTHALT *pAufenthalt, int mel); /* V6.0 */
int lkf_mel_chronodays_new (LKF_AUFENTHALT *pAufenthalt, int melindex); /* V13.0 */
void CopyTrimNull (char *dest, const char *src, unsigned int len); /* V7.2 */
LKF_LINE_BUFFER *lkf_create_linebuffer (LKF_CONTEXT *pContext);
void lkf_drop_linebuffer (LKF_CONTEXT *pContext, LKF_LINE_BUFFER *pBuffer); 
unsigned int lkf_add_dynamic_line (LKF_CONTEXT *pContext, LKF_LINE_BUFFER *pLineBuffer, const char *sBuf);
const char *lkf_get_line (LKF_LINE_BUFFER *pBuffer, unsigned int index); /* V8.0 */
int lkf_get_linelen (LKF_LINE_BUFFER *pBuffer, unsigned int index); /* V8.0 */
long lkf_time2int (const char *tim); 
long lkf_time2intStrict (const char *tim); /* V2025.0 */
long lkf_dat2int (const char *dat); /* V6.0 */
long lkf_dat2intStrict (const char *dat); /* V2025.0 */
char *lkf_int2dat (long lDat, char *sDatBuf); /* V11.0 */
char *lkf_int2dat8 (long lDat, char *sDatBuf); /* V2024.1 */
void DatLongToYMD (long lDate, int *pYear, int *pMonth, int *pDay); /* V11.0 */
unsigned int Copy (char *dest, const char *src, unsigned int len); /* V15.0 */
long lkf_str2int (const char *str, unsigned int len);

/* Routinen zur Bearbeitung des Patienten-Records (auf5.c) *********************/
void lkf_aufenthalt_plaus_init (LKF_AUFENTHALT *pAufenthalt);
void lkf_sort_auf_abt (LKF_AUFENTHALT *pAufenthalt);
int lkf_auf_getidfrompos (LKF_AUFENTHALT *pAufenthalt, const char *pos); 
int lkf_auf_getidfrompos_2017 (LKF_AUFENTHALT *pAufenthalt, const char *pos);
unsigned int lkf_auf_add_ext_len (LKF_AUFENTHALT *pAufenthalt, const char *sBuf, unsigned int nBufLen); /* V11.1 */
unsigned int lkf_auf_add_ext (LKF_AUFENTHALT *pAufenthalt, const char *sBuf); /* V11.1 */
const char *lkf_auf_get_ext (LKF_AUFENTHALT *pAufenthalt, unsigned int nOffset); /* V11.1 */
void lkf_free_aufenthalt_subgruppen (LKF_AUFENTHALT *pAufenthalt); /* V13.0 */
unsigned int lkf_create_aufenthalt_subgruppen (LKF_AUFENTHALT *pAufenthalt, unsigned int nCount); /* V13.0 */
long lkf_auf_get_abtvalue (LKF_AUFENTHALT *pAufenthalt, unsigned int abtIndex, long *tp, long *lp); /* V21.4 */

void lkf_scoringdetails_alloc (LKF_AUFENTHALT *pAufenthalt);
void lkf_scoringdetails_free (LKF_AUFENTHALT *pAufenthalt);
void lkf_scoringdetails_addComment (LKF_AUFENTHALT *pAufenthalt, const char *comment);
void lkf_reset_aufenthalt_internal (LKF_AUFENTHALT *pAufenthalt, int keepX01);
void lkf_auf_add_category (LKF_AUFENTHALT *pAufenthalt, char *code, char *text, unsigned int maxLength);

/* Scoring-Context-spezifische Routinen (context5.c) **************************/
unsigned int lkf_search_patient (LKF_CONTEXT *pContext, const char *kanr, const char *aufnahmezahl, int *exact_match);
void lkf_init_context_counters (LKF_CONTEXT *pContext);
unsigned int lkf_search_kanr (LKF_CONTEXT *pContext, const char *kanr);
int lkf_context_add_spez (LKF_CONTEXT *pContext, const char *line);
int lkf_context_add_kost (LKF_CONTEXT *pContext, const char *line);
int lkf_context_add_melka (LKF_CONTEXT *pContext, const char *line);
/* KOST_LIST_STRING *lkf_alloc_kost_list (LKF_CONTEXT *pContext);   V11.0 */
/* SPEZ_LIST_STRING *lkf_alloc_spez_list (LKF_CONTEXT *pContext);   V11.0 */
/* MEL_KA_STRING *lkf_alloc_mel_ka_list (LKF_CONTEXT *pContext);    V11.0 */
void *lkf_new_semaphore (void);
long lkf_new_semaphore2 (void);
void lkf_enter_semaphore (void *sem);
void lkf_leave_semaphore (void *sem);
void lkf_delete_semaphore (void *sem);
int lkf_init_ka (LKF_CONTEXT *pContext, STAT_KA *pKA, const char *ka, int complete);
void lkf_free_ka (LKF_CONTEXT *pContext, STAT_KA *pKA);
void lkf_set_outOfMemory (LKF_CONTEXT *pContext, const char *comment, size_t size);

const SPEZ_LIST_STRING *SpezInArray (const LKF_CONTEXT *pContext, const char *spez);
unsigned int SpezAnz (const LKF_CONTEXT *);
KOST_LIST_STRING *KostInArray (const LKF_CONTEXT *pContext, const char *kost);
void *KostInArray2 (const LKF_CONTEXT *pContext, const char *kost);
MEL_KA_STRING *GetMELKA (const LKF_CONTEXT *pContext, const char *melka);
int lkf_context_sort_private_stamm (LKF_CONTEXT *pContext);
unsigned int lkf_add_context_linebuf_line (LKF_CONTEXT *pContext, const char *line);
unsigned int lkf_add_context_expLine (LKF_CONTEXT *pContext, LKF_EXPANDED_LINE *pLine);
unsigned int lkf_add_context_linebuf_line_error (LKF_CONTEXT *pContext, const char *line);
void lkf_context_addimporterror (LKF_CONTEXT *pContext, unsigned int nLine, const SATZART_FELD *pFeld, const LKF_SATZART_ERRORDEF *pErrorDef, const SATZART_INFO *pSatzart);
int lkf_context_addimporterrorEx (LKF_CONTEXT *pContext, unsigned int nLine, const SATZART_FELD *pFeld, const LKF_SATZART_ERRORDEF *pErrorDef, const SATZART_INFO *pSatzart, const char *buf, long buflen);
const SATZART_INFO *lkf_GetSatzartI (LKF_CONTEXT *pContext, unsigned int nNr);
const SATZART_INFO *lkf_GetSatzartK (LKF_CONTEXT *pContext, unsigned int nNr);
const SATZART_INFO *lkf_GetSatzartG (LKF_CONTEXT *pContext, unsigned int nNr);
const SATZART_INFO *lkf_GetSatzartR (LKF_CONTEXT *pContext, unsigned int nNr);
const SATZART_INFO *lkf_GetSatzartL (LKF_CONTEXT *pContext, unsigned int nNr);
const SATZART_INFO *lkf_GetSatzartL01Internal (LKF_CONTEXT *pContext); /* V17.0 */
const SATZART_INFO *lkf_GetSatzartS (LKF_CONTEXT *pContext, unsigned int nNr);
const SATZART_INFO *lkf_GetSatzartB (LKF_CONTEXT *pContext, unsigned int nNr); /* V14.2 */
MEL_KA_STRING *GetMELKATKLContext (const LKF_CONTEXT *pContext, const char *melka);
LKF_CONTEXT_ABTEILUNG *lkf_context_add_abteilung (LKF_CONTEXT *pContext, const char *sAbtFC, const char *sKst, const char *sKANR6 /* V11.1 */); /* V11.0 */
void lkf_context_sort_abteilungen (LKF_CONTEXT *pContext); /* V11.0 */
LKF_CONTEXT_ABTEILUNG *lkf_context_find_abteilung (const LKF_CONTEXT *pContext, const char *sAbtFC); /* V11.0 */
const SPEZ_LIST_STRING *FirstSpezInArray (const LKF_CONTEXT *pContext, const SPEZ_LIST_STRING *pSpez, const char *spez); /* V14.1 */
const SPEZ_LIST_STRING *NextSpezInArray (const LKF_CONTEXT *pContext, const SPEZ_LIST_STRING *pSpez, const char *spez); /* V14.1 */
const char *lkf_context_formatted_text (const LKF_CONTEXT *pContext, const char *utf8Text, char *buf); /* V21.0 */
unsigned int lkf_numberOf2ByteCharaters (const LKF_CONTEXT *pContext, const char *utf8Text); /* V21.1 */
/* Stammdaten-Routinen (stamm5.c) */
#ifdef SUPPORT_PRE2017
STAMM2001 *getStamm2009 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2010 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2011 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2012 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2013 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2014 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2015 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2016 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
#endif
STAMM2001 *getStamm2017 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2018 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2019 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2020 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2021 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2022 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2023 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2024 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2025 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);
STAMM2001 *getStamm2026 (LKF_CONTEXT *pContext, const char *input_path, char *errbuf);

PLZ_LIST_STRING *PLZInArray (const LKF_CONTEXT *, const char *plz);
KA_LIST_STRING *KAInArray (const STAMM2001 *, const char *ka);
KA_LIST_STRING *KAInArray2 (const STAMM2001 *, const char *ka, int nQuelle);
KTR_LIST_STRING *KTRInArray (const STAMM2001 *, const char *ktr); /* V14.2 */
void *StaatInArray (const LKF_CONTEXT *, const char *staat);
GKZ_LIST_STRING *FindGKZ (const LKF_CONTEXT *, const char *staat); /* V21.0 */
ICD_LIST_STRING *FindDiag6 (const STAMM2001 *pStamm, const char *diag);
ICD_LIST_STRING *FindDiag5 (const STAMM2001 *pStamm, const char *diag);
ICD_LIST_STRING *FindDiag3 (const STAMM2001 *pStamm, const char *diag);
ICD_LIST_STRING *FindDiag (const STAMM2001 *pStamm, const char *diag); /* V13.3 */
STERNKR_LIST_STRING *FindSternKr3 (const STAMM2001 *pStamm, const char *diag);
STERNKR_LIST_STRING *FindSternKr5 (const STAMM2001 *pStamm, const char *diag);
MEL_ARRAY_STRUC *GetMELArrayString (const STAMM2001 *pStamm, unsigned int i);
MEL_DIAG_STRING *GetMELDiag (const STAMM2001 *pStamm, unsigned int i);
MEL_DIAG_STRUC6 *GetMELDiag6 (const STAMM2001 *pStamm, unsigned int i);
int lkf_dyn_akwarn_compare (const void *p1, const void *p2);
MEL_MEL_STRING *GetMEL_MEL2009 (const STAMM2001 *pStamm, const char *mel1, const char *mel2);
const LKF_KNOTEN *AddLKFKnoten (STAMM2001 *pStamm, LKF_KNOTEN *pSrc);
const LKF_KNOTEN *GetLKFKnoten (STAMM2001 *pStamm, const char *knoten, char *errbuf);
const LKF_KNOTEN *GetLKFKnotenFromBuffer (unsigned int modelljahr, const char *buffer, LKF_KNOTEN *pKnoten, char *errorBuffer);
const LKF_KNOTEN *GetAMBKnoten (STAMM2001 *pStamm, const char *gruppenname, char *errbuf); /* V21.0 */
const SPEZ_LIST_STRING *SpezInArrayStamm (const STAMM2001 *pStamm, const char *spez);
unsigned int SpezAnzStamm (const STAMM2001 *pStamm);
KOST_LIST_STRING *KostInArrayStamm (const STAMM2001 *pStamm, const char *kost);
void *KostInArray2Stamm (const STAMM2001 *pStamm, const char *kost);
MEL_KA_STRING *GetMELKAStamm2009 (const STAMM2001 *pStamm, const char *melka);
MEL_KA_STRING *GetMELKATKL2009 (const STAMM2001 *pStamm, const char *melka);
void freeStamm2001 (STAMM2001 *pStamm); /* V6.0 */
const LKF_KNOTEN *LKFKnotenInArray (STAMM2001 *pStamm, const char *gruppe);
FUNK_LIST_STRING *FunkInArray (const STAMM2001 *pStamm, const char *abtfc);
GGART_STRING *FindGGArt (const LKF_CONTEXT *pContext, const char *sGGArt);
GGLEIST_STRING *FindGGLeist (const LKF_CONTEXT *pContext, const char *sGGLeist);
char *lkf_realloc_stamm_array (LKF_CONTEXT *pContext, unsigned int nSize, unsigned int nAllocCount, char *sOld, unsigned int nCurrentCount, const char *allocText);
char *lkf_alloc_stamm_array (LKF_CONTEXT *pContext, unsigned int nSize, unsigned int nAllocSize, const char *allocText);
const OEMELKA_STRING *FindOeMelka (LKF_CONTEXT *pContext, const char *sKANR6, const char *sMel, unsigned int check6_flagpos); /* V020.3: pStamm -> pContext */
int HasOeMelka (LKF_CONTEXT *pContext, const char *sKANR6); /* V2020.2 / V2021.3: pStamm -> pContext */
MEL_ARRAY_STRUC *FindMel (const LKF_CONTEXT *pContext, const char *sMel);
MEL_ARRAY_STRUC *GetStammMel (const STAMM2001 *pStamm, const char *sMel);
int FindMelIndex (const LKF_CONTEXT *pContext, const char *sMel);
int FindMelIndexStamm (const STAMM2001 *pStamm, const char *sMel);
MEL_ARRAY_STRUC *FindMelStamm (const STAMM2001 *pStamm, const char *sMel);
int FindMelIndexStammWeak (const STAMM2001 *pStamm, const char *sMel, int bLower);
MEL_ARRAY_STRUC *GetMELArrayFromIndex (const LKF_CONTEXT *pContext, unsigned int nMelIndex);
int StammInitMELIndexLists (STAMM2001 *pStamm, int nModellJahr);
int MELInIndexList (const LKF_CONTEXT *pContext, unsigned int nIndexList, int nMelIndex);
int IsConstMEL (const LKF_CONTEXT *pContext, unsigned int nConstMelId, int nMelIndex);
const OEKASO_STRING *FindOEKASO4 (const STAMM2001 *pStamm, const char *ka);
const OEKASO_STRING *FindOEKASO6 (const STAMM2001 *pStamm, const char *ka);
const DIAG_MEL_STRING *diag_mel_find (const LKF_CONTEXT *pContext, const char *diag); /* V18.0 */
const DIAG_MEL_STRING *diag_mel_next (const LKF_CONTEXT *pContext, const DIAG_MEL_STRING *diagMel); /* V18.0 */
const DIAG_DIAG_STRING *diag_diag_find (const LKF_CONTEXT *pContext, const char *diag, const char *otherDiag); /* V18.0 */
int has_diagdiag (const LKF_CONTEXT *pContext, const char *diag); /* V18.0 */
int kost_compare (const void *k1, const void *k2);
int kost2_compare (const void *k1, const void *k2);
int spez_compare (const void *s1, const void *s2);
int mel_ka_compare2009 (const void *m1, const void *m2);
int mel_ka_compare_old (const void *m1, const void *m2);
STAMM_FILE* lkf_stamm_open(STAMM2001* pStamm, const char* filename, const char* alternateName); /* V2021.0 */
const char* lkf_stamm_line(char* buf, int buflen, STAMM_FILE* file); /* V2021.0 */
void lkf_stamm_close(STAMM_FILE* file); /* V2021.0 */
const PLZ_GEMCO_STRING* FindPLZGemco(const LKF_CONTEXT* pContext, const char* plz, const char* gemco); /* V21.2 */
int lkf_context_count_error (LKF_CONTEXT *pContext, LKF_SATZART_ERROR *pError); /* V21.5 */
void build_path (char *path, const char *srcpath, int year);
STAMM2001 *allocStamm2001 (LKF_CONTEXT *pContext, const char *input, long year);
int stamm_read_statonly (STAMM2001 *pStamm2001, const char *input_path, char *errbuf, int year);
int oemelka_compare_2009 (const void *om1, const void *om2);
ATCLIST_STRING *FindATC (const STAMM2001 *pStamm, const char *atc); /* V2026.0 */
/* Plausibilitäts-Routinen (plaus5.c) ******************************************/
int lkf_plaus_compute (LKF_CONTEXT *pContext, LKF_AUFENTHALT *pAufenthalt);
int ABTFC_Spez_Check (LKF_AUFENTHALT *pAufenthalt, int abtid, const SPEZ_LIST_STRING *pSpez, int warn);
const LKF_SATZART_ERRORDEF **GetAllMBDSErrors (int nModelljahr);
const LKF_SATZART_ERRORDEF *lkf_plaus_getErrorDef (const LKF_CONTEXT *pContext, unsigned int nr);
const char *lkf_getErrorMBDSFieldEx (LKF_AUFENTHALT *pAufenthalt, unsigned int errfield, unsigned int erradd, char *text, unsigned int len, int abtIndex /* V20.1 */);
const char *FormatDate8 (const char *date8, char *destbuf);
const char *lkf_getErrorMBDSIdent (LKF_AUFENTHALT *pAufenthalt, unsigned int errfield, unsigned int erradd, unsigned int len, char *text);
const char *lkf_getErrorMBDSSatzart (LKF_AUFENTHALT *pAufenthalt, unsigned int errfield, unsigned int len, char *text);
const char *lkf_getErrorMBDSFieldId (const LKF_CONTEXT *pContext, unsigned int errfield);
const LKF_SATZART_ERRORDEF *lkf_getPlausNPWarningErrorDef (int warncode); 
void lkf_plaus_intabtcheck (LKF_AUFENTHALT *pAufenthalt, int abtid, LKF_AUFENTHALT_ABT *, const LKF_INT_SCORING_ABT *pAbt);
void lkf_plaus_abtcheck_2017 (LKF_AUFENTHALT *pAufenthalt, int abtid, LKF_AUFENTHALT_ABT *pAbt, int needsInt); /* V21.0 */
void *checkAcceptedWarning (LKF_AUFENTHALT *pAufenthalt, const LKF_SATZART_ERRORDEF *pErrorDef, const char *value, int flag);
void *checkAcceptedError (LKF_AUFENTHALT *pAufenthalt, const LKF_SATZART_ERRORDEF *pErrorDef, const char *value, int flag); /* V15.2 */
const LKF_SATZART_ERRORDEF **lkf_getIgnorePlausNFondsErrors (const LKF_CONTEXT *pContext);
void PlausReportIntensivError (LKF_AUFENTHALT *pAufenthalt, int bWarning, int nErrorIndex);
int lkf_stamm_check_consistency (LKF_CONTEXT *pContext);
int ABTFC_SpezList_Match (LKF_CONTEXT *pContext, const SPEZ_LIST_STRING *pSpez); /* V17.0 */
int ABTFC_Spez_Match (LKF_CONTEXT *pContext, const char *sAbtFC, char SpezTyp, const char *SpezBereich, int flag); /* V17.1  */
int abt_in_patternlist (const char *abt, const char **ppValidABTFCs); /* V17.0 - nicht mehr static */
int Satzart_ReportMBDSError (LKF_AUFENTHALT *pAufenthalt, const LKF_SATZART_ERRORDEF *pErrorDef, unsigned int addinfo);
const char *lkf_plaus_get_error_valuefield_description (const LKF_CONTEXT *pContext, const LKF_SATZART_ERRORDEF *pError); /* V20.1 */

void apply_custom_melChecks (STAMM2001 *pStamm);
const char *lkf_get_function_Description (int (*checkFunction)(LKF_AUFENTHALT *, unsigned int i, int nMelAbtIndex));

char *lkf_format_abtpos(LKF_AUFENTHALT_ABT *pAbt, char *buf);
char*lkf_format_abtpos_string (const char *ABTPOS, char *buf);

typedef struct {
    char command[26];
    char value[66];
} LKF_COMMAND;

typedef struct {
    LKF_CONTEXT *pContext;
    LKF_COMMAND *commands;
    unsigned int command_alloc;
    unsigned int command_count;
} LKF_COMMANDS;

LKF_COMMANDS* lkfcommand_alloc (LKF_CONTEXT *pContext, const char *s);
void lkfcommand_free (LKF_COMMANDS *commands);
LKF_COMMAND *lkfcommand_get (const LKF_COMMANDS *commands, const char *name);


#define MELABTOK_CHECKED       1
#define MELABTOK_AM030         (1<<1)
#define MELABTOK_AM020         (1<<2)
#define MELABTOK_AA040         (1<<3)
#define MELABTOK_LH020         (1<<4)
#define MELABTOK_AM040         (1<<5)
#define MELABTOK_AM050         (1<<6)
#define MELABTOK_DB020         (1<<7)
#define MELABTOK_AJ140         (1<<8)
#define MELABTOK_AK010         (1<<9)
#define MELABTOK_LH010         (1<<10)
#define MELABTOK_LH021         (1<<11)
#define MELABTOK_AM100         (1<<12)
#define MELABTOK_AM110         (1<<13)
#define MELABTOK_AM120         (1<<14)
#define MELABTOK_AM130         (1<<15)
#define MELABTOK_AM140         (1<<16)  /* V2022.0 */
#define MELABTOK_AM150         (1<<17)  /* V2022.0 */

int lkf_MELABTOK_Check (LKF_AUFENTHALT *pAufenthalt);

/* Context-Routinen (context5.c) ***********************************************/
void lkf_context_create_demo_aufid (char *dest, const char *source);
unsigned int lkf_search_aufenthalt_2017 (LKF_CONTEXT *pContext, const char *key, int *exact_match, unsigned int matchLength);
int lkf_has_k01 (LKF_CONTEXT *pContext, const char *abtfc); /* V2019.1 */
void lkf_SpezListCheck (LKF_CONTEXT *pContext); /* V2024.0 */
/* Erweiterte Plausibilitäts-Routinen (npplaus5.c) *****************************/
int lkf_read_npplaus_intdiag (int modelljahr, STAMM2001 *pStamm, unsigned int *pCount, char *errbuf);
int lkf_read_npplaus_intmel (int year, STAMM2001 *pStamm, char *errbuf);
int lkf_read_npplaus_intbegrmel (int year, STAMM2001 *pStamm, char *errbuf);
int lkf_read_npplaus_invasmel (int modelljahr, STAMM2001 *pStamm, char *errbuf);

const NPPLAUS_STRUC *lkf_find_npplaus (STAMM2001 *pStamm, const char *diag);
int lkf_NPPlaus_Check (LKF_CONTEXT *pContext, LKF_AUFENTHALT *pAufenthalt);
int lkf_NPPlaus_Init (LKF_CONTEXT *pContext);
int lkf_NPPlaus_End (LKF_CONTEXT *pContext);
NPPLAUS_CONTEXT *lkf_alloc_npplaus_context (LKF_CONTEXT *pContext);
void lkf_free_npplaus_context (NPPLAUS_CONTEXT *pNPPlausContext);
int lkf_reset_npplaus_context_package (NPPLAUS_CONTEXT *pNPPlausContext); /* V21.5 */
int lkf_setNeonatologie (LKF_AUFENTHALT *pAufenthalt, unsigned int nAbtIndex);

/* Scoring-Routinen (scoring5.c) ***********************************************/
int lkf_scoring_compute (LKF_CONTEXT *pContext, LKF_AUFENTHALT *pAufenthalt);
void lkf_setMelMelInfo (LKF_AUFENTHALT *pAufenthalt, unsigned int melIndex);

/* Int-Scoring-Routinen (intscor5.c) *******************************************/
void lkf_int_alloc_structure (LKF_CONTEXT *pContext);
int lkf_int_analyse (LKF_CONTEXT *pContext) ;
void lkf_int_free_structure (LKF_CONTEXT *pContext);
unsigned int lkf_int_check (LKF_CONTEXT *pContext, LKF_AUFENTHALT *pAufenthalt);
void lkf_int_free_aufenthalt (LKF_CONTEXT *pContext, LKF_INT_AUFENTHALT *pIntAufenthalt);
const LKF_SATZART_ERRORDEF **lkf_GetGeneralIntScoringErrors (int modelljahr);
void lkf_int_alloc_structure_aufenthalt (LKF_CONTEXT *pContext, LKF_AUFENTHALT *pAufenthalt, LKF_INT_SCORING *pIntScoring);
int lkf_int_alloc_structure_2017 (LKF_CONTEXT *pContext); /* V21.0 */
int lkf_int_alloc_structure_aufenthalt_2017 (LKF_CONTEXT *pContext, LKF_AUFENTHALT *pAufenthalt, LKF_INT_SCORING *pIntScoring);
unsigned int lkf_int_getIntAufenthaltDetailsInternal (const LKF_CONTEXT *pContext, LKF_INT_SCORING_ABT *pIntAbt, unsigned int lSAPS, char *sBuf, unsigned int lBufLen); /* V2019.1 */
int lkf_int_getAufSAPSScoreInternal (const LKF_CONTEXT *pContext, LKF_INT_SCORING_ABT *pAbt, unsigned int lSAPS, unsigned int lFieldNr); /* V2019.1 */

/* Satzart-Error-Routinen (lkfstru5.c) ******************************************/
LKF_SATZART_ERRORS *Satzart_AllocErrorStructure(LKF_CONTEXT *pContext);
void Satzart_FreeErrorStructure(LKF_CONTEXT *pContext, LKF_SATZART_ERRORS *pErrors);
LKF_SATZART_ERROR *Satzart_GetSatzartError (LKF_SATZART_ERRORS *pErrors, int index);
unsigned int Satzart_GetNextFreeErrorIndex (LKF_CONTEXT *pContext, LKF_SATZART_ERRORS *pErrors);
int Satzart_ReportError (LKF_CONTEXT *pContext, LKF_CHECK_CONTEXT *pCheckContext, const char *pLine, unsigned int buflen, const SATZART_INFO *pSatzartInfo, const SATZART_FELD *pFeld, const LKF_SATZART_ERRORDEF *pErrorDef, const char *sInfo);
void Satzart_ReportErrorExp (LKF_CONTEXT *pContext, LKF_CHECK_CONTEXT *pCheckContext, const LKF_EXPANDED_LINE *pLine, const SATZART_INFO *pSatzartInfo, const SATZART_FELD *pFeld, const LKF_SATZART_ERRORDEF *pErrorDef, const char *sInfo);
const char *lkf_getErrorIdent (const LKF_CONTEXT *pContext, const LKF_SATZART_ERRORDEF *pErrorDef, unsigned int buflen, char *buf);
unsigned int lkf_getErrorIntFromCode (const char *errorcode);
const char *lkf_getErrorFieldHeadline (const LKF_CONTEXT *pContext, unsigned int checkfield);
const char *lkf_getErrorFieldValue (const LKF_CONTEXT *pContext, const LKF_SATZART_ERROR *pError, unsigned int checkfield, unsigned int buflen, char *buf, unsigned int *pFieldLen);
int lkf_ErrorMatchesFilter (const LKF_CONTEXT *pContext, unsigned int nFilter, const LKF_SATZART_ERRORDEF *pError);
const char *Satzart_GetValueDateFormat (const char *ds, unsigned int buflen, const SATZART_FELD *pFeld, char *value, unsigned int maxlen);
const char *Satzart_GetValueDateFormatExp (const LKF_EXPANDED_LINE *expLine, const SATZART_FELD *pFeld, char *value, unsigned int maxlen);

const LKF_SATZART_ERRORDEF *lkf_importcheck_kanr (LKF_CONTEXT *pContext, const char *ka, int bTraegerOk);
int lkf_create_general_errorinfo (LKF_SATZART_ERRORINFO_LIST *pList, LKF_CONTEXT *pContext, unsigned int nSeverity);
const LKF_SATZART_ERRORDEF **lkf_get_general_errors (const LKF_CONTEXT *pContext, unsigned int facility);
int Satzart_ErrorCheckField (const char *ds, unsigned int len, const SATZART_FELD *pFeld, const LKF_SATZART_ERRORCHECK *pCheck, LKF_CHECK_CONTEXT *pCheckContext);
int Satzart_ErrorCheckFieldExp (const LKF_EXPANDED_LINE *expLine, const SATZART_FELD *pFeld, const LKF_SATZART_ERRORCHECK *pCheck, LKF_CHECK_CONTEXT *pCheckContext);
unsigned int lkf_getSeverity (const LKF_CONTEXT *pContext, const LKF_SATZART_ERRORDEF *pErrorDef);
const char *lkf_getErrorFunctionComment (const LKF_CONTEXT *pContext, const void *pPtr);
const LKF_SATZART_ERRORCHECK *lkf_getModelDependentCheck (const LKF_SATZART_ERRORCHECK *pCheck, const LKF_CONTEXT *pContext);
const LKF_SATZART_ERROR_PROPERTIES *lkf_getErrorProperties (const LKF_SATZART_ERRORDEF *pErrorDef, const LKF_CONTEXT *pContext);
int lkf_getErrorRelevance (const LKF_SATZART_ERRORDEF *pErrorDef, const LKF_CONTEXT *pContext);
const SATZART **GetKasKoreSatzarten (int nModellJahr);
void lkf_checkL01 (LKF_CHECK_CONTEXT *pCheckContext); /* V17.0 */
void Satzart_ComputeReference (int jahr, const SATZART *pSatzart, SATZART_INFO *pSatzartInfo); /* V17.0 */
unsigned int Satzart_GetExpandedLines (LKF_EXPANDED_LINES *pExpandedLines, const char *prefix, LKF_EXPANDED_LINE ***pppLines);
int k03_mbdsstat (LKF_CHECK_CONTEXT *pCheckContext, int incremental);
int lkf_scoring_mbdsstat (LKF_CONTEXT *pCheckContext);
/* Satzart-Routinen (satzchk5.c) ************************************************/
LKF_ERRORGROUP *lkf_alloc_errorgroup (LKF_CONTEXT *pContext, const LKF_SATZART_ERRORDEF **ppErrors);
void lkf_free_errorgroup (LKF_CONTEXT *pContext, LKF_ERRORGROUP *pErrorGroup);
LKF_SATZART_ERRORINFO_LIST *lkf_alloc_errorinfo (LKF_CONTEXT *pContext, unsigned int nListOptions);
unsigned int lkf_getNextFreeErrorInfo (LKF_SATZART_ERRORINFO_LIST *pList);
const LKF_SATZART_ERRORCHECK **lkf_get_facility_general_checks (const LKF_CONTEXT *pContext, unsigned int facility);
int lkf_create_facility_errorinfo (LKF_SATZART_ERRORINFO_LIST *pList, LKF_CONTEXT *pContext, unsigned int facility, unsigned int nSeverity); /* V2026.0 */
int lkf_create_intscoring_errorinfo (LKF_SATZART_ERRORINFO_LIST *pList, LKF_CONTEXT *pContext, unsigned int nSeverity);
int lkf_errorinfo_add_usage (LKF_SATZART_ERRORINFO *pErrorInfo, const LKF_SATZART_ERRORCHECK *pCheck, const SATZART *pSatzart, const SATZART_FELD *pFeld);
LKF_CHECK_CONTEXT *lkf_alloc_checkcontext (LKF_CONTEXT *pContext);
void lkf_free_checkcontext (LKF_CONTEXT *pContext, LKF_CHECK_CONTEXT *pCheckContext);
LKF_CHECK_CONTEXT *lkf_get_contextcheckcontext (LKF_CONTEXT *pContext);
void lkf_errorinfo_sort (LKF_SATZART_ERRORINFO_LIST *pList);
LKF_KK_CONTEXT *lkf_alloc_kk_context (LKF_CONTEXT *pContext);
int lkf_check_kk (LKF_CONTEXT *pContext, LKF_KK_CONTEXT *pKKContext);
void lkf_free_kk_context (LKF_KK_CONTEXT *pKKContext);
LKF_KK_CONTEXT_ABTEILUNG *lkf_check_kk_abteilung (LKF_KK_CONTEXT *pKKContext, const char *sAbtFC, unsigned int bCreate);
const SATZART_FELD *lkf_getSatzartFeld (int nModelljahr, const SATZART_FELD *pFeld);
LKF_SATZART_ERRORINFO *lkf_errorinfo_increment (LKF_SATZART_ERRORINFO_LIST *pList, const LKF_SATZART_ERRORDEF *pErrorDef);
LKF_KK_CONTEXT_ABTEILUNG *lkf_find_kk_abteilung (LKF_KK_CONTEXT *pKKContext, const char *sAbtFC); /* V2019.1 */

/* Routinen zur Statistik-Berechnung (lkfstat5.c) - ******************************/
int lkf_alloc_context_lkfstat (LKF_CONTEXT *pContext);
void lkf_free_context_lkfstat (LKF_CONTEXT *pContext);

LKF_CASESTAT *lkf_alloc_context_casestat (LKF_CONTEXT *pContext); /* V21.0 */
LKF_CASESTAT *lkf_free_context_casestat (LKF_CONTEXT *pContext);  /* V21.0 */
int lkf_stat_register_case (LKF_AUFENTHALT *pAufenthalt, const char *category, const char *ident); /* V21.0 */

/* Trace-Routinen (trace5.c) - ++++++++++++***************************************/

#define LKF_IS_TRACE_DETAIL(nTraceMode) (((nTraceMode)&255) == LKF_TRACE_DETAIL)
#define LKF_IS_TRACE_INFO(nTraceMode) ((nTraceMode))
#define LKF_IS_TRACE_INPUT(nTraceMode) ((nTraceMode) & LKF_TRACE_INPUT)

int lkf_getTraceMode (const LKF_CONTEXT *pContext, int nFacility);
void lkf_addTraceLineContext (LKF_CONTEXT *pContext, const char *sLine, int nFacility, int nSeverity);
void lkf_addTraceLine (LKF_CHECK_CONTEXT *pContext, const char *sLine, int nFacility, int nSeverity);
void lkf_addTraceInputLine (LKF_CONTEXT *pContext, const char *sLine);
void lkf_addTraceAufenthaltAbteilungLine (LKF_CONTEXT *pContext, LKF_AUFENTHALT *pAufenthalt, const char *sAbtFC, const char *sLine, int nFacility, int nSeverity);
void lkf_addTraceAufenthaltLine (LKF_CONTEXT *pContext, LKF_AUFENTHALT *pAufenthalt, int nAbt, const char *sLine, int nFacility, int nSeverity);
void lkf_addTraceAbteilungLine (LKF_CONTEXT *pContext, const char *sAbtFC, const char *sLine, int nFacility, int nSeverity);
void lkf_trace_mbds_aufenthalt (LKF_CONTEXT *pContext, LKF_AUFENTHALT *pAufenthalt);
int lkf_isTraceInput (const LKF_CONTEXT *pContext, int nFacility);
int lkf_isTraceInfo (const LKF_CONTEXT *pContext, int nFacility);
int lkf_isTraceDetail (const LKF_CONTEXT *pContext, int nFacility);
int lkf_trace_SetFacility (LKF_CONTEXT *pContext, const char *sLine);


/* Routinen des Berichtswesens (bericht5.c) *************************************/
const char *lkf_getErrorBerichtFunctionComment (const LKF_CONTEXT *pContext, const void *pPtr);
const LKF_SATZART_ERRORCHECK **lkf_get_bericht_general_checks (const LKF_CONTEXT *pContext);

/* Funktionen fuer X-Records (xrecords.c) - Modell 2017 *************************/
int lkf_add_xline (LKF_CONTEXT *pContext, const char *line);
LKF_AUFENTHALT *lkf_add_xline_aufX (LKF_CONTEXT *pContext, const char *line, LKF_EXPANDED_LINE_INFO *pInfo);
int lkf_add_xline_auf_intensiv (LKF_AUFENTHALT *pContext, const char *line, LKF_EXPANDED_LINE_INFO *pInfo);
int lkf_add_xline_auf (LKF_AUFENTHALT *pAufenthalt, const char *line, LKF_EXPANDED_LINE_INFO *pInfo);
int lkf_auf_xline_root (LKF_AUFENTHALT *pAufenthalt, char *line);
int lkf_add_xline_auf_bypass_check (LKF_AUFENTHALT *pAufenthalt, const char *srcline, int nModelljahr, LKF_EXPANDED_LINE_INFO *pInfo);
int lkf_auf_xline_abt (LKF_AUFENTHALT *pAufenthalt, unsigned int i, char *line);
int lkf_auf_xline_diag (LKF_AUFENTHALT *pAufenthalt, unsigned int i, char *line);
int lkf_auf_xline_mel (LKF_AUFENTHALT *pAufenthalt, unsigned int i, char *line);
int lkf_auf_xline_scoring (LKF_AUFENTHALT *pAufenthalt, char *line);
int lkf_auf_xline_akwarn (LKF_AUFENTHALT *pAufenthalt, unsigned int i, char *line, unsigned int *pHitCount);
int lkf_auf_xline_kommentar (LKF_AUFENTHALT *pAufenthalt, char *line);
LKF_EXPANDED_LINE *lkf_create_expandLine (LKF_CONTEXT *pContext, const char *line, unsigned int modifyLen, LKF_EXPANDED_LINE_INFO *pInfo, const char *memoryKey);
void lkf_free_expandLine (LKF_CONTEXT *pContext, LKF_EXPANDED_LINE *ambLine);
const char *lkf_aufenthalt_key (LKF_CONTEXT *pContext, LKF_EXPANDED_LINE *pLine, char *key);
const char *lkf_aufenthalt_key_bm (char *key, const char *datensatzid, const char *aufdat);
const char *lkf_aufenthalt_key_lf (char *key, const char *aufnr, const char *aufdat);
int lkf_add_xline_intensiv (LKF_CONTEXT *pContext, const char *line, LKF_EXPANDED_LINE_INFO *pInfo);
int lkf_add_xline_andere (LKF_CONTEXT *pContext, const char *line, LKF_EXPANDED_LINE_INFO *pInfo);
LKF_EXPANDED_LINE *lkf_create_expandLineWithPre2017Compatibility (LKF_CONTEXT *pContext, const char *line, const SATZART_INFO *pSatzartInfo, int modifyChars, LKF_EXPANDED_LINE_INFO *pInfo);
LKF_EXPANDED_LINES *lkf_create_expandedLines (LKF_CONTEXT *pContext, unsigned int initialSize);
void lkf_free_expandedLines (LKF_EXPANDED_LINES *expandedLines);
unsigned int lkf_add_expandLine (LKF_EXPANDED_LINES *expandedLines, LKF_EXPANDED_LINE *expandLine);
unsigned int lkf_replace_expandLine (LKF_EXPANDED_LINES *pExpandLines, LKF_EXPANDED_LINE *pLine, unsigned int index);
unsigned int lkf_delete_expandLine (LKF_EXPANDED_LINES *pExpandLines, unsigned int index); /* V2024.0 */
unsigned int lkf_replace_addLine (LKF_CONTEXT *pContext, LKF_EXPANDED_LINE *pLine, unsigned int index); /* V2024.0 */
unsigned int lkf_delete_addLine (LKF_CONTEXT *pContext, unsigned int index); /* V2024.0 */
int lkf_write_expLine (char *line, const LKF_EXPANDED_LINE *pLine);
int lkf_write_expLineFields (char *line, unsigned int fieldCount, const char **fields);
int lkf_auf_getintxline (LKF_AUFENTHALT *pAufenthalt, unsigned int index, char *l, char *ident);
int lkf_add_xline_melka (LKF_CONTEXT *pContext, const LKF_EXPANDED_LINE *line);
int lkf_add_xline_melkatkl (LKF_CONTEXT *pContext, const LKF_EXPANDED_LINE *line);
int lkf_add_xline_kost (LKF_CONTEXT *pContext, const LKF_EXPANDED_LINE *line);
int lkf_add_xline_spez (LKF_CONTEXT *pContext, const LKF_EXPANDED_LINE *line, const char *origline);
int lkf_add_xline_oemelka (LKF_CONTEXT *pContext, const LKF_EXPANDED_LINE *line); /* V2021.3 */
int lkf_auf_write_satzart (LKF_AUFENTHALT *pAufenthalt, const SATZART_INFO *pSatzart, unsigned int count, const int *feldIndices, const char **feldWerte, const char *ext, char *line);
int lkf_write_satzart (LKF_CONTEXT *pContext, const SATZART_INFO *pSatzart, unsigned int count, const int *feldIndices, const char **feldWerte, const char *ext, char *line);
int lkf_addOrReplace_xlineIdent (LKF_CONTEXT *pContext, const char *line, char *addIdent, const char *ident);
char *lkf_getXLine_FieldValue (LKF_EXPANDED_LINE *pLine, int fieldIndex, char *buffer, unsigned long bufferLength);
int lkf_setXLine_FieldValue (LKF_EXPANDED_LINE *pLine, int fieldIndex, char *value);

#ifdef SUPPORT_PRE2017
/* context5.c */
int lkf_add_line_auf_bypass_check (LKF_AUFENTHALT *pAufenthalt, const char *line, int nModellJahr);
unsigned int lkf_add_linebuf_line (LKF_AUFENTHALT *pAufenthalt, const char *line);
#endif
