sopen_hl7aecg.c

来自「c++编写的用于生物信号处理的软件库」· C语言 代码 · 共 639 行 · 第 1/2 页

C
639
字号
    t0->tm_sec += timezone;     mktime(t0);//    t0->tm_gmtoff=0;    sprintf(timelow, "%4d%2d%2d%2d%2d%2d.000", t0->tm_year+1900, t0->tm_mon+1, t0->tm_mday, t0->tm_hour, t0->tm_min, t0->tm_sec);    sprintf(timehigh, "%4d%2d%2d%2d%2d%2d.000", t0->tm_year+1900, t0->tm_mon+1, t0->tm_mday, t0->tm_hour, t0->tm_min, t0->tm_sec+hdr->SPR/((int)hdr->SampleRate));    for(int i=0; i<18; ++i){	if(timelow[i] == ' ')	    timelow[i] = '0';	if(timehigh[i] == ' ')	    timehigh[i] = '0';    }    TiXmlElement *effectiveTime = new TiXmlElement("effectiveTime");    TiXmlElement *effectiveTimeLow = new TiXmlElement("low");    effectiveTimeLow->SetAttribute("value", timelow);    effectiveTime->LinkEndChild(effectiveTimeLow);    TiXmlElement *effectiveTimeHigh = new TiXmlElement("high");    effectiveTimeHigh->SetAttribute("value", timehigh);    effectiveTime->LinkEndChild(effectiveTimeHigh);    root->LinkEndChild(effectiveTime);    TiXmlElement *rootComponentOf = new TiXmlElement("componentOf");    rootComponentOf->SetAttribute("typeCode", "COMP");    rootComponentOf->SetAttribute("contextConductionInd", "true");    root->LinkEndChild(rootComponentOf);        TiXmlElement *timePointEvent = new TiXmlElement("timepointEvent");    timePointEvent->SetAttribute("classCode", "CTTEVENT");    timePointEvent->SetAttribute("moodCode", "EVN");    rootComponentOf->LinkEndChild(timePointEvent);        TiXmlElement *timePointComponentOf = new TiXmlElement("componentOf");    timePointComponentOf->SetAttribute("typeCode", "COMP");    timePointComponentOf->SetAttribute("contextConductionInd", "true");    timePointEvent->LinkEndChild(timePointComponentOf);    TiXmlElement *subjectAssignment = new TiXmlElement("subjectAssignment");    subjectAssignment->SetAttribute("classCode", "CLNTRL");    subjectAssignment->SetAttribute("moodCode", "EVN");    timePointComponentOf->LinkEndChild(subjectAssignment);    TiXmlElement *subject = new TiXmlElement("subject");    subject->SetAttribute("typeCode", "SBJ");    subject->SetAttribute("contextControlCode", "OP");    subjectAssignment->LinkEndChild(subject);    TiXmlElement *trialSubject = new TiXmlElement("trialSubject");    trialSubject->SetAttribute("classCode", "RESBJ");    subject->LinkEndChild(trialSubject);        if (strlen(hdr->Patient.Id)>0) {	    	TiXmlElement *trialSubjectId = new TiXmlElement("id");    	trialSubjectId->SetAttribute("extension", hdr->Patient.Id);    	trialSubject->LinkEndChild(trialSubjectId);    }    TiXmlElement *trialSubjectDemographicPerson = new TiXmlElement("subjectDemographicPerson");    trialSubjectDemographicPerson->SetAttribute("classCode", "PSN");    trialSubjectDemographicPerson->SetAttribute("determinerCode", "INSTANCE");    trialSubject->LinkEndChild(trialSubjectDemographicPerson);    if (strlen(hdr->Patient.Name)>0)    if (!hdr->FLAG.ANONYMOUS)     {		TiXmlElement *subjectDemographicPersonName = new TiXmlElement("name");    	TiXmlText *nameText = new TiXmlText(hdr->Patient.Name);    	subjectDemographicPersonName->LinkEndChild(nameText);    	trialSubjectDemographicPerson->LinkEndChild(subjectDemographicPersonName);    }        TiXmlElement *subjectDemographicPersonGender = new TiXmlElement("administrativeGenderCode");    if(hdr->Patient.Sex == 1){	subjectDemographicPersonGender->SetAttribute("code", "M");	subjectDemographicPersonGender->SetAttribute("displayName", "Male");    }    else if(hdr->Patient.Sex == 2){	subjectDemographicPersonGender->SetAttribute("code", "F");	subjectDemographicPersonGender->SetAttribute("displayName", "Female");    }    else{	subjectDemographicPersonGender->SetAttribute("code", "UN");	subjectDemographicPersonGender->SetAttribute("displayName", "Undefined");    }    subjectDemographicPersonGender->SetAttribute("codeSystem", "2.16.840.1.113883.5.1");    subjectDemographicPersonGender->SetAttribute("codeSystemName", "AdministrativeGender");    trialSubjectDemographicPerson->LinkEndChild(subjectDemographicPersonGender);    T0 = gdf_time2t_time(hdr->Patient.Birthday);    t0 = gmtime(&T0);    sprintf(tmp, "%04d%02d%02d%02d%02d%02d.000", t0->tm_year+1900, t0->tm_mon+1, t0->tm_mday, t0->tm_hour, t0->tm_min, t0->tm_sec);    TiXmlElement *subjectDemographicPersonBirthtime = new TiXmlElement("birthTime");    subjectDemographicPersonBirthtime->SetAttribute("value", tmp);    trialSubjectDemographicPerson->LinkEndChild(subjectDemographicPersonBirthtime);	/* write non-standard fields height and weight */    if (hdr->Patient.Weight) {    	sprintf(tmp,"%i",hdr->Patient.Weight);     	TiXmlElement *subjectDemographicPersonWeight = new TiXmlElement("weight");    	subjectDemographicPersonWeight->SetAttribute("value", tmp);    	subjectDemographicPersonWeight->SetAttribute("unit", "kg");    	trialSubjectDemographicPerson->LinkEndChild(subjectDemographicPersonWeight);    }    if (hdr->Patient.Height) {	    	sprintf(tmp,"%i",hdr->Patient.Height);     	TiXmlElement *subjectDemographicPersonHeight = new TiXmlElement("height");    	subjectDemographicPersonHeight->SetAttribute("value", tmp);    	subjectDemographicPersonHeight->SetAttribute("unit", "cm");    	trialSubjectDemographicPerson->LinkEndChild(subjectDemographicPersonHeight);    }    TiXmlElement *subjectAssignmentComponentOf = new TiXmlElement("componentOf");    subjectAssignmentComponentOf->SetAttribute("typeCode", "COMP");    subjectAssignmentComponentOf->SetAttribute("contextConductionInd", "true");    subjectAssignment->LinkEndChild(subjectAssignmentComponentOf);    TiXmlElement *clinicalTrial = new TiXmlElement("clinicalTrial");    clinicalTrial->SetAttribute("classCode", "CLNTRL");    clinicalTrial->SetAttribute("moodCode", "EVN");    subjectAssignmentComponentOf->LinkEndChild(clinicalTrial);    TiXmlElement *clinicalTrialId = new TiXmlElement("id");    clinicalTrialId->SetAttribute("root", "GRATZ");    clinicalTrialId->SetAttribute("extension", "CLINICAL_TRIAL");    clinicalTrial->LinkEndChild(clinicalTrialId);        TiXmlElement *rootComponent = new TiXmlElement("component");    rootComponent->SetAttribute("typeCode", "COMP");    rootComponent->SetAttribute("contextConductionInd", "true");    root->LinkEndChild(rootComponent);        TiXmlElement *series = new TiXmlElement("series");    series->SetAttribute("classCode", "OBSSER");    series->SetAttribute("moodCode", "EVN");    rootComponent->LinkEndChild(series);        TiXmlElement *seriesCode = new TiXmlElement("code");    seriesCode->SetAttribute("code", "RHYTHM");    seriesCode->SetAttribute("seriesCode", "2.16.840.1.113883.5.4");    series->LinkEndChild(seriesCode);        TiXmlElement *seriesEffectiveTime = new TiXmlElement("effectiveTime");    TiXmlElement *seriesEffectiveTimeLow = new TiXmlElement("low");    seriesEffectiveTimeLow->SetAttribute("value", timelow);    seriesEffectiveTime->LinkEndChild(seriesEffectiveTimeLow);    TiXmlElement *seriesEffectiveTimeHigh = new TiXmlElement("high");    seriesEffectiveTimeHigh->SetAttribute("value", timehigh);    seriesEffectiveTime->LinkEndChild(seriesEffectiveTimeHigh);    series->LinkEndChild(seriesEffectiveTime);        for(int i=3; i; --i){	    TiXmlElement *seriesControlVariable = new TiXmlElement("controlVariable");	    seriesControlVariable->SetAttribute("typeCode", "CTRLV");	    series->LinkEndChild(seriesControlVariable);	    	    TiXmlElement *CTRLControlVariable = new TiXmlElement("controlVariable");	    CTRLControlVariable->SetAttribute("classCode", "OBS");	    seriesControlVariable->LinkEndChild(CTRLControlVariable);	    	    TiXmlElement *controlVariableCode = new TiXmlElement("code");	    CTRLControlVariable->LinkEndChild(controlVariableCode);    	    TiXmlElement *controlVariableComponent = new TiXmlElement("component");	    controlVariableComponent->SetAttribute("typeCode", "COMP");	    CTRLControlVariable->LinkEndChild(controlVariableComponent);	    	    TiXmlElement *componentControlVariable = new TiXmlElement("controlVariable");	    componentControlVariable->SetAttribute("classCode", "OBS");	    controlVariableComponent->LinkEndChild(componentControlVariable);	    	    TiXmlElement *componentControlVariableCode = new TiXmlElement("code");	    componentControlVariable->LinkEndChild(componentControlVariableCode);	    	    TiXmlElement *componentControlVariableValue = new TiXmlElement("value");	    componentControlVariableValue->SetAttribute("xsi:type", "PQ");	    componentControlVariable->LinkEndChild(componentControlVariableValue);	    	    switch(i){		case 3:		    controlVariableCode->SetAttribute("code", "MDC_ATTR_FILTER_NOTCH");		    componentControlVariableCode->SetAttribute("code", "MDC_ATTR_NOTCH_FREQ");		    componentControlVariableValue->SetDoubleAttribute("value", hdr->CHANNEL[0].Notch);		    break;		case 2:		    		    controlVariableCode->SetAttribute("code", "MDC_ATTR_FILTER_LOW_PASS");		    componentControlVariableCode->SetAttribute("code", "MDC_ATTR_FILTER_CUTOFF_FREQ");		    componentControlVariableValue->SetDoubleAttribute("value", hdr->CHANNEL[0].LowPass);		    break;		case 1:		    controlVariableCode->SetAttribute("code", "MDC_ATTR_FILTER_HIGH_PASS");		    componentControlVariableCode->SetAttribute("code", "MDC_ATTR_FILTER_CUTOFF_FREQ");		    componentControlVariableValue->SetDoubleAttribute("value", hdr->CHANNEL[0].HighPass);		    break;	    }	    	    controlVariableCode->SetAttribute("codeSystem", "2.16.840.1.113883.6.24");	    controlVariableCode->SetAttribute("codeSystemName", "MDC");	    componentControlVariableCode->SetAttribute("codeSystem", "2.16.840.1.113883.6.24");	    componentControlVariableCode->SetAttribute("codeSystemName", "MDC");	    componentControlVariableValue->SetAttribute("unit", "Hz");	    	    switch(i){		case 3:		    controlVariableCode->SetAttribute("displayName", "Notch Filter");		    componentControlVariableCode->SetAttribute("displayName", "Notch Frequency");		    break;		case 2:		    		    controlVariableCode->SetAttribute("displayName", "Low Pass Filter");		    componentControlVariableCode->SetAttribute("displayName", "Cutoff Frequency");		    break;		case 1:		    controlVariableCode->SetAttribute("displayName", "High Pass Filter");		    componentControlVariableCode->SetAttribute("displayName", "Cutoff Frequency");		    break;	    }    }        TiXmlElement *seriesComponent = new TiXmlElement("component");    seriesComponent->SetAttribute("typeCode", "COMP");    seriesComponent->SetAttribute("contextConductionInd", "true");    series->LinkEndChild(seriesComponent);        TiXmlElement *sequenceSet = new TiXmlElement("sequenceSet");    sequenceSet->SetAttribute("classCode", "OBSCOR");    sequenceSet->SetAttribute("moodCode", "EVN");    seriesComponent->LinkEndChild(sequenceSet);        TiXmlElement *sequenceSetComponent = new TiXmlElement("component");    sequenceSetComponent->SetAttribute("typeCode", "COMP");    sequenceSetComponent->SetAttribute("contextConductionInd", "true");    sequenceSet->LinkEndChild(sequenceSetComponent);        TiXmlElement *sequence = new TiXmlElement("sequence");    sequence->SetAttribute("classCode", "OBS");    sequence->SetAttribute("moodCode", "EVN");        sequenceSetComponent->LinkEndChild(sequence);        TiXmlElement *sequenceCode = new TiXmlElement("code");    sequenceCode->SetAttribute("code", "TIME_ABSOLUTE");    sequenceCode->SetAttribute("codeSystem", "2.16.840.1.113883.6.24");    sequence->LinkEndChild(sequenceCode);    TiXmlElement *sequenceValue = new TiXmlElement("value");    sequenceValue->SetAttribute("xsi:type", "GLIST_TS");    sequence->LinkEndChild(sequenceValue);    TiXmlElement *valueHead = new TiXmlElement("head");    valueHead->SetAttribute("value", timelow);    valueHead->SetAttribute("unit", "s");    sequenceValue->LinkEndChild(valueHead);    TiXmlElement *valueIncrement = new TiXmlElement("increment");    valueIncrement->SetDoubleAttribute("value", 1/hdr->SampleRate);    valueIncrement->SetAttribute("unit", "s");    sequenceValue->LinkEndChild(valueIncrement);    TiXmlText *digitsText;    for(int i=0; i<hdr->NS; ++i){	sequenceSetComponent = new TiXmlElement("component");	sequenceSetComponent->SetAttribute("typeCode", "COMP");	sequenceSetComponent->SetAttribute("contextConductionInd", "true");	sequenceSet->LinkEndChild(sequenceSetComponent);	sequence = new TiXmlElement("sequence");	sequence->SetAttribute("classCode", "OBS");	sequence->SetAttribute("moodCode", "EVN");	sequenceSetComponent->LinkEndChild(sequence);	sequenceCode = new TiXmlElement("code");		strcpy(tmp,"MDC_ECG_LEAD_");	strcat(tmp,LEAD_ID_TABLE[hdr->CHANNEL[i].LeadIdCode]);		sequenceCode->SetAttribute("code", tmp);	sequenceCode->SetAttribute("codeSystem", "2.16.840.1.113883.6.24");	sequenceCode->SetAttribute("codeSystemName", "MDC");	sequence->LinkEndChild(sequenceCode);    	sequenceValue = new TiXmlElement("value");	sequenceValue->SetAttribute("xsi:type", "SLIST_PQ");	sequence->LinkEndChild(sequenceValue);	// store physical unit in tmp 	PhysDim(hdr->CHANNEL[i].PhysDimCode,tmp); 	valueHead = new TiXmlElement("origin");	valueHead->SetDoubleAttribute("value", hdr->CHANNEL[i].Off);	// valueHead->SetDoubleAttribute("value", 0);	valueHead->SetAttribute("unit", tmp);	sequenceValue->LinkEndChild(valueHead);	valueIncrement = new TiXmlElement("scale");	valueIncrement->SetDoubleAttribute("value", hdr->CHANNEL[i].Cal);	//valueIncrement->SetDoubleAttribute("value", 1);	valueIncrement->SetAttribute("unit", tmp);	sequenceValue->LinkEndChild(valueIncrement);	TiXmlElement *valueDigits = new TiXmlElement("digits");	sequenceValue->LinkEndChild(valueDigits);	std::stringstream digitsStream;		for(unsigned int j=0; j<hdr->CHANNEL[i].SPR; ++j)	    digitsStream << (*(int32_t*)(hdr->AS.rawdata + hdr->AS.bi[i] + j*GDFTYP_BYTE[hdr->CHANNEL[i].GDFTYP])) << " ";//	    digitsStream << hdr->data.block[hdr->SPR*i + j] << " ";	digitsText = new TiXmlText(digitsStream.str().c_str());	valueDigits->LinkEndChild(digitsText);    }    doc.SaveFile(hdr->FileName);//    doc.SaveFile(hdr);    return(0);};

⌨️ 快捷键说明

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