Answered by:
Couldn't able to update Medication with Medication V1 checked for OfflineAccess

Question
-
I was trying to update Medication with Medication V1 checked for OfflineAccess. I could able to update Condition. Here is a stack trace:
Microsoft.Health.HealthServiceException was caught
Message="The thing type specified in the update, '5c5f1223-f63c-4464-870c-3e36ba471def', is an older version than the type of the existing instance. "
Source="Microsoft.Health"
ErrorCodeId=85
StackTrace:
at Microsoft.Health.EasyWebRequest.WaitForCompletion()
at Microsoft.Health.EasyWebRequest.Fetch(Uri url)
at Microsoft.Health.EasyWebRequest.Fetch(Uri url, IEasyWebResponseHandler customHandler)
at Microsoft.Health.HealthServiceRequest.ExecuteInternal()
at Microsoft.Health.Web.OfflineWebApplicationConnection.ExecuteRequestWithRetry(HealthServiceRequest request)
at Microsoft.Health.HealthServiceRequest.Execute()
at Microsoft.Health.HealthRecordAccessor.UpdateItems(IList`1 itemsToUpdate)
at Microsoft.Health.HealthRecordAccessor.UpdateItem(HealthRecordItem item)
at APS.AI.HealthVaultAdapter.GetHealthVaultItemTypes.UpdateMedications(HVMedication medicationName, Guid personId, Guid recordId) in C:\APS\APS\APS.AI.HealthVaultAdapter\GetHealthVaultItemTypes.cs:line 176
InnerException:
I was even struggling to retrieve Medication, thanks to Mahesh who helped me to resolve that problem. Please i need your help in solving this Problem.
Thanks in advance,
Addisu
Answers
-
The error message is telling you that you can't update a newer version of the Medication type through the V1 version. This is prohibited because it could result in data loss.
This article provides more information.
I looked at your code, and I think it has a couple of issues.
- If there are multiple medications with the same name in the user's record, you will update both of them.
- If another application read and updates the medication after the time you fetch it into the HVMedication class, you will overwrite their changes.
A better approach would be to save the Key property from the Medication that is fetched in HvMedication. Then, when you have an update to make, you should do the following:
- Fetch the existing Medication based on Key.Id.
- Verify that both Key.Id and Key.VersionStamp are the same in the fetched instance and your HvMedication. If not, it means somebody else updated the item and you should abandon your update.
- Update the item.
Hope that helps
Eric- Marked as answer by Lowell MeyerMicrosoft employee, Moderator Friday, December 18, 2009 5:43 AM
All replies
-
Hello,
From the error message it looks like you are trying to update a Medication V1 type object with a Medication type object. If you try to update an object of type Medication then this error will not happen.
I will check the scenario in my code and get back to you.
Thanks and Regards,
Aneesh D. -
-
Hello Addisu,
I have used the following code to update a Medication item and was not able to reproduce the issue,
Medication medication = (Medication)GetSingleValue<Medication>(new Guid("5c5f1223-f63c-4464-870c-3e36ba471def"));
medication.Strength = new GeneralMeasurement("DisplayStringV1toMed"); // Just to make sure the change is occuring, here make the needed changes
PersonInfo.SelectedRecord.UpdateItem(medication);
Can you try using this code to update the item, else paste the code snippet that you are getting this error on so that we can have a detailed look into it.
Thanks and Regards,
Aneesh D. -
Thanks Aneesh,
I can not use PersonInfo as am not using any of logged on pages. I am trying to update Medication using HealthVault SDK. Here is my code:
public
void UpdateMedications(HVMedication medicationName, Guid personId, Guid recordId)
{
try
{
HealthRecordAccessor offlineAccessor = new HealthRecordAccessor(HealthVaultConnectionManager.CreateConnection(_applicationId, personId), recordId);
IList<Medication> medicationCollection = GetHealthRecordItemCollection<Medication>(Medication.TypeId, offlineAccessor);
int i = 0;
foreach (Medication medication in medicationCollection)
{
if (medication.Name.ToString() == medicationName.Name.ToString())
{
ApproximateDateTime dateDiscontinued = null;
CodableValue route = new CodableValue(medicationName.Route.ToString());
DoseValue dose = new DoseValue(Double.Parse( medicationName.Dose.ToString())); ;
dateDiscontinued =
new ApproximateDateTime(DateTime.Parse(medication.DateDiscontinued.ToString()).ToString());
CodableValue indication = new CodableValue(medication.Indication.ToString());
medication.AmountPrescribed = medicationName.Prescribed;
medication.DoseValue = dose;
medication.StrengthValue =
Int32.Parse(medicationName.Strength.ToString());
medication.Frequency = medicationName.Frequency;
medication.Indication = medicationName.Indication;
medication.DateDiscontinued = dateDiscontinued;
medication.Route = route;
offlineAccessor.UpdateItem(medication);
break;
}
i++;
}
}
Please take a look at it and suggest me a better approach.
Regards,
Addisu -
The error message is telling you that you can't update a newer version of the Medication type through the V1 version. This is prohibited because it could result in data loss.
This article provides more information.
I looked at your code, and I think it has a couple of issues.
- If there are multiple medications with the same name in the user's record, you will update both of them.
- If another application read and updates the medication after the time you fetch it into the HVMedication class, you will overwrite their changes.
A better approach would be to save the Key property from the Medication that is fetched in HvMedication. Then, when you have an update to make, you should do the following:
- Fetch the existing Medication based on Key.Id.
- Verify that both Key.Id and Key.VersionStamp are the same in the fetched instance and your HvMedication. If not, it means somebody else updated the item and you should abandon your update.
- Update the item.
Hope that helps
Eric- Marked as answer by Lowell MeyerMicrosoft employee, Moderator Friday, December 18, 2009 5:43 AM
-
Thanks Eric, i will do that. I am getting an other error. I downloaded new HealthVault SDK and it looks okay to work on Medication not Medication V1. I checked Medication for OfflineAccess and Reauthorize my application. I ran my application and "There is no source code available for the current location" error is popped up. Can you take a look at this error please?
public static OfflineWebApplicationConnection CreateConnection(Guid applicationId,
Guid personId)
{
OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection(applicationId,
WebApplicationConfiguration.HealthServiceUrl, personId);//Error
offlineConn.Authenticate();
return offlineConn;
}
Thanks,
Addisu -
Exactly when are you getting this error? It looks like you will have to rebuild your application once and then try again. If you are still getting the same error then please post the whole stack trace of the same.
Thanks and Regards,
Aneesh D. -
Hi Aneesh, I Rebuild my solution but "There is no source code available for the current location." error is popping up. It doesn't have stack trace. It is a Visual Studio Error pop-up form. I was trying to paste PrtScrn but couldn't.
Please help me.
Thanks,
Addisu -
-
No path, no anything. Error message window is popping-up. That is making it hard for me to troubleshoot. I am thinking it is because the ApplicationId.
I have checked Medication and unchecked Medication V1 for OfflineAccess for
ApplicationId "1427bc2a-e17f-46a7-a8ce-8bbb86d9e33a"
Can you check please this ApplicationId whether it has the right access settings in HealthVault as my local settings?
Thanks,
Addisu -
Hello HealthVault guys,
Please help me in fixing the above problem. I got blocked. I couldn't able to create any connection to HealthVault. Here is what i got when i click Show Disassembly button of a popped-up error window:
--- c:\src\hsmain\private\prod\src\sdk\web\WebApplicationConfiguration.cs ------
00000000 push ebp
00000001 mov ebp,esp
00000003 sub esp,10h
00000006 cmp dword ptr ds:[04BE07F4h],0
0000000d je 00000014
0000000f call 68AF7DA9
00000014 xor edx,edx
00000016 mov dword ptr [ebp-0Ch],edx
00000019 mov dword ptr [ebp-4],0
00000020 nop
00000021 mov ecx,dword ptr ds:[03740258h]
00000027 xor edx,edx
00000029 call 67623EE0
0000002e mov dword ptr [ebp-8],eax
00000031 cmp dword ptr [ebp-8],0
00000035 sete al
00000038 movzx eax,al
0000003b mov dword ptr [ebp-4],eax
0000003e cmp dword ptr [ebp-4],0
00000042 jne 0000005D
00000044 nop
00000045 call dword ptr ds:[04BE8BFCh]
0000004b mov dword ptr [ebp-10h],eax
0000004e mov eax,dword ptr [ebp-10h]
00000051 lea edx,ds:[03740258h]
00000057 call 688A0290
0000005c nop
0000005d mov eax,dword ptr ds:[03740258h]
00000062 mov dword ptr [ebp-0Ch],eax
00000065 nop
00000066 jmp 00000068
00000068 mov eax,dword ptr [ebp-0Ch]
0000006b mov esp,ebp
0000006d pop ebp
0000006e ret
I couldn't find --- c:\src\hsmain\private\prod\src\sdk\web\... path in my system.
I have checked event logs and nothing related to this error is there. Please i need your help.
Thanks,
Addisu -
Hello Addisu,
The source for HealthVault SDK is located in the SDK installation folder. For example in my case it is C:\Program Files\Microsoft HealthVault\SDK\Source. There the source file is in a zip format. Once you unzip it you can look inside the Web folder for WebApplicationConfiguration.cs.
Hope this helps.
Thanks and Regards,
Aneesh D. -
He guys,
Mahesh, Aneesh or whoever can do me a favor, Please check Medication and uncheck Medication V1 for OfflineAcess and OnlineAccess for ApplicationId "1427bc2a-e17f-46a7-a8ce-8bbb86d9e33a"
Please help me. My application is returining
Unable to cast object of type 'Microsoft.Health.ItemTypes.Old.MedicationV1'
to type 'Microsoft.Health.ItemTypes.Medication' error when i tried to update Medication. I have checked Medication and unchecked Medication V1 in my Application Configuration Center but my changes are not reflected in HealthVault system.
Thank you in advance,
Addisu -