c# how to add multiple RDT segments on NHapi using HL7 version 2.5.1 - hl7

I'm working with nHapi v2.5.0.6 and I'm trying to create multiple RDT segments for HL7 v2.5.1.
The segments should look like this:
RDT|555444222111|Adam||19600614|M|
RDT|555444222112|Adam2||19600615|F|
RDT|555444222113|Adam3||19600616|M|
But the most I can do, is this:
RDT|555444222111
RDT|555444222112
RDT|555444222113
I don't know how to add fields after the first one!
This is my code:
private void addSegmentRDT2(DataTable informationTable)
{
//RDT|555444222111|||19600614|M|
var tbr_r08 = new TBR_R08();
int rowNumber = 0;
foreach (DataRow row in informationTable.Rows)
{
var RTD = tbr_r08.AddRDT();
int columnNumber = 0;
foreach (DataColumn column in informationTable.Columns)
{
NHapi.Model.V23.Datatype.ST a = new NHapi.Model.V23.Datatype.ST(tbr_r08.Message);
a.Value = row[column]?.ToString() ?? "";
RTD.ColumnValue.Data = a;
}
}
}
Any help will be appreciated.
Thanks

This is how I resolve the problem, is not the most elegant solution but it works :).
private void addSegmentRDT(DataTable informationTable)
{
var rowNumber = 0;
var tbr_r08 = new TBR_R08();
foreach (DataRow row in informationTable.Rows)
{
var RTD = tbr_r08.AddRDT();
var values = new Varies(tbr_r08.Message);
var columnNumber = 0;
foreach (DataColumn column in informationTable.Columns)
{
var rowColumnValue = row[columnNumber]?.ToString() ?? "";
var HL7String = new NHapi.Model.V23.Datatype.ST(tbr_r08.Message);
HL7String.Value = rowColumnValue;
values.ExtraComponents.getComponent(columnNumber).Data = HL7String;
++columnNumber;
}
RTD.ColumnValue.Data = values;
++rowNumber;
}
}

Related

keeping track of a series of simple multiple choice web form answers

This is the code I'm trying to use, which seems logical. But doesn't seem to be working.
MyAsFileName.prototype.getTotalScore = function() {
var totalScore = 0;
for (var i = 0; i < allQuestions.length; i++) {
totalScore += allQuestions[i].getCalculatedScore();
if (currentModule.allQuestions[i].parent.questionCorrect == true) {
knowledgePoints++;
} else {
knowledgePoints--;
}
}
debugLog("Total score: " + totalScore);
debugLog(knowledgePoints);
return totalScore;
}
I have allQuestions defined as below:
var allQuestions = Array();
I have knowledgePoints defined as:
this.knowledgePoints = 10;
I have questionCorrect defined as:
this.questionCorrect = false;
Second fresh attempt made with new class as answer below suggested (commented out for now until I figure out how to get working):
// package
// {
/*public class Quiz {
//public
var knowledgePoints: int = 10;
//public
var allQuestions: Array = new Array;
//public
var questionCorrect: Boolean = false;
//public
function getTotalScore(): int {
var totalScore: int = 0;
for (var i = 0; i < allQuestions.length; i++) {
totalScore += allQuestions[i].getCalculatedScore();
if (currentModule.allQuestions[i].parent.questionCorrect) {
knowledgePoints++;
} else {
knowledgePoints--;
}
}
debugLog("Total score: " + totalScore);
debugLog(knowledgePoints);
return totalScore;
}
}*/
//}
This code above outputs two errors in flash console:
Error 1. Attribute used outside of class.
Error 2. 'Int' could not be loaded.
It's a weird (and actually non-AS3 way) way to do this. Instead of creating a unnamed closure which refers weird variables from who-knows where, you should make it a normal AS3 class, something like that (in a file named Quiz.as):
package
{
public class Quiz
{
public var knowledgePoints:int = 10;
public var allQuestions:Array = new Array;
public var questionCorrect:Boolean = false;
public function getTotalScore():int
{
var totalScore:int = 0;
// Your code does not explain how you will that Array.
// It is initially an empty Array of length 0.
for (var i = 0; i < allQuestions.length; i++)
{
totalScore += allQuestions[i].getCalculatedScore();
if (currentModule.allQuestions[i].parent.questionCorrect)
{
knowledgePoints++;
}
else
{
knowledgePoints--;
}
}
// Not sure what it is.
debugLog("Total score: " + totalScore);
debugLog(knowledgePoints);
return totalScore;
}
}
}

Will breaking out the context calls cause multiple trips to the database?

