-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
591 lines (520 loc) · 28.4 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.Text;
using System.Threading;
using System.Xml.Serialization;
using HL7TestClient.Constants;
using HL7TestClient.Interfaces;
using HL7TestClient.PersonRegistry;
using NHN.HL7.Constants;
namespace HL7TestClient
{
class Program
{
private const string FhNumberOid = "2.16.578.1.12.4.1.4.3";
private const string DateFormat = "yyyyMMdd";
private const string RootNamespace = "urn:hl7-org:v3";
private static readonly XmlSerializer FindCandidatesRequestSerializer = new XmlSerializer(typeof (PRPA_IN101305NO01), new XmlRootAttribute {Namespace = RootNamespace});
private static readonly XmlSerializer FindCandidatesResponseSerializer = new XmlSerializer(typeof (PRPA_IN101306NO01), new XmlRootAttribute {Namespace = RootNamespace});
private static readonly XmlSerializer GetDemographicsRequestSerializer = new XmlSerializer(typeof (PRPA_IN101307NO01), new XmlRootAttribute {Namespace = RootNamespace});
private static readonly XmlSerializer GetDemographicsResponseSerializer = new XmlSerializer(typeof (PRPA_IN101308NO01), new XmlRootAttribute {Namespace = RootNamespace});
private static readonly XmlSerializer AddPersonRequestSerializer = new XmlSerializer(typeof (PRPA_IN101311NO01), new XmlRootAttribute {Namespace = RootNamespace});
private static readonly XmlSerializer RevisePersonRecordRequestSerializer = new XmlSerializer(typeof (PRPA_IN101314NO01), new XmlRootAttribute {Namespace = RootNamespace});
private static readonly XmlSerializer AddPersonOrRevisePersonRecordResponseSerializer = new XmlSerializer(typeof (PRPA_IN101319NO01), new XmlRootAttribute {Namespace = RootNamespace});
private static readonly XmlSerializer LinkPersonRecordsRequestSerializer = new XmlSerializer(typeof (PRPA_IN101901NO01), new XmlRootAttribute {Namespace = RootNamespace});
private static readonly XmlSerializer UnlinkPersonRecordsRequestSerializer = new XmlSerializer(typeof (PRPA_IN101911NO01), new XmlRootAttribute {Namespace = RootNamespace});
private static readonly XmlSerializer AcknowledgementSerializer = new XmlSerializer(typeof (MCAI_IN000004NO01), new XmlRootAttribute {Namespace = RootNamespace});
private static CS _processingCode = ProcessingCode.Test();
private static readonly Random Random = new Random();
static void Main()
{
var client = CreateClient();
while (true)
{
try
{
Console.Write("\nWould you like to (F)indCandidates, (G)etDemographics, (A)ddPerson, (R)evisePersonRecord, (L)inkPersonRecords, (U)nlinkPersonRecords, change (P)rocessing code, run performance (T)est, or (E)xit? ");
string action = (Console.ReadLine() ?? "E").Trim().ToUpper();
if (action == "F")
FindCandidates(client);
else if (action == "G")
GetDemographics(client);
else if (action == "A")
AddPerson(client);
else if (action == "R")
RevisePersonRecord(client);
else if (action == "L")
LinkPersonRecords(client);
else if (action == "U")
UnlinkPersonRecords(client);
else if (action == "P")
ChangeProcessingCode();
else if (action == "T")
RunPerformanceTest(client);
else if (action == "E")
break;
}
catch (Exception e)
{
Console.WriteLine(e);
if (e is EndpointNotFoundException && e.InnerException is WebException)
{
if (e.InnerException.Message == "The remote server returned an error: (404) Not Found.")
Console.WriteLine("\n\n=== An error occurred when connecting to the server: the server was found, but the service endpoint was not found. This probably means that the URL in the config file is wrong. ===\n");
else if (e.InnerException.Message.StartsWith("The remote name could not be resolved: "))
Console.WriteLine("\n\n=== An error occurred when connecting to the server: the server was not found. This probably means that the URL in the config file is wrong. ===\n");
}
else if (e is MessageSecurityException && e.InnerException is FaultException)
{
if (e.InnerException.Message == "An error occurred when verifying security for the message.")
Console.WriteLine("\n\n=== An error occurred when establishing a secure connection. A possible reason for this is that your local machine clock is out of synch with NHN's server clock. Please contact NHN and ask what the server time is on the server you're trying to connect to. ===\n");
else if (e.InnerException.Message == "At least one security token in the message could not be validated.")
Console.WriteLine("\n\n=== An error occurred when authenticating. This probably means that the username and/or password in the config file are wrong. ===\n");
}
client.Abort();
((IDisposable) client).Dispose();
client = CreateClient();
}
}
client.Abort();
((IDisposable) client).Dispose();
}
private static PersonRegistryClient CreateClient()
{
var client = new PersonRegistryClient();
client.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["username"];
client.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["password"];
return client;
}
private static void FindCandidates(PersonRegistryClient client)
{
var info = ReadPersonalInformation(false, false);
var paramList = new PRPA_MT101306NO01ParameterList();
var nameItems = CreateNameItems(info);
if (nameItems.Count() > 0)
paramList.personName = CreatePersonNameParameter(nameItems);
if (IsDateSpecifiedAndValid(info.DateOfBirth))
paramList.personBirthTime = CreatePersonBirthTimeParameter(info.DateOfBirth);
var addressItems = CreateAddressItems(info);
if (addressItems.Count() > 0)
paramList.identifiedPersonAddress = CreateIdentifiedPersonAddressParameter(addressItems);
var message = SetTopLevelFields(new PRPA_IN101305NO01 {
controlActProcess = new PRPA_IN101305NO01QUQI_MT021001UV01ControlActProcess {
queryByParameter = new PRPA_MT101306NO01QueryByParameter {
parameterList = paramList
}
}
});
FindCandidatesRequestSerializer.Serialize(Console.Out, message);
Console.WriteLine("\n");
PRPA_IN101306NO01 result = client.FindCandidates(message);
FindCandidatesResponseSerializer.Serialize(Console.Out, result);
Console.WriteLine("\n");
Console.WriteLine("Found {0} persons:", result.controlActProcess.queryAck.resultTotalQuantity.value);
if (result.controlActProcess.subject != null)
foreach (var subject in result.controlActProcess.subject)
Console.WriteLine(PersonToString(subject.registrationEvent.subject1.identifiedPerson));
}
private static void GetDemographics(PersonRegistryClient client)
{
string idNumber = ReadLineAndTrim("Enter id number: ");
if (string.IsNullOrWhiteSpace(idNumber))
return;
var id = new II {root = GetOid(idNumber.Trim()), extension = idNumber.Trim()};
PRPA_IN101307NO01 request = CreateGetDemographicsRequest(id);
GetDemographicsRequestSerializer.Serialize(Console.Out, request);
Console.WriteLine("\n");
PRPA_IN101308NO01 response = client.GetDemographics(request);
GetDemographicsResponseSerializer.Serialize(Console.Out, response);
Console.WriteLine("\n");
string queryResponseCode = response.controlActProcess.queryAck.queryResponseCode.code;
switch (queryResponseCode)
{
case QueryResponseCode.Ok:
Console.WriteLine(PersonToString(response.controlActProcess.subject[0].registrationEvent.subject1.identifiedPerson));
break;
case QueryResponseCode.NoResultsFound:
Console.WriteLine("No results found");
break;
case QueryResponseCode.QueryParameterError:
Console.WriteLine("Query parameter error");
break;
default:
Console.WriteLine("Unrecognized query response code: '{0}'", queryResponseCode);
break;
}
}
private static PRPA_IN101307NO01 CreateGetDemographicsRequest(II id)
{
return SetTopLevelFields(new PRPA_IN101307NO01 {
controlActProcess = new PRPA_IN101307NO01QUQI_MT021001UV01ControlActProcess {
queryByParameter = new PRPA_MT101307UV02QueryByParameter {
parameterList = new PRPA_MT101307UV02ParameterList {
identifiedPersonIdentifier = new[] {
new PRPA_MT101307UV02IdentifiedPersonIdentifier {value = new[] {id}}
}
}
}
}
});
}
private static void AddPerson(PersonRegistryClient client)
{
var info = ReadPersonalInformation(false, true);
var innerPerson = new PRPA_MT101311NO01Person();
var nameItems = CreateNameItems(info);
if (nameItems.Count() > 0)
innerPerson.name = new[] {new PN(nameItems)};
if (IsDateSpecifiedAndValid(info.DateOfBirth))
innerPerson.birthTime = new TS(info.DateOfBirth);
var addressItems = CreateAddressItems(info);
if (addressItems.Count() > 0)
innerPerson.addr = new[] {new AD(addressItems)};
if (info.Gender != "")
innerPerson.administrativeGenderCode = CreateAdministrativeGenderCode(info.Gender);
var request = SetTopLevelFields(new PRPA_IN101311NO01 {
controlActProcess = new PRPA_IN101311NO01MFMI_MT700721UV01ControlActProcess {
subject = new PRPA_IN101311NO01MFMI_MT700721UV01Subject1 {
registrationRequest = new PRPA_IN101311NO01MFMI_MT700721UV01RegistrationRequest {
subject1 = new PRPA_IN101311NO01MFMI_MT700721UV01Subject2 {
identifiedPerson = new PRPA_MT101311NO01IdentifiedPerson {
identifiedPerson = innerPerson
}
}
}
}
}
});
AddPersonRequestSerializer.Serialize(Console.Out, request);
Console.WriteLine("\n");
PRPA_IN101319NO01 response = client.AddPerson(request);
AddPersonOrRevisePersonRecordResponseSerializer.Serialize(Console.Out, response);
Console.WriteLine("\n");
var pathToFirstNull = new List<string>();
var subject = NullSafeObjectPathTraverser.Traverse(response, r => r.controlActProcess.subject, pathToFirstNull);
if (subject != null && subject.Length > 0)
{
var id = NullSafeObjectPathTraverser.Traverse(subject[0], s => s.registrationEvent.subject1.identifiedPerson.id, pathToFirstNull);
if (id != null && id.Length > 0)
Console.WriteLine("The person has been given the FH-number " + id[0].extension);
}
}
private static CE CreateAdministrativeGenderCode(string gender)
{
return new CE {code = gender, codeSystem = "2.16.840.1.113883.5.1"};
}
private static void RevisePersonRecord(PersonRegistryClient client)
{
var info = ReadPersonalInformation(true, true);
var outerPerson = new PRPA_MT101302NO01IdentifiedPerson {
id = new[] {new II {root = GetOid(info.FhNumber), extension = info.FhNumber}},
identifiedPerson = new PRPA_MT101302NO01Person()
};
var nameItems = CreateNameItems(info);
if (nameItems.Count() > 0)
outerPerson.identifiedPerson.name = new[] {new PN(nameItems)};
if (IsDateSpecifiedAndValid(info.DateOfBirth))
outerPerson.identifiedPerson.birthTime = new TS(info.DateOfBirth);
var addressItems = CreateAddressItems(info);
if (addressItems.Count() > 0)
outerPerson.identifiedPerson.addr = new[] {new AD(addressItems)};
if (info.Gender != "")
outerPerson.identifiedPerson.administrativeGenderCode = CreateAdministrativeGenderCode(info.Gender);
var request = SetTopLevelFields(new PRPA_IN101314NO01 {
controlActProcess = new PRPA_IN101314NO01MFMI_MT700721UV01ControlActProcess {
subject = new PRPA_IN101314NO01MFMI_MT700721UV01Subject1 {
registrationRequest = new PRPA_IN101314NO01MFMI_MT700721UV01RegistrationRequest {
subject1 = new PRPA_IN101314NO01MFMI_MT700721UV01Subject2 {
identifiedPerson = outerPerson
}
}
}
}
});
RevisePersonRecordRequestSerializer.Serialize(Console.Out, request);
Console.WriteLine("\n");
PRPA_IN101319NO01 response = client.RevisePersonRecord(request);
AddPersonOrRevisePersonRecordResponseSerializer.Serialize(Console.Out, response);
Console.WriteLine();
}
private static void LinkPersonRecords(PersonRegistryClient client)
{
Console.Write("Enter obsolete FH-number: ");
string obsoleteFhNumber = Console.ReadLine();
Console.Write("Enter surviving ID-number or FH-number: ");
string survivingIdNumberOrFhNumber = Console.ReadLine();
if (string.IsNullOrWhiteSpace(obsoleteFhNumber) || string.IsNullOrWhiteSpace(survivingIdNumberOrFhNumber))
return;
var request = SetTopLevelFields(new PRPA_IN101901NO01 {
controlActProcess = new PRPA_IN101901NO01MFMI_MT700721UV01ControlActProcess {
subject = new PRPA_IN101901NO01MFMI_MT700721UV01Subject1 {
registrationRequest = new PRPA_IN101901NO01MFMI_MT700721UV01RegistrationRequest {
subject1 = new PRPA_IN101901NO01MFMI_MT700721UV01Subject2 {
identifiedPerson = new PRPA_MT101901NO01IdentifiedPerson {
id = new[] {new II(GetOid(survivingIdNumberOrFhNumber), survivingIdNumberOrFhNumber)},
identifiedBy = new[] {
new PRPA_MT101901NO01SourceOf2 {
//TODO: Is the value of statusCode important?
otherIdentifiedPerson = new PRPA_MT101901NO01OtherIdentifiedPerson {
id = new II(GetOid(obsoleteFhNumber), obsoleteFhNumber)
}
}
}
}
}
}
}
}
});
LinkPersonRecordsRequestSerializer.Serialize(Console.Out, request);
Console.WriteLine("\n");
MCAI_IN000004NO01 response = client.LinkPersonRecords(request);
AcknowledgementSerializer.Serialize(Console.Out, response);
Console.WriteLine();
}
private static void UnlinkPersonRecords(PersonRegistryClient client)
{
Console.Write("Enter child FH-number: ");
string obsoleteFhNumber = Console.ReadLine();
Console.Write("Enter parent ID-number or FH-number: ");
string survivingIdNumberOrFhNumber = Console.ReadLine();
if (string.IsNullOrWhiteSpace(obsoleteFhNumber) || string.IsNullOrWhiteSpace(survivingIdNumberOrFhNumber))
return;
var request = SetTopLevelFields(new PRPA_IN101911NO01 {
controlActProcess = new PRPA_IN101911NO01MFMI_MT700721UV01ControlActProcess {
subject = new PRPA_IN101911NO01MFMI_MT700721UV01Subject1 {
registrationRequest = new PRPA_IN101911NO01MFMI_MT700721UV01RegistrationRequest {
subject1 = new PRPA_IN101911NO01MFMI_MT700721UV01Subject2 {
identifiedPerson = new PRPA_MT101911NO01IdentifiedPerson {
id = new[] {new II(GetOid(survivingIdNumberOrFhNumber), survivingIdNumberOrFhNumber)},
identifiedBy = new PRPA_MT101911NO01SourceOf2 {
//TODO: Is the value of statusCode important?
otherIdentifiedPerson = new PRPA_MT101911NO01OtherIdentifiedPerson {
id = new II(GetOid(obsoleteFhNumber), obsoleteFhNumber)
}
}
}
}
}
}
}
});
UnlinkPersonRecordsRequestSerializer.Serialize(Console.Out, request);
Console.WriteLine("\n");
MCAI_IN000004NO01 response = client.UnlinkPersonRecords(request);
AcknowledgementSerializer.Serialize(Console.Out, response);
Console.WriteLine();
}
private static void ChangeProcessingCode()
{
Console.Write("Please choose (P)roduction, (T)est, or (D)ebugging: ");
while (true)
{
string code = (Console.ReadLine() ?? "").ToUpper();
if (code == "P")
{
_processingCode = ProcessingCode.Production();
return;
}
if (code == "T")
{
_processingCode = ProcessingCode.Test();
break;
}
if (code == "D")
{
_processingCode = ProcessingCode.Debugging();
break;
}
}
}
private static void RunPerformanceTest(PersonRegistryClient client)
{
var sw = new Stopwatch();
sw.Start();
client.GetDemographics(CreateGetDemographicsRequest(new II(FhNumberOid, CreateRandomFhNumber())));
sw.Stop();
Console.WriteLine("Initial request: " + sw.Elapsed);
sw.Restart();
const int numRequests = 1000;
for (int i = 0; i < numRequests; ++i)
{
client.GetDemographics(CreateGetDemographicsRequest(new II(FhNumberOid, CreateRandomFhNumber())));
}
sw.Stop();
Console.WriteLine("{0} subsequent requests: {1} ({2} ms per request)", numRequests, sw.Elapsed, sw.ElapsedMilliseconds / numRequests);
sw.Restart();
const int numIndividualRequests = 100;
for (int i = 0; i < numIndividualRequests; ++i)
{
using (var c = CreateClient())
{
c.GetDemographics(CreateGetDemographicsRequest(new II(FhNumberOid, CreateRandomFhNumber())));
}
}
sw.Stop();
Console.WriteLine("{0} individual requests: {1} ({2} ms per request)", numIndividualRequests, sw.Elapsed, sw.ElapsedMilliseconds / numIndividualRequests);
const int numThreads = 20;
var threads = new Thread[numThreads];
for (int i = 0; i < numThreads; ++i)
{
threads[i] = new Thread(ThreadTester);
threads[i].Start(i);
}
foreach (var thread in threads)
thread.Join();
}
private static void ThreadTester(object threadId)
{
var sw = new Stopwatch();
sw.Start();
const int numIndividualRequests = 50;
using (var c = CreateClient())
{
for (int i = 0; i < numIndividualRequests; ++i)
{
c.GetDemographics(CreateGetDemographicsRequest(new II(FhNumberOid, CreateRandomFhNumber())));
}
}
sw.Stop();
Console.WriteLine("{0} individual requests from thread #{1}: {2} ({3} ms per request)", numIndividualRequests, (int)threadId, sw.Elapsed, sw.ElapsedMilliseconds / numIndividualRequests);
}
private static string CreateRandomFhNumber()
{
while (true)
{
string fhNumber = Random.Next(800000000, 800009999).ToString();
if (ChecksumGenerator.AppendChecksum(ref fhNumber))
return fhNumber;
}
}
private static IEnumerable<ENXP> CreateNameItems(PersonalInformation info)
{
var nameItems = new List<ENXP>();
nameItems.AddRange(info.FirstName.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries).Select(fn => new engiven(fn)));
nameItems.AddRange(info.MiddleName.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries).Select(mn => new enfamily(mn, true)));
nameItems.AddRange(info.LastName.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries).Select(ln => new enfamily(ln)));
return nameItems;
}
private static IEnumerable<ADXP> CreateAddressItems(PersonalInformation info)
{
var addressItems = new List<ADXP>();
if (info.StreetAddressLine != "")
addressItems.Add(new adxpstreetAddressLine {Text = new[] {info.StreetAddressLine}});
if (info.ZipCode != "")
addressItems.Add(new adxppostalCode {Text = new[] {info.ZipCode}});
return addressItems;
}
private static bool IsDateSpecifiedAndValid(string date)
{
if (date == "")
return false;
DateTime dummy;
if (DateTime.TryParseExact(date, DateFormat, null, DateTimeStyles.None, out dummy))
return true;
Console.WriteLine("Warning: Date of birth is illegal; skipping");
return false;
}
private static PRPA_MT101306NO01PersonName[] CreatePersonNameParameter(IEnumerable<ENXP> nameItems)
{
return new[] {new PRPA_MT101306NO01PersonName {value = new[] {new PN {Items = nameItems.ToArray()}}}};
}
private static PRPA_MT101306NO01IdentifiedPersonAddress[] CreateIdentifiedPersonAddressParameter(IEnumerable<ADXP> addressItems)
{
return new[] {new PRPA_MT101306NO01IdentifiedPersonAddress {value = new[] {new AD {Items = addressItems.ToArray()}}}};
}
private static PRPA_MT101306NO01PersonBirthTime[] CreatePersonBirthTimeParameter(string dateOfBirth)
{
return new[] {new PRPA_MT101306NO01PersonBirthTime {value = new[] {new IVL_TS {value = dateOfBirth}}}};
}
private static string GetOid(string idNumber)
{
if (idNumber[0] >= '8')
return FhNumberOid;
else if (idNumber[0] >= '4')
return "2.16.578.1.12.4.1.4.2";
else
return "2.16.578.1.12.4.1.4.1";
}
private static II CreateMessageId()
{
return new II("1.2.3.4", Guid.NewGuid().ToString());
}
private static string PersonToString(IIdentifiedPerson identifiedPerson)
{
var sb = new StringBuilder();
sb.Append(identifiedPerson.id[0].extension);
sb.Append(": ");
IPerson person = identifiedPerson.identifiedPerson;
if (person.name != null && person.name.Length > 0 && person.name[0].Items != null)
sb.Append(string.Join(" ", person.name[0].Items.Select(ni => ni.Text[0])));
else
sb.Append("(no name)");
if (person.administrativeGenderCode != null)
{
sb.Append("; Gender: ");
sb.Append(person.administrativeGenderCode.code);
}
if (person.birthTime != null)
{
sb.Append("; Date of birth: ");
sb.Append(person.birthTime.value);
}
if (person.addr != null && person.addr.Length > 0)
{
sb.Append("; Address: ");
sb.Append(string.Join(" ", person.addr[0].Items.Select(ai => ai.Text != null && ai.Text.Length > 0 ? ai.Text[0] : "")));
}
return sb.ToString();
}
private static TMessage SetTopLevelFields<TMessage>(TMessage message)
where TMessage : IRequestMessage
{
message.id = CreateMessageId();
message.interactionId = new II("2.16.840.1.113883.1.6", typeof (TMessage).Name);
message.processingCode = _processingCode;
message.processingModeCode = new CS("T");
message.versionCode = new CS("NE2010NO");
message.receiver = new[] {
new MCCI_MT000100UV01Receiver {
typeCode = CommunicationFunctionType.RCV,
device = new MCCI_MT000100UV01Device {
classCode = EntityClassDevice.DEV,
determinerCode = EntityDeterminerSpecific.INSTANCE,
id = new[] {
new II("2.16.578.1.12.4.5.1.1", null),
}
}
}
};
return message;
}
private static PersonalInformation ReadPersonalInformation(bool askForIdNumber, bool askForGender)
{
var info = new PersonalInformation();
if (askForIdNumber)
info.FhNumber = ReadLineAndTrim("FH-number: ");
info.FirstName = ReadLineAndTrim("First name(s): ");
info.MiddleName = ReadLineAndTrim("Middle name(s): ");
info.LastName = ReadLineAndTrim("Last name(s): ");
info.DateOfBirth = ReadLineAndTrim(string.Format("Date of birth ({0}): ", DateFormat));
info.StreetAddressLine = ReadLineAndTrim("Street address line: ");
info.ZipCode = ReadLineAndTrim("Zip code: ");
if (askForGender)
info.Gender = ReadLineAndTrim("Gender (M/F): ");
return info;
}
private static string ReadLineAndTrim(string message)
{
Console.Write(message);
return (Console.ReadLine() ?? "").Trim();
}
}
}