Coder Social home page Coder Social logo

Comments (11)

sureshHARDIYA avatar sureshHARDIYA commented on September 26, 2024

@Kolbein I am not sure if I understand. You need to explain with an example.

from intromat-fhir.

Kolbein avatar Kolbein commented on September 26, 2024

As of now, when you create resources in the database they automatically get an ID. Is it possible to insert an ID in the GraphQL mutation when creating a resource in the database to give the resource that ID. In that case you can get the resource using that ID in the getPatientById query.

The reason we want this is that the Muzima resources we're mapping contain a 'uuid' field which should be mapped to 'id' on the FHIR side of things.

mutation PatientCreate {
PatientCreate(resource: {
resourceType: Patient
id: "7357"
}
) {
id
}
}

https://wiki.openmrs.org/display/projects/Patient+Resource

from intromat-fhir.

sureshHARDIYA avatar sureshHARDIYA commented on September 26, 2024

Hi, it should be possible. But, for that, you need to change the model and when you create the Patient, you have to check if the request contains ID. Then you have to create the patient. There is no built-in method based on what I can understand.

from intromat-fhir.

martinheitmann avatar martinheitmann commented on September 26, 2024

Please let me know if there's a better way to solve this. I tried to dig my way down to where I can check for an id in the request, and found that I can extract it in the resolver if it's available as an argument:

module.exports.createPatient = function createPatient(
	root,
	args,
	context = {},
	info,
) {
	return new Promise(async (resolve, reject) => {
		try {
			const { server: { model }, version, req, res } = context;
			//console.log(args);
			if(args.id) args.resource._id = args.id
			const patient = await model.patients.createData(args.resource);
			resolve(patient)
		} catch (e) {
			reject(e);
		}
	});
};

From there I declare _id as a part of the Schema(and also add it to permitFields) :

const Schema = new mongoose.Schema(
		Object.assign(domainResource, {
			_id: String,
			resourceType: {
				type: String,
				required: true,
				enum: ['Patient'],
			},
                        ...
		}),
	);

Running this query:

mutation PatientCreate {
  PatientCreate(
      id: "test-id-1234",
      resource: {
          resourceType: Patient
          name: [
            {
              use: "official",
              family: "Chalmers",
              given: [
                "Peter",
                "James"
              ]
            },
            {
              use: "usual",
              given: [
                "Jim"
              ]
            },
            {
              use: "maiden",
              family: "Windsor",
              given: [
                "Peter",
                "James"
              ],
              period: {
                end: "2002"
              }
            }
          ]
          gender: "male"
        contact: [
        {
    
          name: {
            text: "mr. F. de Hond"
          },
          telecom: [
            {
              system: "phone",
              value: "022-655 7654"
            },
            {
              system: "email",
              value: "[email protected]"
            },
            {
              system: "fax",
              value: "022-655 0998"
            }
          ],
          address: {
            line: [
              "West Wing, floor 5"
            ]
          }
        }
      ]
          telecom: [
          {
            use: "home"
          },
          {
            system: "phone",
            value: "(03) 5555 6473",
            use: "work",
            rank: "1"
          },
          {
            system: "phone",
            value: "(03) 3410 5613",
            use: "mobile",
            rank: "2"
          },
          {
            system: "phone",
            value: "(03) 5555 8834",
            use: "old",
            period: {
              end: "2014"
            }
          }
        ]
        active: true
          address: [
            {
              type: "postal"
              line: ["3300 Washtenaw Avenue, Suite 227"]
              city: "Ann Arbor"
              state: "MI"
              postalCode: "48104"
              country: "USA"
            }
          ],
        identifier: [
          {
            use: "usual",
            type: {
              coding: [
                {
                  system: "http://terminology.hl7.org/CodeSystem/v2-0203",
                  code: "MR"
                }
              ]
            },
            system: "urn:oid:1.2.36.146.595.217.0.1",
            value: "12345",
            period: {
              start: "2001-05-06"
            },
            assigner: {
              display: "Acme Healthcare"
            }
          }
        ],
    }
  ) {
    id
    resourceType
    name { family }
    address {
      id
      line
      type
    }
    identifier {
      use,
      assigner {
        display
      }
    }
    identifier {
      use,
      assigner {
        display
      }
    }
  }
}

The server returns:

