Can we update any fhir resource on the basis of patient id? - hl7-fhir

I am trying to update Encounter resource on the basis of patient id but it is only creating one new record of Encounter rather than updating the existing one. But if i try to update Encounter on the basis of identifier i.e. unique value representing Encounter resource then it is able to update it.
Why is that? Can anyone explain?

One patient will potentially have many (even hundreds) of encounters. Updates are always driven by the record of the resource itself - every resource (Patient, Encounter, Observation, CarePlan, etc.) has an 'id' element that represents the identifier of that resource on that particular server - sort of like a primary key. Updates are performed by making a RESTful PUT of the new record to a URL that includes that same identifier.
I.e. an update of an Encounter MUST always be performed with a URL of the form:
PUT [somebaseurl]/Encounter/[serverEncounterId]
The patient associated with the encounter will be referenced from within the Encounter object in the body of the RESTful call, but does not appear in the URL.

As you have discovered, some FHIR servers will allow a 'conditional update':
PUT [somebaseurl]/Encounter?search_key=search_value&...
You will need to add search parameters that filter all Encounters and result in a unique one, which will then be updated. Since, as Lloyd also indicated, a Patient can have multiple associated Encounters, the Patient id is not a suitable parameter for the conditional update. Your Encounter's identifier was unique enough, so that update succeeded.

Related

How to use Get Record to lookup a related record on another object when I don't have the schema Entity Name - Just the LogicalName

All,
I am building a Power Flow. I am returning an object that has a relationship to another entity.
I want to get some values from the related entity.
I am attemping to use the "Get Record" connector. The returning object returns just the logicalEntityName (in this case "opportunities") but Get Record wants an Entity Name that is the Schema Name ("Working Opportunities").
Big Question: What's the secret to use CDS to get information from a related record in another object?
Little Question: How do I do get the Schema Name?
The logical name will be the same as schema name except some casing difference, ie schema name will have camel casing (first letter of first/second word with capitals, you can notice it clearly in custom entity which will have publisher prefix like new_entityname) and logical name will have pascal casing (all lower case).
You can find the details in XrmToolBox metadata browser or in Solution.
In the below snip, (Logical) Name = Opportunity and Schema Name = Opportunity, also Display Name can be anything and can be changed anytime.
Regarding the related entities, you should use List Records: GetItems_V2 and you can use filter by passing parent record to get related child records. Read more
Could you please share flow screenshot and response to help you with your requirement?
As suggested by Arun you could use List Record and filter query to pass parent record id which will be available from dynamic content.
see below link.
https://crmkeeper.com/2019/08/31/cds-list-records-filter-query-using-flow/
Please mark my answer verified if i were helpful

Why MedicationDispense doesn't contain attribute of prescription number?

The MedicationDispense resource of FHIR defines the attributes related to prescription, like request, dosage, quantity etc. The prescription number, a.k.a. the RxNumber is a pretty common attribute of dispensed record in pharmacy system. I'm wondering why this is not defined in MedicationDispense schema?
There are two identifiers in the schema, the id and identifier. As mentioned in another post, the identifier should be something across systems, like SSN of a patient. Meanwhile the id is ambiguous since it could be internal database identifier or anything that could uniquely identify this dispense record.
What's the difference between id and identifier for a FHIR resource?
The MedicationDispense includes a reference to the 'authorizingPrescription' MedicationRequest. That's where all information about the prescription (identifier, prescriber, prescription date, prescribed drug, etc.) is captured. In FHIR we try hard to not combine information present in other resources into a referencing resource because doing so makes it hard to keep things in sync and doesn't work well for RESTful exchange. As a result, it's common to use the _include parameter when executing search to grab related resources (e.g. MedicationRequest, Organization, Medication, Practitioner, etc.) when searching against a base resource.
The 'id' is essentially the primary key for a resource as stored on a particular server. If you copy the resource onto a different server, that server will assign its own id/primary key. The 'identifier' on the other hand is a business identifier. For a dispense, this would typically be the "transaction" identifier that goes on the bottle/jar/box that uniquely identifies that particular dispense event. If the dispense information gets stored on multiple systems (e.g. it gets forwarded to the prescribing system, to a personal health record, to a centralized medication registry, etc.) it would have the same 'identifier' but would (usually) have a distinct 'id'. It's certainly possible for two closely linked systems to share the same 'id' for the equivalent records, but it requires careful coordination to avoid conflicts.
Note that the MedicationDispense.identifier is not the same as the MedicationRequest.identifier. The first is a unique identifier for a specific dispense event. The latter is a unique identifier for the overall order. There are often multiple MedicationDispense events (each with a distinct identifier) for a single MedicationRequest.