I'm refactoring some previously written MVC and Entity Framework code. The way the initial code was written they called a DAL.GetGroupDetail(int groupId) method. In that method it created a ViewModel and populated several properties. Some of those properties are Lists for things like CostCenters, Cities, Groups. I want to break those calls out into their own methods so that they can be re-used in other controllers.
My question is that doing that I'm creating new Contexts using the Using statement. My understanding is that would create multiple connections to the database and thus would slow down the site if multiple users were using it at the same time?
Example, currently this is the basic code:
public ClockGroupViewModel GetClockGroupDetail(int groupId)
{
GroupViewModel cgdv = new GroupViewModel();
using (var ctx = new VTContext())
{
bio_group group = ctx.bio_group.Where(x => x.group_id == groupId).FirstOrDefault();
cgdv.GroupId = group.group_id;
cgdv.GroupName = group.group_name;
cgdv.Cities = ctx.bio_city.ToList();
var clocks = from c in ctx.bio_clock.Where(x => x.group_id == groupId)
select new ClockViewModel
{
ClockID = c.rdr_id.ToString(),
ClockDescription = c.clock_desc,
};
cgdv.ClockList = clocks.ToList();
cgdv.CostCtrList = (from g in ctx.bio_clock_group
from cgc in ctx.bio_clock_group_costctr
where cgc.group_id == g.group_id && g.group_id == groupId
select cgc.cost_ctr).ToList();
}
This how I'm thinking of changing it:
public ClockGroupViewModel GetClockGroupDetail(int groupId)
{
GroupViewModel cgdv = new GroupViewModel();
using (var ctx = new VTContext())
{
bio_group group = ctx.bio_group.Where(x => x.group_id == groupId).FirstOrDefault();
cgdv.GroupId = group.group_id;
cgdv.GroupName = group.group_name;
cgdv.Cities = GetCityList();
cgdv.ClockList = GetClockGroupClockList(group.group_id);
cgdv.CostCtrList = GetGroupCostCenter(group.group_id);
}
}
public List<bio_clock_city> GetCityList()
{
using (var ctx = new VTContext())
{
return ctx.bio_city.ToList();
}
}
public List<ClockViewModel> GetClockGroupClockList(int groupId)
{
using (var ctx = new VTContext())
{
var data = (from c in ctx.bio_clock.Where(x => x.group_id == groupId)
select new ClockViewModel
{
ClockID = c.rdr_id.ToString(),
ClockDescription = c.clock_desc,
}).ToList();
return data;
}
}
public List<string> GetGroupCostCenter(int groupId)
{
using (var ctx = new VTContext())
{
var data = (from g in ctx.bio_clock_group
from cgc in ctx.bio_clock_group_costctr
where cgc.group_id == g.group_id && g.group_id == groupId
select cgc.cost_ctr).ToList();
return data;
}
}

Insert into Xamarin NSMutableArray<T> results in out of range exception

This code works:
var arr = new NSMutableArray();
arr.Insert(new NSString("lol"), 0);
But this causes System.IndexOutOfRangeException
var arr = new NSMutableArray<NSString>();
arr.Insert(new NSString("lol"), 0);
Same goes to InsertObjects method:
var arr = new NSMutableArray<NSString>(); // Crash
//var arr = new NSMutableArray(); - No crash
var srcArr = new NSString[] { new NSString("one"), new NSString("two") };
var indexes = NSIndexSet.FromNSRange(new NSRange(0, 2));
arr.InsertObjects(srcArr, indexes);
Maybe there are some other methods that don't work. Why is that?
Looks like a bug to me. I can't find anything on the bugtracker.
The workaround would be to use Add if the index is equal to Count. You could pack this into a extension method like:
public static class NSMutableArrayFix
{
public static void InsertFix<T>(this NSMutableArray<T> array, T obj, nint index)
where T : class, INativeObject
{
if(array.Count == (nuint)index)
{
array.Add(obj);
}
else
{
array.Insert(obj, index);
}
}
}
And then you can use
var arr = new NSMutableArray<NSObject>();
arr.InsertFix(new NSString("lol"), 0);

Programmatically create polymer Elements in Dart

Need add polymer paper-dropdown-menu in DOM.
I try this code:
makePapersElements() {
List _items = new List();
for (var i = 0; i < 13; i++) {
PaperItem item = new dom.Element.tag('paper-item');
item.text = i;
_items.add(item);
}
return _items;
}
And add nodes in PaperListbox then in PaperDropdownMenu:
List<PaperItem> items = makePapersElements();
var element = new dom.Element.tag('div');
PaperDropdownMenu dropMenu = new PaperDropdownMenu();
PaperListbox listBox = new dom.Element.tag('paper-listbox');
dropMenu.append(listBox);
listBox.nodes.addAll(items);
element.nodes.add(dropMenu);
$['example'].nodes.add(element);
It's not work currently:
How it can be done?
Update: Added Gist
https://gist.github.com/Rasarts/a0b6710e234ec8b4aa37f90e4cd14839
You can create PaperDropDownMenu and Paperlistbox with new Xxx(), no need for new dom.Element.tag('Xxx') because these elements contain a constructor for convenience where this is done already
https://github.com/dart-lang/polymer_elements/blob/7912e0e6641155505007a89140f11c25db14e3f8/lib/paper_listbox.dart#L61
https://github.com/dart-lang/polymer_elements/blob/7912e0e6641155505007a89140f11c25db14e3f8/lib/paper_dropdown_menu.dart#L69
I guess the issue is because you don't use the Polymer DOM API. See also https://github.com/dart-lang/polymer-dart/wiki/local-dom. Only when you enable full shadow DOM (with full polyfills whithout native support) then you don't need to use this API.
makePapersElements() {
List _items = new List();
for (var i = 0; i < 13; i++) {
PaperItem item = new PaperItem();
item.text = i;
_items.add(item);
}
return _items;
}
List<PaperItem> items = makePapersElements();
var element = new dom.Element.tag('div');
PaperDropdownMenu dropMenu = new PaperDropdownMenu();
PaperListbox listBox = new PaperListbox();
Polymer.dom(dropMenu).append(listBox);
// not sure this will work
Polymer.dom(listBox).childNodes.addAll(items);
// alternatively
var listboxDom = Polymer.dom(listBox);
for(var item in items) {
listboxDom.append(item);
}
Polymer.dom(this)appen(dropMenu);
// ro Polymer.dom(this.root)appen(dropMenu);
Polymer.dom($['example']).append(element);
Yes, I do it wrong. Example helped. Thanks.
https://github.com/bwu-dart-playground/polymer1/blob/12a4bca9c5c5b21c690af0bd4451407b64899a6e/so36689312_programmatically_create_paper_elements/web/pdm_element.dart#L36-L36

Error 'cannot be initialized in a query result' when trying to get data with Linq

ISSUE:
I have an asp.net mvc 3 app. I'm using EF 4.1 and trying out jqGrid. I'm trying to get data for my jqGrid using the GridData method below. I get the following error on the group of data starting at 'var jsonData = new...'. Any ideas?
ERROR:
{"The array type 'System.String[]' cannot be initialized in a query result.
Consider using 'System.Collections.Generic.List`1[System.String]' instead."}
GridData Method:
public JsonResult GridData(string sidx, string sord, int page, int rows)
{
var result = from a in db.t_harvest_statistics_elk
where a.year == "2008" && a.unit_number == 1
orderby a.id
select a;
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = result.Count(); // context.Questions.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var questions = result.Skip(pageIndex * pageSize).Take(pageSize);
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = (
from question in questions
select new
{
i = question.id,
cell = new string[] { SqlFunctions.StringConvert((double)question.id), SqlFunctions.StringConvert((double)question.total_rec_days), question.year }
}).ToArray()
};
return Json(jsonData);
}
HERE IS AN EXAMPLE THAT DOES WORK
public JsonResult DynamicGridData(string sidx, string sord, int page, int rows)
{
var context = new HaackOverflowDataContext();
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = context.Questions.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var questions = context.Questions.OrderBy(sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize);
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = (
from question in questions
select new
{
i = question.Id,
cell = new string[] { question.Id.ToString(), question.Votes.ToString(), question.Title }
}).ToArray()
};
return Json(jsonData);
}
The easiest way to fix the code will be to use something like the following
// to be able to use ToString() below which is NOT exist in the LINQ to Entity
// so we should get the data from the database and save the result locally before
// the next step. One can use .ToList() or to .AsEnumerable(), but one should
// choose only the fields of questions which we will need later
var queryDetails = (from item in questions
select new { item.id, item.total_rec_days, item.year }).ToList();
var jsonData = new {
total = totalPages,
page,
records = totalRecords,
rows = (
from question in queryDetails
select new
{
id = question.Id,
cell = new [] {
question.Id.ToString(),
question.total_rec_days.ToString(),
question.year.ToString()
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
Your current code contain some small problems like the usage of i = question.id instead of id = question.id.
I would recommend you to read the answer and download the demo from the answer which contains more recent and extended code.
var jsonData = new {
total = totalPages,
page,
records = totalRecords,
rows = (
from question in queryDetails
select new
{
id = question.Id,
cell = new IComparable[]{
question.Id.ToString(),
question.total_rec_days.ToString(),
question.year.ToString()
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
Can you try modifying your code like :
rows = (
from question in questions.AsEnumerable() //AsEnumerable() is added to switch to LINQ to Entites to eager load the data.
select new
{
i = question.id,
cell = new string[] { SqlFunctions.StringConvert((double)question.id), SqlFunctions.StringConvert((double)question.total_rec_days), question.year }
}).ToArray()
Because the MSDN says that : "You cannot call this function directly. This function can only appear within a LINQ to Entities query." (Though the next line is little confusing in documentation)
You can't use custom functions inside direct queries to you database. Instead you can do something like this:
rows = questions.AsEnumerable()
//or select just that you want questions.Select(q=> new {g.Id, q.Votes,q.Title})
.Select(p=> new {
id = p.Id,
cell = new string[] { SqlFunctions.StringConvert((double)p.id), SqlFunctions.StringConvert((double)p.total_rec_days), p.year }
}).ToArray()
That should work.

Resources