{
    "data": {
        "PatientCreate": {
            "id": "test-id-1234",
            "resourceType": "Patient",
            "name": [
                {
                    "family": "Chalmers"
                },
                {
                    "family": null
                },
                {
                    "family": "Windsor"
                }
            ],
            "address": [
                {
                    "id": "5e838a0a24846263b0b2bcb4",
                    "line": [
                        "3300 Washtenaw Avenue, Suite 227"
                    ],
                    "type": "postal"
                }
            ],
            "identifier": [
                {
                    "use": "usual",
                    "assigner": {
                        "display": "Acme Healthcare"
                    }
                }
            ]
        }
    }
}

Is there a better way to do this? This will have to be implemented in every resource for it to work.

from intromat-fhir.

sureshHARDIYA avatar sureshHARDIYA commented on September 26, 2024

@Kolbein @martinheitmann In HL7 FHIR it is possible to create identifier yourself. So, passing id: "test-id-1234", like this okay.

I am not sure about your intention but storing ID like that is fine. However, you can not force MongoDB to create (_id). I recommend save it as a different field and map it later.

from intromat-fhir.

martinheitmann avatar martinheitmann commented on September 26, 2024

If I haven't misunderstood, querying a resource by other fields than its _id isn't supported, right? That was the main intention behind setting the id of the resource, so that we can easily query earch resource by their id.

For example, this isn't supported...

query Patient {
    Patient(id: "test-id-1234-5678"){
         id
    resourceType
    name { family }

I'm able to set the id field of the resource, but I can't query on it. Can we fix that somehow?

Edit: I see that it doesn't make sense to query by the id field in this case, but we still need to be able to query by some other id than just the objects MongoDB id.

from intromat-fhir.

sureshHARDIYA avatar sureshHARDIYA commented on September 26, 2024

Each resource can be queried by ID.

query Patient {
    Patient(_id: "5dcc0734d39e0045d82b6eae") {
        id
        name { family }
    }
}

There is nothing you have to do to support this. If you are querying like above and you are getting error, then there is something wrong in the code.

from intromat-fhir.

martinheitmann avatar martinheitmann commented on September 26, 2024

That works, yes. But if we can't override the internal MongoDB _id value, we'll have to be able to query by something else instead.

So say that we decide to query each resource by a uuid instead (which we can implement as an extension or whatever), how could we do that?

The reason why I'd like to do this is so that when we receive e.g. a patient from the mUzima app that already has an id, we can just assign that id somewhere in the resource and query it using that field.

from intromat-fhir.

sureshHARDIYA avatar sureshHARDIYA commented on September 26, 2024

What you can query with is defined in the query.

module.exports.PatientQuery = {

It is NOT defined that you have to query by _id. So, instead of _id, you should be able to query by any field. To debug I would:

  1. Use uuid field in query and log https://github.com/sureshHARDIYA/intromat-fhir/blob/master/src/resources/4_0_0/profiles/patient/resolver.js#L15 args and see if args correctly recognizes the uuid field or not.

  2. If uuid is recognized, then it goes to the model. https://github.com/sureshHARDIYA/intromat-fhir/blob/master/src/models/patient.js#L148 HERE. Try to log here and see params.

  3. Then check line https://github.com/sureshHARDIYA/intromat-fhir/blob/master/src/models/patient.js#L151. Here it is using findOne. The function findOne can take the object as input like:

Patient.findOne({ age: 21, location: "New York" }, function(err, result) {
  if (err) {
    res.send(err);
  } else {
    res.send(result);
  }
});

I don't have a working example in my computer so, I can not tell you exactly where is the issue. But based on the description, it should be possible to query using any field. If you pass uuid and GraphQL says, you can not query by uuid that means, the schema does not allow to query by uuid. In that case, you have allow to query by uuid in the schema.

If you have a hosted resource server with GRAPHIQL enabled, pass me the link and I can try to check what type of error it returns.

from intromat-fhir.

Kolbein avatar Kolbein commented on September 26, 2024

When trying to create a patient in the resource server providing a uuid with Martin's proposed id solution as commented above, I am successfully able to do so with the following query:
patient success

If I don't provide an id, this is the error I get:
patient error

from intromat-fhir.

sureshHARDIYA avatar sureshHARDIYA commented on September 26, 2024

Closing thread, due to inactive feedbacks.

from intromat-fhir.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.