MVC SiteMapProvider allow nodes with same URL

Is there a setting to allow multiple nodes with the same URL?
We've setup a small CMS type system where web content admins can add new pages with content and widgets to the website.
They sometimes make the mistake of adding the same name to multiple pages under the same parent causing 2 nodes to have the same URL. I would rather not showing and ignoring the duplicate than throwing an exception.
The URL (when supplied) is used as a key of a dictionary. By definition, the key of a dictionary must be unique. Even if the duplicate URL check were removed, the dictionary would throw a more cryptic duplicate key exception.
I would suggest sanitizing the data before reading it with IDynamicNodeProvider or ISiteMapNodeProvider.
Options
Add a check to the data entry form to ensure the URL is unique before allowing it to be saved.
Put a unique constraint on the URL field in your database to throw an exception upon data entry instead of when it is read.
Put a distinct filter in your query so only one of the duplicate URL records is considered when adding them to the SiteMap.
Consider using controller, action, and id (from the primary key) when using data-driven URLs. The only thing that really needs to be data-driven are the Routes, and the URLs will be resolved correctly within MvcSiteMapProvider.

Determine new record in PreWriteRecord event handler and check value of joined field

There is custom field "Lock Flag" in Account BC, namely in S_ORG_EXT_X table. This field is made available in Opportunity BC using join to above table. The join specification is as follows: Opportunity.Account Id = Account.Id. Account Id is always populated when creating new opportunity. The requirement is that for newly created records in Opportunity BC if "Lock Flag" is equal to 'Y', then we should not allow to create the record and we should show custom error message.
My initial proposal was to use a Runtime Event that is calling Data Validation Manager business service where validation rule is evaluated and error message shown. Assuming that we have to decide whether to write record or not, the logic should be placed in PreWriteRecord event handler as long as WriteRecord have row already commited to database.
The main problem was how to determine if it is new record or updated one. We have WriteRecordNew and WriteRecordUpdated runtime events but they are fired after record is actually written so it doesn't prevent user from saving record. My next approach was to use eScript: write custom code in BusComp_PreWriteRecord server script and call BC's method IsNewRecordPending to determine if it is new record, then check the flag and show error message if needed.
But unfortunately I am faced with another problem. That joined field "Lock Flag" is not populated for newly created opportunity records. Remember we are talking about BC Opportunity and field is placed in S_ORG_EXT_X table. When we create new opportunity we pick account that it belongs to. So it reproduceable: OpportunityBC.GetFieldValue("Lock Flag") returns null for newly created record and returns correct value for the records that was saved previously. For newly created opportunities we have to re-query BC to see "Lock Flag" populated. I have found several documents including Oracle's recomendation to use PreDefaultValue property if we want to display joined field value immediately after record creation. The most suitable expression that I've found was Parent: BCName.FieldName but it is not the case, because active BO is Opportunity and Opportunity BC is the primary one.
Thanks for your patience if you read up to here and finally come my questions:
Is there any way to handle PreWrite event and determine if it is new record or not, without using eScript and BC.IsNewRecordPending method?
How to get value of joined field for newly created record especially in PreWriteRecord event handler?
It is Siebel 8.1
UPDATE: I have found an answer for the first part of my question. Now it seems so simple to me that I am wondering how I haven't done it initially. Here is the solution.
Create Runtime Event triggered on PreWriteRecord. Specify call to Data Validation Manager business service.
In DVM create a ruleset and a rule where condition is
NOT(BCHasRows("Opportunity", "Opportunity", "[Id]='"+[Id]+"'", "AllView"))
That's it. We are searching for record wth the same Row Id. If it is new record there should't be anything in database yet (remember that we are in PreWriteRecord handler) and function returns FALSE. If we are updating some row then we get TRUE. Reversing result with NOT we make DVM raise an error for new records.
As for second part of my question credits goes to #RanjithR who proposed to use PickMap to populate joined field (see below). I have checked that method and it works fine at least when you have appropriate PickMap.
We Siebel developers have used scripting to correctly determine if record is new. One non scripting way you could try is to use RuntimeEvents to set a profileattribute during the BusComp NewRecord event, then check that in the PreWrite event to see if the record is new. However, there is always a chance that user might undo a record, those scenarios are tricky.
Another option, try invokine the BC Method:IsNewRecordPending from RunTime event. I havent tried this.
For the second part of the query, I think you could easily solve your problem using a PickMap.
On Opportunity BC, when your pick Account, just add one more pickmap to pick the Locked flag from Account and set it to the corresponding field on Opportunity BC. When the user picks the Account, he will also pick the lock flag, and your script will work in PreWriteRecord.
May I suggest another solution, again, I haven't tried it.
When new records are created, the field ModificationNumber will be set to 0. Every time you modify it, the ModificationNumber will increment by 1.
Set a DataValidationManager ruleset, trigger it from PreSetFieldValue event of Account field on Opportunity BC. Check for the LockFlag = Y AND (ModificationNumber IS NULL OR ModificationNumber = 0)) and throw error. DVM should throw error when new records are created.
Again, best practices say don't use the ModNumbers. You could set a ProfileAttribute to signal NewRecord, then use that attribute in the DVM. But please remember to clear the value of ProfileAttribute in WriteRecord and UndoRecord.
Let us know how it went !

LINQ to Entities - How best to obtain the IDENTITY value after calling SaveChanges()

There have been numerous questions posed on this site relating to the retrieval of the IDENTITY after an insert is performed. The way we have been getting the identity is to make the call below, immediately after calling SaveChanges();
context.MyClass.OrderByDescending(c => c.Id).FirstOrDefault();
This seems to work consistently may be completely adequate; however, it has the appearence of opening up a potential for error, should another record be added in between the calls. So the first question is, given that EF performs withing a transacional context, is this method sound?
Secondly, the answer provided to the following question suggests there may be a better way.
Linq to SQL - How to find the the value of the IDENTITY column after InsertOnSubmit()
In that answer, after calling SubmitChanges(), the following call (where "tst" represents the user's class) retrieves the value.
Response.Write("id:" + tst.id.ToString)
This appears to work exactly the same way in LINQ to Entities, where after the call to save changes the instance of the class now includes the id.
context.MyClass.Add(myClass);
context.SaveChanges();
int myNewIdentity = myClass.Id;
Since we are asking for the the actual ID of the class instance (actual record) it would appear to be failsafe. And, it seems logical that the designers of EF should make such basic functionality available. Can anyone confirm that this is proper way to get the identity or at least a best practice?
Yes, LINQ-to-Entities (and LINQ-to-SQL for that matter) will set the generated identity column back in the entity for you after SaveChanges is called. It will also do so for any foreign keys that couldn't be set ahead of time (for instance, a new parent row + a new child row are saved together, and after SaveChanges you'll have the right value in the child row's FK value).
Your particular concern is documented in the 'Working with Entity Keys' page:
http://msdn.microsoft.com/en-us/library/dd283139.aspx
The particular section is 'Entity Keys and Added Objects' and the particular steps are:
4 - If the INSERT operation succeeds, server-generated values are written back to the ObjectStateEntry.
5 - The ObjectStateEntry updates the object with the server-generated value.

Resources