【问题标题】:How can I insert Billing Information after Providing Patient Diagnosis Information in one-to-one relationship One after another如何在一对一关系中提供患者诊断信息后插入计费信息一个接一个
【发布时间】:2017-09-30 03:47:57
【问题描述】:

我正在尝试制作的应用程序是医院管理系统。在 EnterPatientDiagnosis 表格(最后给出截图)中,我需要首先添加患者的诊断信息,然后我需要添加其相关的账单信息。在这里,两个表的主键列都是一个标识列。 这是许多系统中的常见步骤。但我仍然找不到有关如何实现它的详细信息。

我想到的一个解决方案是使用存储过程插入所有保持 FK_billId 属性为 Null 的诊断信息,并从存储过程中获取 DiagnosisId 作为输出参数。然后当用户提交账单信息时,我将使用 BillId 和 DiagnosisId 更新诊断表中先前插入的行。但我不喜欢这种方法有两个原因:

首先因为它有一个额外的更新查询。因为,如果我使用 DiagnosisId 作为这 2 个数据库表之间的外键而不是 BillId,那么就不会是否需要此更新查询。但是我还没有找到任何关于在一对一关系中应该使用哪个键作为 FK 的规则/优先级。

其次它与我创建的实体类冲突。我在实体层中为这 2 个表手动创建了 2 个类。因此,如果我想通过实体层插入行,那么我将不得不为 Billing 类提供一个名为 DiagnosisId 的新属性,这与我的数据库表架构相矛盾。 这是实体层中的 2 个类:

public class EntityPatientDiagnosis
{
    //Diagnosis Id is automatically assigned   
    public int DiagnosisId { get; set; }
    public int PatientId { get; set; }


    public string Symptoms { get; set; }
    public string DiagnosisProvided { get; set;}

    public string AdministeredBy { get; set; }

    public DateTime DateofDiagnosis { get; set; }
    public string FollowUpRequired { get; set; }
    public DateTime DateOfFollowUp { get; set; }
    public int BillId { get; set; } //BillId -> Foreign Key 

}

public class EntityBilling
{
    //BillId -> Primary Key ->set automatically
    public int BillId { get; set; } 
    public int BillAmount { get; set; }
    public string CardNumber { get; set; }
    public string ModeOfPayment { get; set; }
}

这是表格和 Web 表单的 ERD 的图片:

【问题讨论】:

  • 不确定我是否完全理解。但是您可以将信息保留在您的类对象中,直到添加计费信息。一旦你拥有了两者,首先插入到账单表中,这会给你 BillId 用作诊断表的 FK。

标签: c# asp.net sql-server webforms one-to-one


【解决方案1】:

您可以尝试不同的方法。您可以更改实体 PatientDiagnosis 和 Billing 之间的关系。因此,首先您可以创建一个 PatientDiagnosis 条目,然后为其创建一个 Billing 条目。

public class EntityPatientDiagnosis
{
    //Diagnosis Id is automatically assigned   
    public int DiagnosisId { get; set; }
    public int PatientId { get; set; }
    public string Symptoms { get; set; }
    public string DiagnosisProvided { get; set;}
    public string AdministeredBy { get; set; }
    public DateTime DateofDiagnosis { get; set; }
    public string FollowUpRequired { get; set; }
    public DateTime DateOfFollowUp { get; set; }

}


public class EntityBilling
{
    //BillId -> Primary Key ->set automatically
    public int BillId { get; set; }

    //DiagnosisId -> Foreign Key  unique
    public int DiagnosisId { get; set; }

    public int BillAmount { get; set; }
    public string CardNumber { get; set; }
    public string ModeOfPayment { get; set; }
}

【讨论】:

  • 两个实体之间的关系取决于它们的交互以及它们在系统中的定义方式。如果在你的系统中,一个诊断有多个账单,你应该使用一对多的关系,如果没有,你可以使用一对一的关系。
  • 我在我的帖子“首先,因为它有一个额外的更新查询......”中也提到了这一点。但我不想这样做,因为首先我给定的项目要求是这样设置表架构的。我也不明白为什么当你改变关系时它会起作用。因为它是一对一的关系,据我所知,它不应该对我用来建立关系的表的主键有任何影响。即使它在这里产生了明显的不同。我也想知道不同的在线商店和其他系统/网站是如何做到的。
猜你喜欢
  • 2021-10-13
  • 1970-01-01
  • 1970-01-01
  • 2015-11-06
  • 1970-01-01
  • 1970-01-01
  • 2021-01-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多