Sync biosiglite with upstream

parent 2081145d
/*
% Copyright (C) 2005-2016 Alois Schloegl <alois.schloegl@gmail.com>
% Copyright (C) 2005-2018 Alois Schloegl <alois.schloegl@gmail.com>
% This file is part of the "BioSig for C/C++" repository
% (biosig4c++) at http://biosig.sf.net/
......@@ -30,7 +30,9 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#if !defined(_MSC_VER)
#include <sys/param.h>
#endif
#include <time.h>
#include "physicalunits.h"
......@@ -131,7 +133,6 @@ char *getlogin (void);
typedef __int64 int64_t;
typedef unsigned __int32 uint32_t;
typedef __int32 int32_t;
typedef unsigned __int16 uint16_t;
typedef __int16 int16_t;
typedef unsigned __int8 uint8_t;
typedef __int8 int8_t;
......@@ -362,8 +363,14 @@ typedef struct HDR_STRUCT {
gdf_time Birthday; /* Birthday of Patient */
// Age; // the age is HDR.T0 - HDR.Patient.Birthday, even if T0 and Birthday are not known
uint16_t Headsize[3]; /* circumference, nasion-inion, left-right mastoid in millimeter; */
char Name[MAX_LENGTH_NAME+1]; /* because for privacy protection it is by default not supported, support is turned on with FLAG.ANONYMOUS */
// char* Name; // because for privacy protection it is by default not supported, support is turned on with FLAG.ANONYMOUS
/* Patient Name:
* can consist of up to three components, separated by the unit separator ascii(31), 0x1f, containing in that order
Last name, first name, second last name (see also SCP-ECG specification EN1064, Section 1, tag 0, 1, and 3)
* for privacy protection this field is by default not supported, support can be turned on with FLAG.ANONYMOUS
*/
char Name[MAX_LENGTH_NAME+1];
char Id[MAX_LENGTH_PID+1]; /* patient identification, identification code as used in hospital */
uint8_t Weight; /* weight in kilograms [kg] 0:unkown, 255: overflow */
uint8_t Height; /* height in centimeter [cm] 0:unkown, 255: overflow */
......@@ -561,7 +568,7 @@ extern const struct FileFormatStringTable_t FileFormatStringTable [];
# include <endian.h>
# include <byteswap.h>
#elif defined(__WIN32__)
#elif defined(__WIN32__) || defined(_WIN32)
# include <stdlib.h>
# define __BIG_ENDIAN 4321
# define __LITTLE_ENDIAN 1234
......@@ -571,8 +578,9 @@ extern const struct FileFormatStringTable_t FileFormatStringTable [];
# define bswap_64(x) __builtin_bswap64(x)
# include <winsock2.h>
# include <sys/param.h>
# if !defined(_MSC_VER)
# include <sys/param.h>
# endif
# if BYTE_ORDER == LITTLE_ENDIAN
# define htobe16(x) htons(x)
# define htole16(x) (x)
......@@ -584,9 +592,16 @@ extern const struct FileFormatStringTable_t FileFormatStringTable [];
# define be32toh(x) ntohl(x)
# define le32toh(x) (x)
# define htobe64(x) __builtin_bswap64(x)
# define htole64(x) (x)
# define be64toh(x) __builtin_bswap64(x)
# if !defined(_MSC_VER)
# define htobe64(x) __builtin_bswap64(x)
# define be64toh(x) __builtin_bswap64(x)
# else
# define ntohll(x) (((_int64)(ntohl((int)((x << 32) >> 32))) << 32) | (unsigned int)ntohl(((int)(x >> 32))))
# define htonll(x) ntohll(x)
# define htobe64(x) htonll(x)
# define be64toh(x) ntohll(x)
# endif
# define le64toh(x) (x)
# elif BYTE_ORDER == BIG_ENDIAN
......
/*
Copyright (C) 2005-2017 Alois Schloegl <alois.schloegl@gmail.com>
Copyright (C) 2005-2018 Alois Schloegl <alois.schloegl@gmail.com>
Copyright (C) 2011 Stoyan Mihaylov
This file is part of the "BioSig for C/C++" repository
(biosig4c++) at http://biosig.sf.net/
......@@ -3477,7 +3477,7 @@ int read_header(HDRTYPE *hdr) {
size_t count = hdr->HeadLen;
if (hdr->HeadLen<=512) {
ifseek(hdr, count, SEEK_SET);
hdr->AS.Header = (uint8_t*)realloc(hdr->AS.Header, 513);
hdr->AS.Header = (uint8_t*)realloc(hdr->AS.Header, 513);
count += ifread(hdr->AS.Header+hdr->HeadLen, 1, 512-count, hdr);
getfiletype(hdr);
}
......@@ -3718,7 +3718,13 @@ else if (!strncmp(MODE,"r",1)) {
}
#endif
hdr->AS.Header = (uint8_t*)malloc(513);
// modern cpu's have cache lines of 4096 bytes, so for performance reasons we use this size as well.
const size_t PAGESIZE=4096;
/* reading some formats may imply that at least 512 bytes are read,
if you want to use a smaller page size, double check whether your format(s) are correctly handled. */
assert(PAGESIZE >= 512);
hdr->AS.Header = (uint8_t*)malloc(PAGESIZE+1);
size_t k;
#ifndef ONLYGDF
size_t name=0,ext=0;
......@@ -3769,8 +3775,8 @@ else if (!strncmp(MODE,"r",1)) {
curl_easy_cleanup(curl);
/* */
count = ifread(hdr->AS.Header, 1, 512, hdr);
hdr->AS.Header[512]=0;
count = ifread(hdr->AS.Header, 1, PAGESIZE, hdr);
hdr->AS.Header[count]=0;
}
} else
#endif
......@@ -3811,7 +3817,7 @@ else if (!strncmp(MODE,"r",1)) {
return(hdr);
}
if (VERBOSE_LEVEL>7) fprintf(stdout,"SOPEN 101:\n");
count = ifread(hdr->AS.Header, 1, 512, hdr);
count = ifread(hdr->AS.Header, 1, PAGESIZE, hdr);
hdr->AS.Header[count]=0;
......@@ -3823,8 +3829,8 @@ else if (!strncmp(MODE,"r",1)) {
hdr->FILE.gzFID = gzdopen(fileno(hdr->FILE.FID),"r");
hdr->FILE.COMPRESSION = (uint8_t)1;
hdr->FILE.FID = NULL;
count = ifread(hdr->AS.Header, 1, 512, hdr);
hdr->AS.Header[512]=0;
count = ifread(hdr->AS.Header, 1, PAGESIZE, hdr);
hdr->AS.Header[count]=0;
#else
biosigERROR(hdr, B4C_FORMAT_UNSUPPORTED, "Error SOPEN(READ); *.gz file not supported because not linked with zlib.");
#endif
......@@ -8041,12 +8047,13 @@ if (VERBOSE_LEVEL>8)
if (!hdr->FLAG.ANONYMOUS) {
len = min(40, MAX_LENGTH_NAME);
char *s = (char*)(hdr->AS.Header+28);
char *s;
s = (char*)(hdr->AS.Header+68); // lastname
int len1 = min(40, strlen(s));
strncpy(hdr->Patient.Name, s, len1);
hdr->Patient.Name[len] = ' ';
hdr->Patient.Name[len] = 0x1f; // unit separator ascii(31)
s = (char*)(hdr->AS.Header+68);
s = (char*)(hdr->AS.Header+28); // firstname
int len2 = min(strlen(s), MAX_LENGTH_NAME-len-1);
strncpy(hdr->Patient.Name+len1+1, s, len2);
hdr->Patient.Name[len1+len2+1] = 0;
......@@ -10103,20 +10110,23 @@ if (VERBOSE_LEVEL>2)
if (VERBOSE_LEVEL>7) fprintf(stdout,"SOPEN (Persyst) [270] %d<%s>\n",status,line);
if (!hdr->FLAG.ANONYMOUS) {
size_t len = 0;
if (FirstName!=NULL) len = strlen(FirstName);
size_t len = 0, len0=0;
if (SurName!=NULL) len += strlen(SurName);
if (len < MAX_LENGTH_NAME) {
strcpy(hdr->Patient.Name, FirstName);
hdr->Patient.Name[len++]=' ';
strcpy(hdr->Patient.Name, SurName);
hdr->Patient.Name[len]=0x1f;
len0 = ++len;
}
if (MiddleName!=NULL) len += strlen(MiddleName);
if (FirstName!=NULL) len += strlen(FirstName);
if (len < MAX_LENGTH_NAME) {
strcpy(hdr->Patient.Name, MiddleName);
hdr->Patient.Name[len++]=' ';
strcpy(hdr->Patient.Name+len0, FirstName);
hdr->Patient.Name[len]=' ';
len0 = ++len;
}
if (SurName!=NULL) len += strlen(SurName);
if (MiddleName!=NULL) len += strlen(MiddleName);
if (len < MAX_LENGTH_NAME) {
strcpy(hdr->Patient.Name, SurName);
strcpy(hdr->Patient.Name+len0, MiddleName);
hdr->Patient.Name[len0]=' ';
}
hdr->Patient.Name[len]=0;
}
......@@ -13415,10 +13425,10 @@ size_t swrite(const biosig_data_type *data, size_t nelem, HDRTYPE* hdr) {
#ifdef ZLIB_H
if (H1.FILE.COMPRESSION)
gzprintf(H1.FILE.gzFID,"%f\n",i/DIV);
gzprintf(H1.FILE.gzFID,"%g\n",i/DIV);
else
#endif
fprintf(H1.FILE.FID,"%f\n",i/DIV);
fprintf(H1.FILE.FID,"%g\n",i/DIV);
}
}
else if (hdr->TYPE == BIN) {
......@@ -13798,7 +13808,17 @@ if (VERBOSE_LEVEL>7) fprintf(stdout, "asprintf_hdr2json: sz=%i\n", (int)sz);
c += sprintf(STR, "\t\"NumberOfGroupsOrUserSpecifiedEvents\"\t: %d,\n", (unsigned)NumberOfUserSpecifiedEvents);
c += sprintf(STR, "\t\"Patient\"\t: {\n");
if (hdr->Patient.Name) c += sprintf(STR, "\t\t\"Name\"\t: \"%s\",\n", hdr->Patient.Name);
if (strlen(hdr->Patient.Name)) {
c += sprintf(STR, "\t\t\"Name\"\t: \"%s\",\n", hdr->Patient.Name);
char Name[MAX_LENGTH_NAME+1];
strcpy(Name, hdr->Patient.Name);
char *lastname = strtok(Name,"\x1f");
char *firstname = strtok(NULL,"\x1f");
char *secondlastname = strtok(NULL,"\x1f");
c += sprintf(STR, "\t\t\"Lastname\"\t: \"%s\",\n", lastname);
c += sprintf(STR, "\t\t\"Firstname\"\t: \"%s\",\n", firstname);
c += sprintf(STR, "\t\t\"Second_Lastname\"\t: \"%s\",\n", secondlastname);
}
if (hdr->Patient.Id) c += sprintf(STR, "\t\t\"Id\"\t: \"%s\",\n", hdr->Patient.Id);
if (hdr->Patient.Weight) c += sprintf(STR, "\t\t\"Weight\"\t: \"%i kg\",\n", hdr->Patient.Weight);
if (hdr->Patient.Height) c += sprintf(STR, "\t\t\"Height\"\t: \"%i cm\",\n", hdr->Patient.Height);
......@@ -13987,7 +14007,17 @@ int fprintf_hdr2json(FILE *fid, HDRTYPE* hdr)
fprintf(fid,"\t\"NumberOfGroupsOrUserSpecifiedEvents\"\t: %d,\n",(unsigned)NumberOfUserSpecifiedEvents);
fprintf(fid,"\t\"Patient\"\t: {\n");
if (hdr->Patient.Name) fprintf(fid,"\t\t\"Name\"\t: \"%s\",\n", hdr->Patient.Name);
if (strlen(hdr->Patient.Name)) {
fprintf(fid, "\t\t\"Name\"\t: \"%s\",\n", hdr->Patient.Name);
char Name[MAX_LENGTH_NAME+1];
strcpy(Name, hdr->Patient.Name);
char *lastname = strtok(Name,"\x1f");
char *firstname = strtok(NULL,"\x1f");
char *secondlastname = strtok(NULL,"\x1f");
fprintf(fid, "\t\t\"Lastname\"\t: \"%s\",\n", lastname);
fprintf(fid, "\t\t\"Firstname\"\t: \"%s\",\n", firstname);
fprintf(fid, "\t\t\"Second_Lastname\"\t: \"%s\",\n", secondlastname);
}
if (hdr->Patient.Id) fprintf(fid,"\t\t\"Id\"\t: \"%s\",\n", hdr->Patient.Id);
if (hdr->Patient.Weight) fprintf(fid,"\t\t\"Weight\"\t: \"%i kg\",\n", hdr->Patient.Weight);
if (hdr->Patient.Height) fprintf(fid,"\t\t\"Height\"\t: \"%i cm\",\n", hdr->Patient.Height);
......@@ -14157,7 +14187,17 @@ int hdr2ascii(HDRTYPE* hdr, FILE *fid, int VERBOSE)
fprintf(fid, "\tVersion : %s\n",hdr->ID.Manufacturer.Version);
fprintf(fid, "\tSerialNumber : %s\n",hdr->ID.Manufacturer.SerialNumber);
fprintf(fid, "Patient:\n\tID : %s\n",hdr->Patient.Id);
fprintf(fid, "\tName : %s\n",hdr->Patient.Name);
if (strlen(hdr->Patient.Name)) {
fprintf(fid, "\tName : %s\n",hdr->Patient.Name);
char Name[MAX_LENGTH_NAME+1];
strcpy(Name, hdr->Patient.Name);
char *lastname = strtok(Name,"\x1f");
char *firstname = strtok(NULL,"\x1f");
char *secondlastname = strtok(NULL,"\x1f");
fprintf(fid,"\t\tLastname : %s\n",lastname);
fprintf(fid,"\t\tFirstname : %s\n",firstname);
fprintf(fid,"\t\tSecondLastName : %s\n",secondlastname);
}
if (hdr->Patient.Birthday>0)
age = (hdr->T0 - hdr->Patient.Birthday)/ldexp(365.25,32);
......
/*
Copyright (C) 2012,2013,2016,2017 Alois Schloegl <alois.schloegl@gmail.com>
Copyright (C) 2012-2018 Alois Schloegl <alois.schloegl@gmail.com>
This file is part of the "BioSig for C/C++" repository
(biosig4c++) at http://biosig.sf.net/
......@@ -434,6 +434,7 @@ const char* biosig_get_manufacturer_serial_number(HDRTYPE *hdr);
const char* biosig_get_application_specific_information(HDRTYPE *hdr);
int biosig_set_patient_name(HDRTYPE *hdr, const char* rid);
int biosig_set_patient_name_structured(HDRTYPE *hdr, const char* LastName, const char* FirstName, const char* SecondLastName);
int biosig_set_patient_id(HDRTYPE *hdr, const char* rid);
int biosig_set_recording_id(HDRTYPE *hdr, const char* rid);
int biosig_set_technician(HDRTYPE *hdr, const char* rid);
......
/*
Copyright (C) 2012,2013 Alois Schloegl <alois.schloegl@gmail.com>
Copyright (C) 2012-2018 Alois Schloegl <alois.schloegl@gmail.com>
This file is part of the "BioSig for C/C++" repository
(biosig4c++) at http://biosig.sf.net/
......@@ -350,6 +350,36 @@ const char* biosig_get_patient_name(HDRTYPE *hdr) {
if (hdr==NULL) return NULL;
return hdr->Patient.Name;
}
const char* biosig_get_patient_lastname(HDRTYPE *hdr, size_t *LengthLastName) {
if (hdr==NULL) return NULL;
*LengthLastName = strcspn(hdr->Patient.Name, "\x1f");
return hdr->Patient.Name;
}
const char* biosig_get_patient_firstname(HDRTYPE *hdr, size_t *LengthFirstName) {
if (hdr==NULL) return NULL;
char *tmpstr = strchr(hdr->Patient.Name, 0x1f);
if (tmpstr==NULL) {
*LengthFirstName = 0;
return NULL;
}
*LengthFirstName = strcspn(tmpstr, "\x1f");
return tmpstr;
}
const char* biosig_get_patient_secondlastname(HDRTYPE *hdr, size_t *LengthSecondLastName) {
if (hdr==NULL) return NULL;
char *tmpstr = strchr(hdr->Patient.Name, 0x1f);
if (tmpstr != NULL)
tmpstr = strchr(tmpstr, 0x1f);
if (tmpstr==NULL) {
*LengthSecondLastName = 0;
return NULL;
}
*LengthSecondLastName = strcspn(tmpstr, "\x1f");
return tmpstr;
}
const char* biosig_get_patient_id(HDRTYPE *hdr) {
if (hdr==NULL) return NULL;
return hdr->Patient.Id;
......@@ -387,6 +417,26 @@ int biosig_set_patient_name(HDRTYPE *hdr, const char* name) {
if (hdr==NULL) return -1;
strncpy(hdr->Patient.Name, name, MAX_LENGTH_NAME);
hdr->Patient.Name[MAX_LENGTH_NAME]=0;
}
int biosig_set_patient_name_structured(HDRTYPE *hdr, const char* LastName, const char* FirstName, const char* SecondLastName) {
if (hdr==NULL) return -1;
size_t len1 = (LastName ? strlen(LastName) : 0 );
size_t len2 = (FirstName ? strlen(FirstName) : 0 );
size_t len3 = (SecondLastName ? strlen(SecondLastName) : 0 );
if (len1+len2+len3+2 > MAX_LENGTH_NAME) {
fprintf(stderr,"Error in function %f: total length of name too large (%i > %i)\n",__func__,len1+len2+len3+2,MAX_LENGTH_NAME);
return -1;
}
strcpy(hdr->Patient.Name, LastName); // Flawfinder: ignore
if (FirstName != NULL) {
hdr->Patient.Name[len1]=0x1f;
strcpy(hdr->Patient.Name+len1+1, FirstName); // Flawfinder: ignore
}
if (SecondLastName != NULL) {
hdr->Patient.Name[len1+len2+1]=0x1f;
strcpy(hdr->Patient.Name+len1+len2+2, SecondLastName); // Flawfinder: ignore
}
return 0;
}
int biosig_set_patient_id(HDRTYPE *hdr, const char* id) {
......
......@@ -128,6 +128,7 @@ int gdf_time2tm_time_r(gdf_time t, struct tm *t3) {
int32_t rd = (int32_t)floor(ldexp((double)t,-32)); // days since 0001-01-01
double s = ldexp((t & 0x00000000ffffffff)*86400,-32); // seconds of the day
int32_t sec = round (s);
// s += timezone;
/* derived from datenum.m from Octave 3.0.0 */
......@@ -152,10 +153,10 @@ int gdf_time2tm_time_r(gdf_time t, struct tm *t3) {
t3->tm_mon = (int)m-1;
t3->tm_mday = (int)d;
t3->tm_hour = (int)(floor (s / 3600));
s = s - 3600 * t3->tm_hour;
t3->tm_min = (int)(floor (s / 60));
t3->tm_sec = round(s - 60 * t3->tm_min);
t3->tm_hour = sec / 3600;
sec = sec - (3600 * t3->tm_hour);
t3->tm_min = sec / 60;
t3->tm_sec = sec - (60 * t3->tm_min);
//t3->tm_gmtoff = 3600;
return(0);
......
/*
Copyright (C) 2008-2013 Alois Schloegl <alois.schloegl@gmail.com>
Copyright (C) 2008-2013,2018 Alois Schloegl <alois.schloegl@gmail.com>
This file is part of the "BioSig for C/C++" repository
(biosig4c++) at http://biosig.sf.net/
......@@ -567,15 +567,14 @@ if (VERBOSE_LEVEL>6) fprintf(stdout,"HEKA L5 @%i= #%i,%i, %s %g/%g %g/%g \n",(in
}
if ((pdc & 0xFFE0) != (hc->PhysDimCode & 0xFFE0)) {
fprintf(stdout, "Warning: Yunits do not match #%i,%f-%fHz\n",ns, DT[ns],dT);
biosigERROR(hdr, B4C_FORMAT_UNSUPPORTED, "Heka/Patchmaster: Yunits do not match");
fprintf(stdout, "ERROR: [%i,%i,%i,%i] Yunits in %s do not match %04x(%s) ! %04x(%s)\n",k1,k2,k3,k4, Label, pdc, PhysDim3(pdc), hc->PhysDimCode, PhysDim3(hc->PhysDimCode));
biosigERROR(hdr, B4C_FORMAT_UNSUPPORTED, "Heka/Patchmaster: Yunits do not match");
}
if ( ( VERBOSE_LEVEL > 7 ) && ( fabs( DT[ns] - dT) > 1e-9 * dT) ) {
fprintf(stdout, "%s (line %i) different sampling rates [%i,%i,%i,%i]#%i,%f/%f \n",__FILE__,__LINE__,(int)k1,(int)k2,(int)k3,(int)k4,(int)ns, 1.0/DT[ns],1.0/dT);
}
}
if (YOffset) {
biosigERROR(hdr, B4C_FORMAT_UNSUPPORTED, "Heka/Patchmaster: YOffset is not zero");
}
......
/*
Copyright (C) 2005,2006,2007,2011,2012,2013 Alois Schloegl <alois.schloegl@gmail.com>
Copyright (C) 2005-2018 Alois Schloegl <alois.schloegl@gmail.com>
Copyright (C) 2011 Stoyan Mihaylov
This file is part of the "BioSig for C/C++" repository
......@@ -752,18 +752,18 @@ int sopen_SCP_read(HDRTYPE* hdr) {
if (tag==0) {
// convert to UTF8
if (!hdr->FLAG.ANONYMOUS) {
// strncpy(hdr->Patient.Name, (char*)(PtrCurSect+curSectPos),min(len1,MAX_LENGTH_NAME));
// convert to UTF8
// Last name or entire name if no first name is provided
decode_scp_text(hdr, len1, (char*)PtrCurSect+curSectPos, MAX_LENGTH_NAME, hdr->Patient.Name, versionSection);
}
}
else if (tag==1) {
if (!hdr->FLAG.ANONYMOUS) {
// First name
size_t len = strlen(hdr->Patient.Name);
if (len+3 < MAX_LENGTH_NAME) {
strcat(hdr->Patient.Name,", ");
len+=2;
// convert to UTF8
// unit separator ascii(31), 0x1f is used for separating name componentes
strcat(hdr->Patient.Name,"\x1f");
len+=1;
decode_scp_text(hdr, len1, (char*)PtrCurSect+curSectPos, MAX_LENGTH_NAME-len+1, hdr->Patient.Name+len, versionSection);
}
}
......@@ -783,11 +783,12 @@ int sopen_SCP_read(HDRTYPE* hdr) {
}
else if (tag==3) {
if (!hdr->FLAG.ANONYMOUS) {
// Second last name
size_t len = strlen(hdr->Patient.Name);
if (len+2 < MAX_LENGTH_NAME) {
strcat(hdr->Patient.Name," ");
// unit separator ascii(31), 0x1f is used for separating name componentes
strcat(hdr->Patient.Name,"\x1f");
len+=1;
// convert to UTF8
decode_scp_text(hdr, len1, (char*)PtrCurSect+curSectPos, MAX_LENGTH_NAME-len+1, hdr->Patient.Name+len, versionSection);
}
}
......
/*
Copyright (C) 2005,2006,2007,2012,2013,2015 Alois Schloegl <alois.schloegl@ist.ac.at>
Copyright (C) 2005-2018 Alois Schloegl <alois.schloegl@ist.ac.at>
This file is part of the "BioSig for C/C++" repository
(biosig4c++) at http://biosig.sf.net/
......@@ -162,30 +162,34 @@ int sopen_SCP_write(HDRTYPE* hdr) {
ptr = (uint8_t*)realloc(ptr,sectionStart+10000);
PtrCurSect = ptr+sectionStart;
curSectLen = 16; // current section length
char *nextPartOfPatientName=hdr->Patient.Name;
if (VERBOSE_LEVEL>7) fprintf(stdout,"Section 1 Tag 0 \n");
// Tag 0 (max len = 64)
if (!hdr->FLAG.ANONYMOUS && (hdr->Patient.Name != NULL))
if (!hdr->FLAG.ANONYMOUS && (nextPartOfPatientName != NULL) && strlen(nextPartOfPatientName))
{
*(ptr+sectionStart+curSectLen) = 0; // tag
len = strlen(hdr->Patient.Name) + 1;
len = strcspn(nextPartOfPatientName, "\x1f");
leu16a(len, ptr+sectionStart+curSectLen+1); // length
strncpy((char*)ptr+sectionStart+curSectLen+3,hdr->Patient.Name,len); // field
strncpy((char*)ptr+sectionStart+curSectLen+3,nextPartOfPatientName,len); // field
nextPartOfPatientName += len+1;
curSectLen += len+3;
}
if (VERBOSE_LEVEL>7) fprintf(stdout,"Section 1 Tag 1 \n");
// Tag 1 (max len = 64) Firstname
/*
*(ptr+sectionStart+curSectLen) = 1; // tag
len = strlen(hdr->Patient.Name) + 1;
leu16a(len, ptr+sectionStart+curSectLen+1); // length
strncpy((char*)ptr+sectionStart+curSectLen+3,hdr->Patient.Name,len); // field
curSectLen += len+3;
*/
if (!hdr->FLAG.ANONYMOUS && (nextPartOfPatientName != NULL) && strlen(nextPartOfPatientName))
{
*(ptr+sectionStart+curSectLen) = 1; // tag
len = strcspn(nextPartOfPatientName, "\x1f");
leu16a(len, ptr+sectionStart+curSectLen+1); // length
strncpy((char*)ptr+sectionStart+curSectLen+3,nextPartOfPatientName,len); // field
nextPartOfPatientName += len+1;
curSectLen += len+3;
}
// Tag 2 (max len = 64) Patient ID
if (VERBOSE_LEVEL>7) fprintf(stdout,"Section 1 Tag 2 \n");
......@@ -198,16 +202,18 @@ int sopen_SCP_write(HDRTYPE* hdr) {
curSectLen += len+3;
}
// fprintf(stdout,"Section %i Len %i %x\n",curSect,curSectLen,sectionStart);
// Tag 3 (max len = 64) Second Last Name
/*
*(ptr+sectionStart+curSectLen) = 3; // tag
len = strlen(hdr->Patient.Name) + 1;
leu16a(len, ptr+sectionStart+curSectLen+1); // length
strncpy(ptr+sectionStart+curSectLen+3,hdr->Patient.Name,len); // field
curSectLen += len+3;
*/
if (VERBOSE_LEVEL>7) fprintf(stdout,"Section 1 Tag 3 \n");
if (!hdr->FLAG.ANONYMOUS && (nextPartOfPatientName != NULL) && strlen(nextPartOfPatientName))
{
*(ptr+sectionStart+curSectLen) = 3; // tag
len = strcspn(nextPartOfPatientName, "\x1f");
leu16a(len, ptr+sectionStart+curSectLen+1); // length
strncpy((char*)ptr+sectionStart+curSectLen+3,nextPartOfPatientName,len); // field
nextPartOfPatientName += len+1;
curSectLen += len+3;
}
// Tag 5 (len = 4)
if ((hdr->Patient.Birthday) > 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment