-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSfmPatient.cs
154 lines (125 loc) · 3.96 KB
/
SfmPatient.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.FhirPath;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Specification;
using Hl7.Fhir.Support;
using Hl7.Fhir.Utility;
using Hl7.FhirPath;
using Hl7.FhirPath.Expressions;
using Hl7.Fhir.Validation;
using Hl7.Fhir.Specification.Source;
namespace FhirTool
{
/// <summary>
/// Helper class for SfmPatient
/// </summary>
public class SfmPatient
{
private Patient p = null;
static string ProfileSfmPatientURL = "http://ehelse.no/fhir/StructureDefinition/sfm-Patient";
static string ExtCitizenURL = "http://hl7.org/fhir/StructureDefinition/patient-citizenship";
static string ExtMiddlenameURL = "http://hl7.no/fhir/StructureDefinition/no-basis-middlename";
public SfmPatient()
{
p = new Patient();
SfmInitPatient();
}
public SfmPatient( Patient existingPat)
{
p = existingPat;
SfmInitPatient();
}
public SfmPatient (string given, string family)
{
p = new Patient();
p.Name.Add(new HumanName().WithGiven(given).AndFamily(family));
SfmInitPatient();
}
void SfmInitPatient()
{
if (p == null) return;
p.Id = Guid.NewGuid().ToString();
if (p.Meta == null)
{
p.Meta = new Meta();
}
p.Meta.VersionId = "1";
p.Meta.LastUpdatedElement = Instant.Now();
p.Meta.Profile = new List<string>() { ProfileSfmPatientURL };
// Wait with this for now!
// Add extension for Citizenship
//Extension citizenship = new Extension(ExtCitizenURL, )
//p.Extension.Add(citizenship);
p.Active = true;
p.Gender = AdministrativeGender.Male;
}
public Patient patient
{
get
{
return p;
}
set
{
p = value;
}
}
/// <summary>
/// Method for accessing middlename
/// Assume exactly one HunmanName
/// </summary>
public String middlename
{
get
{
if (p.Name.Count == 0) return null;
return ExtensionExtensions.GetStringExtension(p.Name[0], ExtMiddlenameURL); // Get extension "middlename" from the first humanname
}
set
{
Extension middle = new Extension(ExtMiddlenameURL, new FhirString(value));
if (p.Name.Count == 0) // In case human name does not exist
{
HumanName hn = new HumanName();
}
ExtensionExtensions.SetStringExtension(p.Name[0], ExtMiddlenameURL, value);
}
}
public String FNR
{
get
{
string fnr = null;
foreach (Identifier i in p.Identifier)
{
if (i.System == "urn:oid:2.16.578.1.12.4.1.4.1")
{
fnr = i.Value;
}
}
return fnr;
}
set
{
foreach (Identifier i in p.Identifier)
{
if (i.System == "urn:oid:2.16.578.1.12.4.1.4.1")
{
p.Identifier.Remove(i);
}
}
var id = new Identifier();
id.System = "urn:oid:2.16.578.1.12.4.1.4.1";
id.Value = value;
id.Use = Identifier.IdentifierUse.Official;
p.Identifier.Add(id);
}
}
}
}