#include 'hl7.h' #include <string.h>

/********************************************************************* ********************************************************************/

char * concat(char *string1, char *string2){ //concat:将两个字符串连接起来。

int length1, length2; /* 存储字符串的长度 */

/* 获取第二个字符串的长度 */ length2 = strlen(string2);

/* 如果第二个字符串为空,我们就完成了 */ if (length2==0) return string1;

/* 获取第一个字符串的长度 */ length1 = strlen(string1);

/* 扩展字符串以容纳额外的字符 */ if (string1 = (char *) realloc(string1, length1 + length2 +1)){

/* 将第二个字符串附加到第一个字符串的末尾 */
strncpy(&string1[length1], string2, length2);
string1[length1 + length2] = '\000';   //将string2拼接到string1后,将新字符串的末尾设置为'\0'

/* 返回新字符串 */
return string1;

} else { /* 没有足够的内存,退出 */ exit(1); }

}

/********************************************************************* 为字符串分配内存,将字符串复制到内存中,然后返回指向该内存的指针。 ********************************************************************/

char * strset (char *string) // strset:将一个字符串复制到一个新的内存区域中 {

char *pointer_to_string;

if (pointer_to_string = (char ) malloc (strlen (string)+1)) //计算字符串的长度,然后为字符串分配一个包含该长度加一的空间,最后将该字符串复制到新分配的内存空间中。 { strcpy (pointer_to_string, string); return (pointer_to_string); } else { / 出错 / exit (1); } } / end strset */

/********************************************************************* ********************************************************************/

void hl7count (struct hl7_part_t *message, char *seg_location) { //hl7count:统计HL7消息中特定部分的数量。

} /* end hl7count */

/********************************************************************* ********************************************************************/

void hl7rawcount (struct hl7_part_t *message, char *location) { //hl7rawcount:统计HL7消息中特定部分的数量,不考虑层次结构。

} /* end hl7rawcount */

/********************************************************************* ********************************************************************/

void hl7delete (struct hl7_part_t *message, char *seg_location, char *string){ //hl7delete:删除HL7消息中特定部分的特定字符串。

} /* end hl7delete */

/********************************************************************* ********************************************************************/

void hl7insert (struct hl7_part_t *message, char *seg_location, char *string){ //hl7insert:在HL7消息中特定部分插入特定字符串

} /* end hl7insert */

/********************************************************************* ********************************************************************/

void hl7rawdelete (struct hl7_part_t *message, struct hl7_location_t *location){ // hl7rawdelete:删除HL7消息中特定位置的节点。

} /* end hl7rawdelete */

/********************************************************************* ********************************************************************/

void hl7rawinsert (struct hl7_part_t *message, struct hl7_location_t *location, char *string){ //hl7rawinsert:在HL7消息中特定位置插入特定字符串

} /* end hl7rawinsert */

/********************************************************************* ********************************************************************/

void hl7set (struct hl7_part_t *message, char *seg_location, char *string){ //hl7set:设置HL7消息中特定部分的值。

} /* end hl7set */

/********************************************************************* ********************************************************************/

void hl7get (struct hl7_part_t *message, char *seg_location){ //hl7get:获取HL7消息中特定部分的值。

} /* end hl7get */

/********************************************************************* ********************************************************************/

void hl7rawset (struct hl7_part_t *message, struct hl7_location_t *location, char *string){ // hl7rawset:设置HL7消息中特定位置的值

/* 这个有点难,您必须遍历字符串到给定的位置,创建缺少的节点,然后将最终部分设置为给定的字符串。 */

} /* end hl7rawset */

/********************************************************************* 函数hl7rawget遍历消息到给定位置并返回最佳表示消息结构的字符串。

hl7rawget传入指向消息结构的指针和位置,返回表示该点处消息结构的字符串的指针。

该函数通过遍历消息结构直到到达路径中的NULL或指定位置来工作。

如果它到达NULL,它将返回空字符串。

否则,它到达指定位置并将正确的参数传递给join,以检索正确的字符串。 ********************************************************************/

char *hl7rawget (struct hl7_part_t *message, struct hl7_location_t *given_location){ // hl7rawget:获取HL7消息中特定位置的值

struct hl7_part_t *hl7_part; struct hl7_location_t *location; char msg_string; / 指向消息字符串 / char separators[8]; / 正确顺序中的分隔符列表 */ int i, depth = 0;

/* 初始化返回值字符串的指针 */ msg_string = strset('');

/* 遍历树 */ hl7_part = message->lower; for (location = given_location ; location->next ; location=location->next){

/* 计数器 */
for(i=location->count; i ; i--) {
  if(hl7_part->next){
    hl7_part=hl7_part->next;
  } else {
    return msg_string;
  }
}

/* 向下遍历每个级别 */
if(hl7_part->lower){
  depth++;
  hl7_part=hl7_part->lower;
} else {

/* return msg_string; */ } }

/* 需要将其作为子例程,因为我们刚刚执行了两次 / / 构建分隔符字符串 */ separators[0] = '\n'; separators[1] = '\n'; separators[2] = '\r'; separators[3] = message->lower->lower->lower->next->lower->lower->lower->data[0]; separators[4] = message->lower->lower->lower->next->next->lower->lower->lower->data[3]; separators[5] = message->lower->lower->lower->next->next->lower->lower->lower->data[0]; separators[6] = message->lower->lower->lower->next->next->lower->lower->lower->data[1]; separators[7] = '\000';

printf('深度为 >%d< ', depth); hl7printlocation(given_location);

/* 调用join函数 */ msg_string=join(hl7_part, msg_string, &separators[depth+1]);

/* 返回我们找到的字符串 */ return msg_string;

} /* end hl7rawget */

/********************************************************************* 函数join将使用递归从消息中构建字符串,该字符串基于一组分隔符字符。

join被传递一个指向消息部分的指针、一个分隔符字符的字符串和一个状态,它将返回一个指向包含hl7_message的字符串的指针。

一些特殊的编码

HL7 消息处理库:解析、操作和生成 HL7 消息

原文地址: https://www.cveoy.top/t/topic/npao 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录