⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scp_formatter.cpp

📁 BIOSIG is an open source software library for biomedical signal processing. Library works well with
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
---------------------------------------------------------------------------
Copyright (C) 2005-2006  Franco Chiarugi
Developed at the Foundation for Research and Technology - Hellas, Heraklion, Crete

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
---------------------------------------------------------------------------
*/
/*
// SCP_Formatter.cpp: implementation of the cSCP_Formatter class.
*/

#include "StdAfx.h"
#include "SCPECG_Writer.h"
#include "Section1_Info.h"
#include "ECGSignal_Info.h"
#include "SCP_Formatter.h"
#ifndef VS_DEF
#include <unistd.h>
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

cSCP_Formatter::cSCP_Formatter()
{
	S1I = NULL;
	ESI = NULL;

	lenSect0 = 0;
	lenSect1 = 0;
	lenSect3 = 0;
//	lenSect4 = 0;
//	lenSect5 = 0;
	lenSect6 = 0;
//	lenSect7 = 0;
//	lenSect8 = 0;
//	lenSect10 = 0;
}

cSCP_Formatter::~cSCP_Formatter()
{
}

void  cSCP_Formatter::ResetInfo()
{
	if (S1I != NULL) {
		delete S1I;
		S1I = NULL;
	}

	S1I = new cSection1_Info();

	if (ESI != NULL) {
		delete ESI;
		ESI = NULL;
	}

	ESI = new cECGSignal_Info();
}

int16_t cSCP_Formatter::DoTheSCPFile(char* szFilePathName)
{
	if (szFilePathName == NULL)
		return (-1);

	if ((S1I == NULL) || (ESI == NULL))
		return (-2);

	if (!CreateSCPFileHeaderDraft())
		return (-3);
	if (!CreateSCPSection0Draft())
		return (-4);
	if (!CreateSCPSection1())
		return (-5);
	if (!CreateSCPSection3())
		return (-6);
	//No reference beat is available in XML aECG
	//if (!CreateSCPSection4())
	//	return (-7);
	//if (!CreateSCPSection5())
	//	return (-8);
	if (!CreateSCPSection6())
		return (-9);
	//Global measurements, lead specific measurements and diagnosis are not available
	//if (!CreateSCPSection7())
	//	return (-10);
	//if (!CreateSCPSection8())
	//	return (-11);
	//if (!CreateSCPSection10())
	//	return (-12);

	if (!CorrectSCPSection0())
		return (-13);
	if (!CorrectSCPHeader())
		return (-14);

	if (!WriteSCPFile(szFilePathName))
		return (-15);

	return (0);
}

int16_t cSCP_Formatter::SetLastName(char* szLastName)
{
	if (szLastName == NULL)
		return (-1);

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	strncpy(S1I->szLastName, szLastName, 63);
	S1I->szLastName[63] = '\0';

	if (strlen(szLastName) > 63)
		return (-3);
	else
		return (0);
}

int16_t cSCP_Formatter::GetLastName(char* szLastName)
{
	if (szLastName == NULL)
		return (-1);

	szLastName[0] = '\0';

	if (S1I == NULL)
		return (-2);

	strncpy(szLastName, S1I->szLastName, 63);
	szLastName[63] = '\0';

	return (0);
}

int16_t cSCP_Formatter::SetFirstName(char* szFirstName)
{
	if (szFirstName == NULL)
		return (-1);

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	strncpy(S1I->szFirstName, szFirstName, 63);
	S1I->szFirstName[63] = '\0';

	if (strlen(szFirstName) > 63)
		return (-3);
	else
		return (0);
}

int16_t cSCP_Formatter::GetFirstName(char* szFirstName)
{
	if (szFirstName == NULL)
		return (-1);

	szFirstName[0] = '\0';

	if (S1I == NULL)
		return (-2);

	strncpy(szFirstName, S1I->szFirstName, 63);
	szFirstName[63] = '\0';

	return (0);
}

int16_t cSCP_Formatter::SetPatientID(char* szPatientID)
{
	if (szPatientID == NULL)
		return (-1);

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	strncpy(S1I->szPatientID, szPatientID, 63);
	S1I->szPatientID[63] = '\0';

	if (strlen(szPatientID) > 63)
		return (-3);
	else
		return (0);
}

int16_t cSCP_Formatter::GetPatientID(char* szPatientID)
{
	if (szPatientID == NULL)
		return (-1);

	szPatientID[0] = '\0';

	if (S1I == NULL)
		return (-2);

	strncpy(szPatientID, S1I->szPatientID, 63);
	szPatientID[63] = '\0';

	return (0);
}

int16_t cSCP_Formatter::SetSecondLastName(char* szSecondLastName)
{
	if (szSecondLastName == NULL)
		return (-1);

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	strncpy(S1I->szSecondLastName, szSecondLastName, 63);
	S1I->szSecondLastName[63] = '\0';

	if (strlen(szSecondLastName) > 63)
		return (-3);
	else
		return (0);
}

int16_t cSCP_Formatter::GetSecondLastName(char* szSecondLastName)
{
	if (szSecondLastName == NULL)
		return (-1);

	szSecondLastName[0] = '\0';

	if (S1I == NULL)
		return (-2);

	strncpy(szSecondLastName, S1I->szSecondLastName, 63);
	szSecondLastName[63] = '\0';

	return (0);
}

