如何通过 C# 使用 Fhir R4 添加遭遇
How to add encounter using Fhir R4 by c#
我试过添加新遭遇,但它显示“System.NullReferenceException:'Object reference not set to an instance of an object'”。这是我的代码:
private static void AddEncounter()
{
var encount = new Encounter();
encount.Identifier.Add(new Identifier
{
Use = (Identifier.IdentifierUse?)1,
System = "http://www.amc.nl/zorgportal/identifiers/visits",
Value = "tek001"
}) ;
encount.Class = new Coding("http://terminology.hl7.org/CodeSystem/v3-ActCode", "SS", "Lưu trú ngắn hạn");
encount.Status = 0;
encount.Priority = new CodeableConcept("http://terminology.hl7.org/CodeSystem/v3-ActPriority", "R", "routine");
encount.Subject = new ResourceReference("Patient/a07b880381ec44ad8f80743f396c8011/_history/1", "Lâm");
encount.Length.Value = 120;
encount.Length.Unit = "min";
encount.Length.System = "http://unitsofmeasure.org";
encount.Length.Code = "min";
encount.ReasonCode.Add(new CodeableConcept("http://snomed.info/sct", "184004", "Rối loạn nhịp tim rút"));
encount.Hospitalization.PreAdmissionIdentifier.Use = (Identifier.IdentifierUse?)1;
encount.Hospitalization.PreAdmissionIdentifier.System = "http://www.amc.nl/zorgportal/identifiers/pre-admissions";
encount.Hospitalization.PreAdmissionIdentifier.Value = "1598753";
encount.Hospitalization.AdmitSource = new CodeableConcept("http://terminology.hl7.org/CodeSystem/admit-source", "outp", "Khoa ngoại trú");
encount.Hospitalization.DischargeDisposition = new CodeableConcept("http://terminology.hl7.org/CodeSystem/discharge-disposition", "hosp", "Bệnh nhân đã được xuất viện và chăm sóc giảm nhẹ");
Console.WriteLine("Successful");
Console.ReadLine();
}
我怎样才能准确添加一个?
如果没有看到整个 class
很难确定,但是在尝试访问尚未实例化的内容时会抛出 System.NullReferenceException
。
encount.Hospitalization
可能是对另一个必须首先实例化的 class
的引用。 尝试在访问之前先创建和实例(下面的示例)。
encount.Length = new Length();
encount.Hospitalization = new Hospitalization();
注意:我猜是 class
名称(Length
和 Hospitalization
),因此您可能需要针对您的代码进行调整.主要思想是您必须在 utilizing\accessing.
之前创建 class
(new ...()
)
就像您为标识符字段创建标识符以及为 Class、优先级和主题字段创建其他复杂对象一样,您需要为长度字段创建持续时间:
encount.Length = new Duration();
encount.Length.Value = 120;
// etc.
您必须对您在代码中使用的所有复杂对象执行此操作,因此对于 Hospitalization 字段和 PreAdmissionIdentifier:
encount.Hospitalization = new Encounter.HospitalizationComponent();
encount.Hospitalization.PreAdmissionIdentifier = new Identifier();
// etc.
我想建议的另一项更改是使用枚举中提供的值作为标识符使用,使您的代码更具可读性并明确您的意图:
encount.Hospitalization.PreAdmissionIdentifier.Use = Identifier.IdentifierUse.Official;
我试过添加新遭遇,但它显示“System.NullReferenceException:'Object reference not set to an instance of an object'”。这是我的代码:
private static void AddEncounter()
{
var encount = new Encounter();
encount.Identifier.Add(new Identifier
{
Use = (Identifier.IdentifierUse?)1,
System = "http://www.amc.nl/zorgportal/identifiers/visits",
Value = "tek001"
}) ;
encount.Class = new Coding("http://terminology.hl7.org/CodeSystem/v3-ActCode", "SS", "Lưu trú ngắn hạn");
encount.Status = 0;
encount.Priority = new CodeableConcept("http://terminology.hl7.org/CodeSystem/v3-ActPriority", "R", "routine");
encount.Subject = new ResourceReference("Patient/a07b880381ec44ad8f80743f396c8011/_history/1", "Lâm");
encount.Length.Value = 120;
encount.Length.Unit = "min";
encount.Length.System = "http://unitsofmeasure.org";
encount.Length.Code = "min";
encount.ReasonCode.Add(new CodeableConcept("http://snomed.info/sct", "184004", "Rối loạn nhịp tim rút"));
encount.Hospitalization.PreAdmissionIdentifier.Use = (Identifier.IdentifierUse?)1;
encount.Hospitalization.PreAdmissionIdentifier.System = "http://www.amc.nl/zorgportal/identifiers/pre-admissions";
encount.Hospitalization.PreAdmissionIdentifier.Value = "1598753";
encount.Hospitalization.AdmitSource = new CodeableConcept("http://terminology.hl7.org/CodeSystem/admit-source", "outp", "Khoa ngoại trú");
encount.Hospitalization.DischargeDisposition = new CodeableConcept("http://terminology.hl7.org/CodeSystem/discharge-disposition", "hosp", "Bệnh nhân đã được xuất viện và chăm sóc giảm nhẹ");
Console.WriteLine("Successful");
Console.ReadLine();
}
我怎样才能准确添加一个?
如果没有看到整个 class
很难确定,但是在尝试访问尚未实例化的内容时会抛出 System.NullReferenceException
。
encount.Hospitalization
可能是对另一个必须首先实例化的 class
的引用。 尝试在访问之前先创建和实例(下面的示例)。
encount.Length = new Length();
encount.Hospitalization = new Hospitalization();
注意:我猜是 class
名称(Length
和 Hospitalization
),因此您可能需要针对您的代码进行调整.主要思想是您必须在 utilizing\accessing.
class
(new ...()
)
就像您为标识符字段创建标识符以及为 Class、优先级和主题字段创建其他复杂对象一样,您需要为长度字段创建持续时间:
encount.Length = new Duration();
encount.Length.Value = 120;
// etc.
您必须对您在代码中使用的所有复杂对象执行此操作,因此对于 Hospitalization 字段和 PreAdmissionIdentifier:
encount.Hospitalization = new Encounter.HospitalizationComponent();
encount.Hospitalization.PreAdmissionIdentifier = new Identifier();
// etc.
我想建议的另一项更改是使用枚举中提供的值作为标识符使用,使您的代码更具可读性并明确您的意图:
encount.Hospitalization.PreAdmissionIdentifier.Use = Identifier.IdentifierUse.Official;