Question
saranraj Rasu · Oct 15, 2019

Graphql API using Fhir

Hi,

    I am new  to fhir framework, I have searched articles to write graphql API using FHIR i did not get any proper tutorial for this. I need to find better tutorial or articles for this.  I have written API using graphql, typescript with mongodb. Can some one tell why we need resourcetype, identifier in fhir.

    Also i have tried github code based on fhir using javascript. The source code i got from "https://github.com/Asymmetrik/graphql-fhir" here i tried to save patient informations

     mutation{
  PatientCreate(id: "PatientMani", resource: {
    resourceType: Patient
    name: [{
      given: ["mani"]
      prefix: ["Mr"]
      period: {
        start: "2019-10-14T13:33:43.145Z"
        end: "2019-10-30T13:33:43.145Z"
      }
    }]
    gender: "Male"
    birthDate : "1992-01-06"
    deceasedBoolean: false
    identifier: {
     
      assigner: "Saranraj Rasu"
    }
    deceasedDateTime: "1992-01-06T13:33:43.145Z"
    address: {
      use: "PDY",
      city: "shanmugapuram"
      district: "Pondicherry"
      state: "Pondicherry"
      postalCode: "605009"
      country: "India"
      period: {
        start: "1992-01-06T13:33:43.145Z"
        end: "2019-10-15T13:33:43.145Z"
      }
    }
    contact: {
      name: {
        family: "Manifamily"
        given: ["Vinoth"]
        prefix: ["Mr"]
      }
      period: {
        start: "1992-01-06T13:33:43.145Z"
        end: "2019-10-15T13:33:43.145Z"
      }
      gender: "Male"
      address: {
      use: "PDY",
      city: "shanmugapuram"
      district: "Pondicherry"
      state: "Pondicherry"
      postalCode: "605009"
      country: "India"
      period: {
        start: "1992-01-06T13:33:43.145Z"
        end: "2019-10-15T13:33:43.145Z"
      }
    }
    }
  }) {
    id
    name{
      given
    }
    gender
  }
  }

      This exact input i need to give mutation but i got error i need help to fix this issue.

{
  "errors": [
    {
      "path": [
        "PatientCreate"
      ],
      "message": "Identifier 'version' has already been declared",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "extensions": {
        "resource": {
          "resourceType": "OperationOutcome",
          "issue": [
            {
              "severity": "error",
              "code": "exception",
              "diagnostics": "Identifier 'version' has already been declared"
            }
          ]
        }
      }
    }
  ],
  "data": {
    "PatientCreate": null
  }
}
 

00
1 0 2 394
Log in or sign up to continue

Yes i wrote MongoDB operation in resolver. The code is following below

module.exports.createPatient = function createPatient(

    root,

    args,

    context = {},

    info,

) {

    let { server, version, req, res } = context;

    console.log('inside the create patient', context.req.body);

    console.log('context.server.db', context.server.db);

    let db = context.server.db;

    let version = context.version;

    let logger = context.server.logger;

    return new Promise((resolve, reject) => {

        db.patients.create(context.req.body, (err, patient) => {

            console.log('error:', err);

            console.log('patient:', patient);

            if (err) {

                logger.error(err);

                let error = errorUtils.internal(version, err.message);

                reject(errorUtils.formatErrorForGraphQL(error));

            } else {

                resolve(patient);

            }

        })

    });

};