int16_t cSCP_Formatter::SetDateOfBirth(int16_t dd, int16_t mm, int16_t yyyy)
{
	if ((dd < 1) || (dd > 31))
		return (-1);
	if ((mm < 1) || (mm > 12))
		return (-1);

// Inserted further checks on the date of birth correctness
	// April, June, September and November have 30 days
	if ((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11))
		if (dd == 31)
			return (-1);
	// February cannot have more than 29 days
	if (mm == 2)
		if (dd > 29)
			return (-1);
	// Check on leap years
	if ((yyyy % 4) == 0) {
		if (((yyyy % 100) == 0) && ((yyyy % 400) != 0)) {
			// Not leap
			if (dd == 29)
				return (-1);
		}
		else {
			// Leap (do nothing)
		}
	}

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	S1I->DOB.dd = (uint8_t) ((0x00FF) & dd);
	S1I->DOB.mm = (uint8_t) ((0x00FF) & mm);
	S1I->DOB.yyyy = yyyy;

	return (0);
}

int16_t cSCP_Formatter::GetDateOfBirth(int16_t* dd, int16_t* mm, int16_t* yyyy)
{
	if ((dd == NULL) || (mm == NULL) || (yyyy == NULL)) {
		if (dd != NULL)
			*dd = 0;
		if (mm != NULL)
			*mm = 0;
		if (yyyy != NULL)
			*yyyy = 0;
		return (-1);
	}

	*dd = 0;
	*mm = 0;
	*yyyy = 0;

	if (S1I == NULL)
		return (-2);

	*dd = S1I->DOB.dd;
	*mm = S1I->DOB.mm;
	*yyyy = S1I->DOB.yyyy;

	return (0);
}

int16_t cSCP_Formatter::SetHeight(int16_t height)
{
	if (height < 0)
		return (-1);

// Eventually insert further checks on the height correctness

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	S1I->wHeight = height;

	return (0);
}

int16_t cSCP_Formatter::GetHeight(int16_t* height)
{
	if (height == NULL)
		return (-1);

	*height = 0;

	if (S1I == NULL)
		return (-2);

	*height = S1I->wHeight;

	return (0);
}

int16_t cSCP_Formatter::SetWeight(int16_t weight)
{
	if (weight < 0)
		return (-1);

// Eventually insert further checks on the height correctness

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	S1I->wWeight = weight;

	return (0);
}

int16_t cSCP_Formatter::GetWeight(int16_t* weight)
{
	if (weight == NULL)
		return (-1);

	*weight = 0;

	if (S1I == NULL)
		return (-2);

	*weight = S1I->wWeight;

	return (0);
}

int16_t cSCP_Formatter::SetSex(int16_t sex)
{
	if ((sex != 0) && (sex != 1) && (sex != 2) && (sex != 9))
		return (-1);

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	S1I->bSex = (uint8_t) sex;

	return (0);
}

int16_t cSCP_Formatter::GetSex(int16_t* sex)
{
	if (sex == NULL)
		return (-1);

	*sex = 0;

	if (S1I == NULL)
		return (-2);

	*sex = S1I->bSex;

	return (0);
}

int16_t cSCP_Formatter::SetSBP(int16_t SBP)
{
	if (SBP < 0)
		return (-1);

// Eventually insert further checks on the SBP correctness

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	S1I->wSBP = SBP;

	return (0);
}

int16_t cSCP_Formatter::GetSBP(int16_t* SBP)
{
	if (SBP == NULL)
		return (-1);

	*SBP = 0;

	if (S1I == NULL)
		return (-2);

	*SBP = S1I->wSBP;

	return (0);
}

int16_t cSCP_Formatter::SetDBP(int16_t DBP)
{
	if (DBP < 0)
		return (-1);

// Eventually insert further checks on the DBP correctness

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	S1I->wDBP = DBP;

	return (0);
}

int16_t cSCP_Formatter::GetDBP(int16_t* DBP)
{
	if (DBP == NULL)
		return (-1);

	*DBP = 0;

	if (S1I == NULL)
		return (-2);

	*DBP = S1I->wDBP;

	return (0);
}

int16_t cSCP_Formatter::SetReferringPhysician(char* RefPhys)
{
	if (RefPhys == NULL)
		return (-1);

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	strncpy(S1I->szRefPhys, RefPhys, 63);
	S1I->szRefPhys[63] = '\0';

	if (strlen(RefPhys) > 63)
		return (-3);
	else
		return (0);
}

int16_t cSCP_Formatter::GetReferringPhysician(char* RefPhys)
{
	if (RefPhys == NULL)
		return (-1);

	RefPhys[0] = '\0';

	if (S1I == NULL)
		return (-2);

	strncpy(RefPhys, S1I->szRefPhys, 63);
	RefPhys[63] = '\0';

	return (0);
}

int16_t cSCP_Formatter::SetLastConfirmingPhys(char* LCPhys)
{
	if (LCPhys == NULL)
		return (-1);

	if (S1I == NULL) {
		S1I = new cSection1_Info();
	}

	if (S1I == NULL)
		return (-2);

	strncpy(S1I->szLCPhys, LCPhys, 63);
	S1I->szLCPhys[63] = '\0';

	if (strlen(LCPhys) > 63)
		return (-3);
	else
		return (0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -