HL7 Spy - Clearing field OBX-5.5.1 - hl7

Hullo All,
I am currently working on a custom script in Inner Harbor's HL7 Spy. Most everything is going well, but I'm having difficulty scrubbing out embedded PDFs. Logic: if OBX-5.2 == "PDF", then set OBX-5.5.1 = "PDF". My roughed out code is below:
public HL7Message getStrippedMessage()
{
HL7Message message = GetParsedMessage();
foreach(var obx in message.OBXs)
{
if(obx.ObservationValue_05.ElementAt(2).TX_01.Value == "PDF")
{
obx.ObservationValue_05.ElementAt(5).TX_01.Value = "PDF";
}
}
return message;
}
What does it currently do, you ask? It returns the unaltered HL7 message. I'm sure neither the 'if' nor the assignment therein are formatted correctly even though they compile without issue. Could anyone advise on how I would check and alter, respectively, these fields?
Many Thanks

Got a chance to talk with a dev here and found that this one is actually really quite simple. OBX-5, being a coded entry, is handled quite differently from the other fields. This solution is probs pretty obvious to others with more experience, but I locked myself into some tunnel vision.
public HL7Message getStrippedMessage()
{
HL7Message message = GetParsedMessage();
foreach (var obx in message.OBXs) {
if (obx[5, 1, 2] == "PDF")
obx[5, 1, 5] = "PDF";
}
return message;
}

Related

Apparent race condition/concurrency issue

I have a web application written using ASP.NET MVC (C#), Entity Framework and an Oracle database. In one of the controllers I have code similar to the following (stripped down to show only what I consider necesary for this question):
using (var context = CreateContext())
{
//Other code ...
var workItem = //Get work item from context
var nextReviewers =
await context.WorkItemReviewers
.Where(r => r.WorkItemId == workItem.Id)
.Where(r => r.Position > workItem.NextReviewerPosition)
.OrderBy(r => r.Position)
.ToArrayAsync();
if (nextReviewers.Count() > 0)
{
workItem.Status = "A";
workItem.StatusDetails = "A";
workItem.NextReviewerPosition = nextReviewers.First().Position;
//Other Code
}
else
{
workItem.Status = "B";
workItem.StatusDetails = "B";
workItem.NextReviewerPosition = null;
}
//Other Code
await context.SaveChangesAsync();
}
Based on the code above, I never expect the values of Status or StatusDetails to ever be different but I have a situation in production where two requests came in about 3-4 milliseconds apart and now, inexplicably, I have the following values in the database: Status = "B"; StatusDetails = "A".
Am I missing something? Is there a logical explanation for this based on how EntityFramework (against Oracle 11g) might behave in ASP.NET?
Based on the code above, given that the workItem entity updated was loaded within the scope of the DB context and that the 2 values are strings, I'd have to say with 99.5% certainty that this code is not responsible for the behaviour you are seeing. (though I will definitely be watching this item to see if that is proven wrong:) I would be taking a close look at everywhere that either Status or StatusDetails is being used in relation to the calls made to the service. I suspect some other code is unexpectedly changing one or the other and calling SaveChanges.
A small optimization I can suggest:
var nextReviewer = context.WorkItemReviewers
.Where(r => r.WorkItemId == workItem.Id
&& r.Position > workItem.NextReviewerPosition)
.OrderBy(r => r.Position)
.Select(r => new { r.Position }) // Add any other details you may need from reviewer and other related entities.
.FirstOrDefault();
if (nextReviewer != null)
{
workItem.Status = "A";
workItem.StatusDetails = "A";
workItem.NextReviewerPosition = nextReviewer.Position;
//Other Code
}
else
{
workItem.Status = "B";
workItem.StatusDetails = "B";
workItem.NextReviewerPosition = null;
}
By using .Select() you can optimize the query to just return back the columns from the tables you need which will make calls to the DB faster. Unless the query is expected to be relatively heavy in terms of time (> ~500ms for instance) I'd also avoid the async operation. It's purpose is to make the server more responsive when dealing with bigger operations. Using it on everything will make all operations a wee bit slower than necessary. Once you've optimized the data coming back, then async can be considered if it still requires a bit of time to chew through.

Google reCaptch customization in ASP.NET MVC VIew

I m using google reCaptch for captca validation and so i want to customize according to my application design.
I had user html helper for google reCaptch.
So how can i customize its height,width and other appearance in view using razor html helper ?
Really stuck in this customization issue.
I realise this post is a little old, but I've recently done something similar - so thought I could help (if you still need it)
I know you want to use the Html helpers, but having looked into this extensively - none really offer this. The reCaptcha Developers Guide has a guide as to how you can implement your own style, and validation - a good idea would be to abstract the validation to behind an interface to allow proper testing.
You can more or less copy the HTML example from the reCaptcha documentation, but the validation code would look (in a very basic form) something like this:
bool success;
const string url = "http://www.google.com/recaptcha/api/verify";
var ip = Request.UserHostAddress;
var d = new NameValueCollection
{
{ "privatekey", "6Ld-lN0SAAAAAB1c2Mzgu2pNjkLxn9W07FsAMLgc" },
{ "remoteip", ip },
{ "challenge", Request.Form["recaptcha_challenge_field"] },
{ "response", Request.Form["recaptcha_response_field"] }
};
using (var client = new System.Net.WebClient())
{
var response = client.UploadValues(url, d);
var result = Encoding.ASCII.GetString(response);
success = result.StartsWith("true");
}
if (!success)
ModelState.AddModelError("recaptcha_response_field", "Please enter the correct words");
else
Response.Write("CAPTCHA check is valid - we think you are a human");

How can I return my MVC4 partial view as json and is it a good thing to do?

I am trying to clean up my code. I have a grid screen that gets refreshed with the following:
public ActionResult Details(string pk)
{
IEnumerable<ContentDetail> model = null;
try
{
model = _content.Details(pk);
if (model.Count() > 0)
{
return PartialView(getView(pk) + "Details", model);
}
}
catch (Exception e)
{
log(e);
}
return Content("No records found");
}
All the rest of my code uses json and I would like to return something like this:
public JsonResult JsonDetails(string pk)
But what should I do about the PartialView? I can't find anything about how to do this. Also is there any advantage / disadvantage to doing this? I was thinking if the code fails then I would return something like the following which the new ASP MVC4 code uses:
return Json(new { errors = GetErrorsFromModelState() });
Can someone help me with this? I'm looking to find any suggestions in particular for MVC4.
I've previously used the approach outlined in this answer, which was successful for me.
I can't think of any disadvantages of returning HTML within JSON, although the payload would likely be much larger than if you were returning data alone.
An alternative would be to return the model as JSON, and use a templating library, e.g. Handlebars.js, to generate the markup on the client. This is a common approach in single page applications.
Your idea around returning errors is good. GetErrorsFromModelState is only used where there are validation errors in the model state - in the example above, you're not performing any validation that would require you to use this method. So you'd probably want to output some friendly message within your catch-block, e.g.
try
{
...
}
catch (Exception e)
{
log(e);
return Json(new { errors = "An error occurred, please try again later" });
}
I've used the code from this answer before and it worked out great for me, I haven't tried returning specific errors, but it is possible to access controller.ModelState to check.

Monotouch - EASession output stream gives null error

Looking for some help over here.
When i run this code (below), it crashes when i process it for the second time.
it crashes with an object reference not set.. on the session.outputstream
var session= new EASession(accessory, "net.gebe");
session.OutputStream.Open();
the second time session.outputstream is null. Even when disposing session.
Richard
public void PrintIt()
{
var _accessoryList = EAAccessoryManager.SharedAccessoryManager.ConnectedAccessories;
accessory = null;
foreach(var obj in _accessoryList)
{
if(obj.ProtocolStrings.Contains("net.gebe"))
{
accessory = obj;
//break;
}
}
if(accessory == null)
{
//tmg.InfoAlert ("No Printer");
return;
}
var session= new EASession(accessory, "net.gebe");
session.OutputStream.Open();
string str2 = "HELLO THERE PRINTER 1 2 3 4 5";
byte[] printdata2;
ASCIIEncoding encoding2 = new ASCIIEncoding();
printdata2 = encoding2.GetBytes(str2);
uint nlen2 = Convert.ToUInt32 (str2.Length+1);
session.OutputStream.Write(printdata2,nlen2 );
session.OutputStream.Close ();
session.Dispose ();
}
I got mine working now. What I did:
Save the session as a variable in the class
Only create the session if session is null
You may not want to call session.OutputStream.Close() after every print. At least it's something to keep in mind while debugging for your situation.
This will allow for multiple print jobs on the same page without blowing up. session.OutputStream was not null in this case.
I also found that the ViewDidLoad/Unload events weren't great for detecting when the device becomes available/unavailable via the EAAccessoryDidConnectNotification and EAAccessory DidDisconnectNotification observers. Instead I used ViewDidAppear/ViewDidDisappear. In those methods, I tear down the session, and when I come back in to print a new job, the session gets created and OutputStream is assigned.
Lastly, I wasn't getting events fired for my device via session.OutputStream.OnEvent. Not sure if it's my device, a MonoTouch bug, or just a generic bug of mine yet.
UPDATE: Check out this nicely wrapped implementation of AccessoryAdapter
You need to list the external accessories you're going to use in your Info.plist.
There is some documentation on this on apple's site:
http://developer.apple.com/library/ios/#featuredarticles/ExternalAccessoryPT/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009502
Here is a screenshot of how to set this value in Info.plist:
http://screencast.com/t/AYmOWjf8wkL
(This is from here: https://bugzilla.xamarin.com/show_bug.cgi?id=1635#c1)

MVC2 Multilevel navigation

One question I have yet to find an answer on is this. How do I keep track of active Sitemap nodes on multiple levels?
For example :
node 1
node 2 "active"
Child node 1
Child node 2 "active"
node 3
How do I keep track of a childnode being active as well as the parent it belongs to being marked as active.
I know there is something called IsDescendant but I always get exceptions when using it due to null values.
Is there some screencast/tutorial on doing more advanced custom navigation in mvc.net(or asp.net for that matter). Most seem to deal with simple one level navigation.
I would prefer examples in C# if possible, thank you.
Ok ,,, I've suffered from the same issue and I came up with a work around, check my answer in this question :
Hierarchical menu in view based on parent child class
I've been meaning to come up with a more generic elegant way of doing it since I've faced the problem but I've been busy ever since. I'm hoping I'll find some time in the next weeks to come up with something ,,,
Note : for simplicity in my solution in the above question in the methods DisplayMenu and ConvertToItem particularity, I've removed the parts where it should check for the currentMenuID and the currentMenuItemID fields and add the current css class to the li element (or active class in your case).
Since this is all what's your question is about, I've provided the full methods below.
public static string DisplayMenu(this HtmlHelper helper, NavigationModel navigationMenu)
{
string classOfCurrentMenu;
String result = "<ul id='main-nav'>\n";
foreach(Menu menu in navigationMenu.Menus)
{
classOfCurrentMenu = "";
if (menu.ID == navigationMenu.currentMenuID)
{
classOfCurrentMenu = "current";
}
result += "<li>\n";
result += string.Format("<a href='#' class='{0}'> {1} </a>\n", helper.AttributeEncode(classOfCurrentMenu),helper.AttributeEncode(menu.Name));
result += "<ul>\n";
foreach(MenuItem item in menu.MenuItems)
{
result += NavigationHelper.ConvertToItem(helper, item, navigationMenu.currentMenuID, navigationMenu.currentMenuItemID);
}
result += "</ul>\n";
result += "</li>\n";
}
result += "</ul>\n";
return result;
}
private static string ConvertToItem(this HtmlHelper helper,MenuItem item, int currentMenuID, int currentMenuItemID)
{
if (item.Show)
{
string classOfCurrentItem = "";
if (item.ID == currentMenuItemID && item.MenuID == currentMenuID)
classOfCurrentItem = "current";
return string.Format("<li><a href='{0}' class='{1}'>{2}</a></li>\n", helper.AttributeEncode(item.Link), helper.AttributeEncode(classOfCurrentItem), helper.AttributeEncode(item.Label));
}
else { return ""; }
}
I don't consider this as a perfect solution to the problem, I hate writing HTML in C# code, I will try my best to come up with a more generic (multi level) cleaner solution for the problem, and of course make use of the TagBuilder class in the framework.

Resources