坚持决定智能合同项目的工作

发布于 2025-01-22 15:23:49 字数 886 浏览 0 评论 0原文

因此,我正在进行一个项目,该项目基本上是在智能合同的帮助下进行医疗保险索赔程序。它的工作方式是:

  1. 用户签署由保险公司运营的网站。
  2. 他们通过进入相关医院,保险金额和一个包含账单的PDF文件来提出索赔。
  3. 医院使用网站根据提供的信息批准/拒绝索赔。
  4. 保险公司使用网站批准/拒绝基于提供的信息并向用户支付索赔。
  5. 每当有人申请/批准/拒绝,支付索赔时,就会发出事件。

这是我的第一个以太坊/固体项目,我无法弄清楚如何将其集在一起。

这是主张的结构:

struct Record {
        uint id; // unique id for the record
        address patientAddr;
        address hospitalAddr;
        string billId; // points to the pdf stored somewhere
        uint amount; 
        mapping (address => RecordStatus) status; // status of the record
        bool isValid; // variable to check if record has already been created or not
    }

我的一些问题是:

  1. 如何将记录链接到特定用户?作为一个用户可以使用多个元掩体钱包。
  2. 是否可以获取所有带有ID的特定记录的事件,以便我可以向用户显示记录中发生的所有批准/拒绝?
  3. 对于医院而言,除了从智能合约中获取所有记录并在前端过滤外,是否有更好的方法获得相关记录?

非常感谢您的帮助。

So I'm doing a project which basically carries out the medical insurance claim process with the help of the smart contract. How it works is:

  1. User signs up to the website run by the insurer.
  2. They file a claim by entering the concerned hospital, insured amount and a pdf file containing the bills which are to be verified.
  3. The hospital uses the website to approve/deny the claim based on the info provided.
  4. The insurer uses the website approve/deny the claim based on the info provided and pays the user.
  5. Any time someone files, approves/denies, pays the claim, an event is emitted.

This is my first ethereum/solidity project and I'm unable to figure out how to pull this together.

This is the structure of a Claim:

struct Record {
        uint id; // unique id for the record
        address patientAddr;
        address hospitalAddr;
        string billId; // points to the pdf stored somewhere
        uint amount; 
        mapping (address => RecordStatus) status; // status of the record
        bool isValid; // variable to check if record has already been created or not
    }

Some of my questions were:

  1. How do I link a Record to a specific user? As a single user can use multiple Metamask wallets.
  2. Is it possible to fetch all the events linked to a specific record with an id so I can display all the approvals/denials happened with the Record to the user?
  3. For the hospital, is there a better way to get associated Records other than to get all Records from the smart contract and then filter it on the front end?

Thanks a lot for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨后彩虹 2025-01-29 15:23:50

要将记录链接到特定用户,您需要添加映射(我假设您拥有一个用户ID),该映射看起来像这样:

mapping(uint => Record[]) recordsByUserID;

那么您将能够获得一系列记录,了解用户ID

Records userRecords[] = recordsByUserID[user_id];

:事件记录实际上很容易,因为我们有索引关键字,让我向您展示一个示例:

event Approved(uint indexed userId, uint indexed recordId);

使用此类事件,您可以使用用户ID和记录ID查询所有事件。

关于第三个问题,我建议您使用图形 https://thegraph.com/en/ 。它基本上通过以非常简单的方式为您索引所有事件来创建您自己的GraphQL后端。然后,您可以运行GraphQl查询并提高一些效率。

To link a Record to specific user you will need to add a mapping (I am assuming that you have a user ID) that will look like this:

mapping(uint => Record[]) recordsByUserID;

Then you will be able to get an array of Records knowing the user id by:

Records userRecords[] = recordsByUserID[user_id];

About the event logging it's actually kind of easy because we have the indexed keyword, let me show you an example:

event Approved(uint indexed userId, uint indexed recordId);

With an event like this you are able to query all the events using the user id and the record id.

About the third question I suggest you to use the graph https://thegraph.com/en/. It basically creates your own GraphQL backend by indexing all the events for you in a very easy way. Then you are able to run your graphql queries and make something efficient.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文