Skip to content

Commit

Permalink
# - properly define the scaffolds' database formats
Browse files Browse the repository at this point in the history
  • Loading branch information
dlatikay committed Nov 23, 2023
1 parent e937927 commit 7d782c5
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@
***********************************************************************************/

using Lc.Linca.Sdk.Sample.Resources;
using Lc.Linca.Sdk.Scaffolds;
using System.Security.Cryptography.X509Certificates;

namespace Lc.Linca.Sdk.Client;

internal class Program
internal static class LinkedCareSampleClient
{
/// <summary>
/// In SDK, this always points to the development system
/// </summary>
internal const string FhirServerBaseUrl = "https://fhir5-d.linkedcare.at";
//internal const string FhirServerBaseUrl = "https://localhost:8084";

internal static CareInformationSystem CareInformationSystemScaffold = new();
internal static PractitionerInformationSystem PractitionerInformationSystemScaffold = new();
internal static PharmacyInformationSystem PharmacyInformationSystemScaffold = new();

private const string CommandLineArgumentUseEmbeddedCert = "--use-embedded-cert";
private const int ExitCodeCouldNotConnect = 0xaca1;
private const int ExitCodeIdle = 0x1;
Expand Down
46 changes: 31 additions & 15 deletions Lc.Linca.Sdk.Sample/Scaffolds/ActorSoftwareScaffold.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Lc.Linca.Sdk.Scaffolds;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Lc.Linca.Sdk.Scaffolds;

/// <summary>
/// An abstract representation of a software product
Expand All @@ -8,30 +11,43 @@
/// </summary>
internal abstract class ActorSoftwareScaffold
{
internal enum PseudoDatabaseField
internal PseudoStore Data;

protected string db { init; get; }

protected internal ActorSoftwareScaffold(string db)
{
PatientId = 0
Data = new();
this.db = db;
}

internal static void PseudoDatabaseStore(string db, PseudoDatabaseField field, Guid value)
internal void PseudoDatabaseStore()
{
var record = new byte[16 * typeof(PseudoDatabaseField).GetFields().Length];

value.ToByteArray().CopyTo(record, 16 * (short)field);
File.WriteAllBytes($".{db}.tmp.db", record);
File.WriteAllText($".{db}.tmp.lcdb", JsonSerializer.Serialize(Data));
}

internal static Guid PseudoDatabaseRetrieve(string db, PseudoDatabaseField field)
internal void PseudoDatabaseRetrieve()
{
try
{
var content = File.ReadAllBytes($".{db}.tmp.db");
var fileName = $".{db}.tmp.lcdb";

return new(content.Skip((short)field * 16).Take(16).ToArray());
if (File.Exists(fileName))
{
Data = JsonSerializer.Deserialize<PseudoStore>(File.ReadAllText(fileName))!;
}
catch
else
{
return Guid.Empty;
Data = new();
}
}

internal class PseudoStore
{
public string ClientIdRenate { get; set; } = string.Empty;
public string ClientIdGuenter { get; set; } = string.Empty;
public string ClientIdPatrizia { get; set; } = string.Empty;
public string LcIdImmerdar { get; set; } = string.Empty;
public string LcIdVogelsang { get; set; } = string.Empty;
public string OrderProposalIdGuenter { get; set; } = string.Empty;
public string OrderProposalIdPatrizia { get; set; } = string.Empty;
}
}
37 changes: 2 additions & 35 deletions Lc.Linca.Sdk.Sample/Scaffolds/CareInformationSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Runtime.CompilerServices;

namespace Lc.Linca.Sdk.Scaffolds;
namespace Lc.Linca.Sdk.Scaffolds;

/// <summary>
/// A minimal implementation of a fictitious care information
Expand All @@ -9,38 +7,7 @@ namespace Lc.Linca.Sdk.Scaffolds;
/// </summary>
internal class CareInformationSystem : ActorSoftwareScaffold
{
public static Client GetClient()
{
var clientInfo = new Client()
{
ClientId = GetClientIdFromDb()
};

return clientInfo;
}

private static Guid GetClientIdFromDb()
{
var clientId = Guid.NewGuid();
var existingClientId = PseudoDatabaseRetrieve(nameof(CareInformationSystem), PseudoDatabaseField.PatientId);

if (existingClientId == Guid.Empty)
{
/* what a caregiver calls a client,
* a doctor calls a patient. */
PseudoDatabaseStore(
nameof(CareInformationSystem),
PseudoDatabaseField.PatientId,
clientId
);
}
else
{
clientId = existingClientId;
}

return clientId;
}
public CareInformationSystem() : base(nameof(CareInformationSystem)) { }

public class Client
{
Expand Down
1 change: 1 addition & 0 deletions Lc.Linca.Sdk.Sample/Scaffolds/PharmacyInformationSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
/// </summary>
internal class PharmacyInformationSystem : ActorSoftwareScaffold
{
public PharmacyInformationSystem() : base(nameof(PharmacyInformationSystem)) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
/// </summary>
internal class PractitionerInformationSystem : ActorSoftwareScaffold
{
public PractitionerInformationSystem() : base(nameof(PractitionerInformationSystem)) { }
}
85 changes: 22 additions & 63 deletions Lc.Linca.Sdk.Sample/Specs/ActorCare/US001-MedOrderSingleArticle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Lc.Linca.Sdk.Client;
using Lc.Linca.Sdk.Scaffolds;
using System.Globalization;

Expand All @@ -26,7 +27,6 @@ internal class US001_MedOrderSingleArticle : Spec
As Susanne Allzeit will pick up the medication on the go, she places the order
without specifying a pharmacy.";

public Patient createdPatient = new Patient();
protected MedicationRequest medReq = new();

public US001_MedOrderSingleArticle(LincaConnection conn) : base(conn)
Expand All @@ -52,7 +52,8 @@ public US001_MedOrderSingleArticle(LincaConnection conn) : base(conn)
/// </summary>
private bool CreateClientRecord()
{
var client = CareInformationSystem.GetClient();
LinkedCareSampleClient.CareInformationSystemScaffold.PseudoDatabaseRetrieve();
var client = new CareInformationSystem.Client();
var patient = new Patient
{
BirthDate = DateTime.ParseExact(
Expand All @@ -73,12 +74,15 @@ private bool CreateClientRecord()
system: Constants.WellknownOidSocialInsuranceNr,
value: client.SocInsNumber
));
patient.Gender = AdministrativeGender.Female;

(createdPatient, var canCue) = LincaDataExchange.CreatePatient(Connection, patient);
patient.Gender = AdministrativeGender.Female;
(var createdPatient, var canCue) = LincaDataExchange.CreatePatient(Connection, patient);

if(canCue)
{
LinkedCareSampleClient.CareInformationSystemScaffold.Data.ClientIdRenate = createdPatient.Id;
LinkedCareSampleClient.CareInformationSystemScaffold.PseudoDatabaseStore();

Console.WriteLine($"Client information transmitted, id {createdPatient.Id}");
}
else
Expand All @@ -89,82 +93,35 @@ private bool CreateClientRecord()
return canCue;
}

private bool OrderAnyPharmacy()
{
var client = CareInformationSystem.GetClient();
if(client.ClientId == Guid.Empty)
{
Console.WriteLine("No client Id has been registered in the care information system");

return false;
}

// populate the order position
var orderPosition = new MedicationRequest()
{
// the client for whom the medication is ordered
Subject = new()
{

},
// the practitioner who will be asked to issue the prescription
Performer = new()
{

},
// the product ordered
Medication = new()
{

}
};


// populate the order header
var order = new RequestOrchestration()
{
Contained = new(new[] { orderPosition })
};

(var createdOrder, var canCue) = LincaDataExchange.PlaceOrder(Connection, order);

if (canCue)
{
Console.WriteLine($"Order created, id {createdOrder.Id}");
}
else
{
Console.WriteLine("Failed to create order");
}

return canCue;
}

private void PrepareOrderMedicationRequest()
{
LinkedCareSampleClient.CareInformationSystemScaffold.PseudoDatabaseRetrieve();

medReq.Id = Guid.NewGuid().ToFhirId(); // REQUIRED
medReq.Status = MedicationRequest.MedicationrequestStatus.Unknown; // REQUIRED
medReq.Intent = MedicationRequest.MedicationRequestIntent.Proposal; // REQUIRED
medReq.Subject = new ResourceReference() // REQUIRED
{
Reference = $"HL7ATCorePatient/{createdPatient.Id}" // relative path to Linca Fhir patient resource
//Reference = "HL7ATCorePatient/c4313cca3e5b4cda89053630b5caae8d"
// relative path to Linca Fhir patient resource
Reference = $"HL7ATCorePatient/{LinkedCareSampleClient.CareInformationSystemScaffold.Data.ClientIdRenate}"
};

medReq.Medication = new()
{
Concept = new()
{
Coding = new()
{
new Coding()
{
new Coding()
{
Code = "0031130",
System = "https://termgit.elga.gv.at/CodeSystem/asp-liste",
Display = "Lasix 40 mg Tabletten"
}
Code = "0031130",
System = "https://termgit.elga.gv.at/CodeSystem/asp-liste",
Display = "Lasix 40 mg Tabletten"
}
}
}
};

medReq.InformationSource.Add(new ResourceReference() // REQUIRED, cardinality 1..1 in LINCA
{
Identifier = new()
Expand All @@ -174,6 +131,7 @@ private void PrepareOrderMedicationRequest()
},
Display = "Pflegedienst Immerdar" // optional
});

medReq.Requester = new ResourceReference() // REQUIRED
{
Identifier = new()
Expand All @@ -183,6 +141,7 @@ private void PrepareOrderMedicationRequest()
},
Display = "DGKP Susanne Allzeit"
};

medReq.Performer.Add(new ResourceReference() // REQUIRED, cardinality 1..1 in LINCA
{
Identifier = new()
Expand Down
Loading

0 comments on commit 7d782c5

Please sign in to comment.