3 using System.Collections;
4 using System.Collections.Generic;
11 using System.ComponentModel;
15 static private Patient loadedPatient = null;
17 private List<AdditionalInformation> additionalInformation =
new List<AdditionalInformation> ();
18 private List<string> additionalInformationTabs =
new List<string> ();
19 private List<View> mViews =
new List<View> ();
20 private List<AnnotationJson> rawAnnotation =
new List<AnnotationJson> ();
21 private List<GameObject> mAnnotations =
new List<GameObject> ();
25 public string name {
get; set; }
26 public string type {
get; set; }
27 public string content {
get; set; }
28 public string tabName {
get; set; }
33 PatientEventSystem.stopListening (PatientEventSystem.Event.PATIENT_FinishedLoading, finishedLoading);
34 PatientEventSystem.startListening (PatientEventSystem.Event.PATIENT_FinishedLoading, finishedLoading);
35 PatientEventSystem.startListening (PatientEventSystem.Event.PATIENT_Closed, closePatient);
42 stopListeningToEvents ();
45 private void stopListeningToEvents()
47 PatientEventSystem.stopListening (PatientEventSystem.Event.PATIENT_FinishedLoading, finishedLoading);
50 private string rewritePathInHTML(
string content,
string filePath)
53 string folderHTMLSources =
"";
54 string[] substrings = filePath.Split(
'/');
55 for (
int i = 0; i < substrings.Length - 1; i++)
57 folderHTMLSources += substrings[i];
62 c = c.Replace(
"src=\".",
"src=\"./" + path +
"/" + folderHTMLSources);
63 c = c.Replace(
"href=\".",
"href=\"./" + path +
"/" + folderHTMLSources);
68 public static Patient getLoadedPatient()
79 public static void close()
81 if (loadedPatient != null)
82 loadedPatient.stopListeningToEvents ();
86 public List<string> getAdditionalInfoTabs()
88 return additionalInformationTabs;
90 public List<AdditionalInformation> getAdditionalInfo()
92 return additionalInformation;
106 private string bold(
string input )
108 return "<b>" + input +
"</b>";
114 public int getViewCount()
118 public int insertView(
View newView,
int index )
120 index = Mathf.Min (index, mViews.Count);
121 mViews.Insert (index, newView);
124 public View getView(
int index )
126 if ( index >= 0 && mViews.Count > index) {
127 return mViews [index];
132 public void deleteView(
int index )
134 if (index >= 0 && mViews.Count > index) {
135 mViews.RemoveAt (index);
139 private void readViews()
142 string viewsFile = Path.Combine (base.path,
"views.json");
145 if (File.Exists (viewsFile)) {
149 System.IO.StreamReader file =
new System.IO.StreamReader (viewsFile);
150 while ((line = file.ReadLine ()) != null) {
160 Debug.Log (
"Loaded: " + mViews.Count +
" views.");
163 public void saveViews()
165 Patient p = Patient.getLoadedPatient();
166 string path = p.path +
"/views.json";
169 if (!File.Exists(path))
171 using (StreamWriter outputFile =
new StreamWriter(path,
true))
178 using (StreamWriter outputFile =
new StreamWriter(path))
180 foreach(
View view
in mViews)
183 outputFile.WriteLine(JsonMapper.ToJson(vj));
193 public void setupDefaultWidgets()
197 Widget w = UI.Core.instance.getWidgetByName (
"ViewControl");
199 w.gameObject.SetActive (
true);
201 w = UI.Core.instance.getWidgetByName (
"PatientBriefing");
203 w.gameObject.SetActive (
true);
205 w = UI.Core.instance.getWidgetByName (
"DICOMViewer");
207 w.gameObject.SetActive (
true);
213 private void PatientLoaderWorker(
object sender, DoWorkEventArgs e)
215 string metaFile = Path.Combine(base.path,
"meta.json");
216 string raw = File.ReadAllText(metaFile);
220 data = JsonMapper.ToObject(raw);
224 throw new System.Exception(
"Cannot parse meta.json. Invalid syntax?");
227 if (data.Keys.Contains(
"additional information"))
229 JsonData infoArray = data[
"additional information"];
232 additionalInformationTabs.Add(
"General");
234 c += bold(
"Patient Name: ") + name +
"\n";
235 c += bold(
"Date of Birth: ") + birthDate +
"\n";
236 c += bold(
"Date of Operation: ") + operationDate +
"\n";
237 AdditionalInformation info =
new AdditionalInformation
239 name =
"Patient Information",
244 additionalInformation.Add(info);
247 for (
int i = 0; i < infoArray.Count; i++)
249 JsonData entry = infoArray[i];
250 if (entry.Keys.Contains(
"Name") && entry.Keys.Contains(
"File"))
253 if (System.IO.File.Exists(base.path +
"/" + entry[
"File"]))
255 string content = System.IO.File.ReadAllText(base.path +
"/" + entry[
"File"]);
256 string title = entry[
"Name"].ToString();
257 string type =
"plainText";
258 if (entry.Keys.Contains(
"Type"))
259 type = entry[
"Type"].ToString();
260 string tabName =
"General";
261 if (entry.Keys.Contains(
"Tab"))
263 tabName = entry[
"Tab"].ToString();
265 if (name.Length > 0 && content.Length > 0)
267 info =
new AdditionalInformation
274 if (info.type ==
"HTML")
276 info.content = rewritePathInHTML(info.content, entry[
"File"].ToString());
279 additionalInformation.Add(info);
280 if (!additionalInformationTabs.Contains(tabName))
282 additionalInformationTabs.Add(tabName);
291 loadAnnotationFromFile ();
294 private void PatientLoaderCallback(
object sender, RunWorkerCompletedEventArgs e)
299 Debug.Log(
"[Patient.cs] Patient Loading cancelled");
301 else if (e.Error != null)
303 Debug.LogError(
"[Patient.cs] Error while loading the patient");
307 loadedPatient =
this;
310 PatientEventSystem.triggerEvent(PatientEventSystem.Event.PATIENT_Loaded,
this);
319 public void updateAnnotationList( List<GameObject> list )
325 private void loadAnnotationFromFile (
object obj = null)
335 string path = this.path +
"/annotation.json";
337 if (!File.Exists (path)) {
341 List<AnnotationJson> apjList =
new List<AnnotationJson> ();
344 System.IO.StreamReader file =
new System.IO.StreamReader (path);
345 while ((line = file.ReadLine ()) != null) {
352 rawAnnotation = apjList;
355 public void createAnnotations() {
357 AnnotationControl.instance.createAnnotation (aJson);
359 AnnotationControl.instance.updatePatientAnnotationList ();
360 AnnotationControl.instance.clearAll ();
365 public void saveAnnotation ()
368 if (loadedPatient == null) {
372 string path = loadedPatient.path +
"/annotation.json";
375 if (!File.Exists (path)) {
376 using (StreamWriter outputFile =
new StreamWriter (path,
true)) {
382 using (StreamWriter outputFile =
new StreamWriter (path)) {
383 foreach (GameObject apListEntry
in mAnnotations) {
387 apj.type = ap.GetComponent<
Annotation> ().myType;
388 apj.Text = ap.GetComponent<
Annotation> ().getLabelText ();
389 apj.ColorR = ap.GetComponent<
Annotation> ().getColor ().r;
390 apj.ColorG = ap.GetComponent<
Annotation> ().getColor ().g;
391 apj.ColorB = ap.GetComponent<
Annotation> ().getColor ().b;
392 apj.ScaleX = ap.GetComponent<
Annotation> ().getMeshScale ().x;
393 apj.ScaleY = ap.GetComponent<
Annotation> ().getMeshScale ().y;
394 apj.ScaleZ = ap.GetComponent<
Annotation> ().getMeshScale ().z;
395 apj.PositionX = ap.transform.localPosition.x;
396 apj.PositionY = ap.transform.localPosition.y;
397 apj.PositionZ = ap.transform.localPosition.z;
399 apj.RotationW = ap.transform.localRotation.w;
400 apj.RotationX = ap.transform.localRotation.x;
401 apj.RotationY = ap.transform.localRotation.y;
402 apj.RotationZ = ap.transform.localRotation.z;
405 apj.MeshRotationW = ap.GetComponent<
Annotation> ().myAnnotationMesh.transform.localRotation.w;
406 apj.MeshRotationX = ap.GetComponent<
Annotation> ().myAnnotationMesh.transform.localRotation.x;
407 apj.MeshRotationY = ap.GetComponent<
Annotation> ().myAnnotationMesh.transform.localRotation.y;
408 apj.MeshRotationZ = ap.GetComponent<
Annotation> ().myAnnotationMesh.transform.localRotation.z;
411 apj.Creator = ap.GetComponent<
Annotation> ().creator;
412 apj.CreationDate = ap.GetComponent<
Annotation> ().creationDate;
413 outputFile.WriteLine (JsonUtility.ToJson (apj));
424 public void finishedLoading(
object obj = null)
429 setupDefaultWidgets();
430 NotificationControl.instance.createNotification (
"Patient loaded.",
new TimeSpan (0, 0, 5));
434 public void closePatient (
object obj = null)
436 AnnotationControl.instance.deleteAllAnnotations ();
437 AnnotationControl.instance.resetLayers ();
438 PatientEventSystem.stopListening (PatientEventSystem.Event.PATIENT_Closed, closePatient);