Skip to content

Commit

Permalink
Merge pull request #182 from b123400/fix-179
Browse files Browse the repository at this point in the history
Send any prescription to ZurRose, convert BAG to GLN
  • Loading branch information
zdavatz authored Dec 25, 2024
2 parents 3e33015 + 0400278 commit e64473d
Show file tree
Hide file tree
Showing 27 changed files with 461 additions and 91 deletions.
136 changes: 92 additions & 44 deletions AmiKoDesitin/Base.lproj/PatientViewController.xib

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion AmiKoDesitin/DoctorViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ - (BOOL) validateFields:(Operator *)doctor
valid = FALSE;
}

BOOL hinLoggedIn = [[MLPersistenceManager shared] HINSDSTokens] != nil || [[MLPersistenceManager shared] HINADSwissTokens] != nil;
// Validate photo
if (!self.signatureView.image) {
if (!self.signatureView.image && !hinLoggedIn) {
self.signatureView.backgroundColor = lightRed;
valid = FALSE;
}
Expand Down
1 change: 1 addition & 0 deletions AmiKoDesitin/EPrescription/EPrescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ NS_ASSUME_NONNULL_BEGIN

- (ZurRosePrescription *)toZurRosePrescription;
- (NSDictionary *)amkDict;
+ (NSString *)swissKantonFromZip:(NSString *)zip;

@end

Expand Down
11 changes: 7 additions & 4 deletions AmiKoDesitin/EPrescription/EPrescription.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "EPrescription.h"
#import "NSData+GZIP.h"
#import "MLUtility.h"
#import "Patient.h"

@implementation EPrescriptionPatientId
@end
Expand Down Expand Up @@ -214,7 +215,7 @@ - (ZurRosePrescription *)toZurRosePrescription {
patient.firstName = self.patientFirstName;
patient.street = self.patientStreet;
patient.city = self.patientCity;
patient.kanton = [self swissKantonFromZip:self.patientZip];
patient.kanton = [EPrescription swissKantonFromZip:self.patientZip];
patient.zipCode = self.patientZip;
patient.birthday = self.patientBirthdate;
patient.sex = [self.patientGender intValue]; // same, 1 = m, 2 = f
Expand Down Expand Up @@ -275,7 +276,7 @@ - (ZurRosePrescription *)toZurRosePrescription {
return prescription;
}

- (NSString *)swissKantonFromZip:(NSString *)zip {
+ (NSString *)swissKantonFromZip:(NSString *)zip {
if (!zip.length) return nil;
NSURL *url = [[NSBundle mainBundle] URLForResource:@"swiss-zip-to-kanton" withExtension:@"json"];
NSData *data = [NSData dataWithContentsOfURL:url];
Expand Down Expand Up @@ -315,6 +316,8 @@ - (NSDictionary *)amkDict {
}];
}

EPrescriptionPatientId *firstPatientId = self.patientIds.firstObject;

NSDictionary *amkDict = @{
@"prescription_hash": [[NSUUID UUID] UUIDString],
// Normally place_date is composed with doctor's name or city,
Expand All @@ -329,13 +332,13 @@ - (NSDictionary *)amkDict {
@"given_name": self.patientLastName ?: @"",
@"family_name": self.patientFirstName ?: @"",
@"birth_date": self.patientBirthdate ? [birthDateDateFormatter stringFromDate:self.patientBirthdate] : @"",
@"gender": self.patientGender.intValue == 1 ? @"M" : @"F",
@"gender": self.patientGender.intValue == 1 ? KEY_AMK_PAT_GENDER_M : KEY_AMK_PAT_GENDER_F,
@"email_address": self.patientEmail ?: @"",
@"phone_number": self.patientPhone ?: @"",
@"postal_address": self.patientStreet ?: @"",
@"city": self.patientCity ?: @"",
@"zip_code": self.patientZip ?: @"",
@"insurance_gln": self.patientReceiverGLN ?: @"",
@"insurance_gln": [firstPatientId.type isEqual:@1] ? firstPatientId.value : (self.patientReceiverGLN ?: @""),
},
@"medications": mediDicts,
};
Expand Down
6 changes: 4 additions & 2 deletions AmiKoDesitin/EPrescription/ZurRosePrescription.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ - (DDXMLDocument *)toXML {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd";
[e addAttribute:[DDXMLNode attributeWithName:@"issueDate" stringValue:[formatter stringFromDate:self.issueDate]]];
[e addAttribute:[DDXMLNode attributeWithName:@"validity" stringValue:[formatter stringFromDate:self.validity]]];
[e addAttribute:[DDXMLNode attributeWithName:@"validity" stringValue:self.validity ? [formatter stringFromDate:self.validity] : @""]];
[e addAttribute:[DDXMLNode attributeWithName:@"user" stringValue:self.user]];
[e addAttribute:[DDXMLNode attributeWithName:@"password" stringValue:self.password]];
if (self.prescriptionNr) {
Expand Down Expand Up @@ -58,7 +58,9 @@ - (void)sendToZurRoseWithCompletion:(void (^)(NSHTTPURLResponse* res, NSError* e
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://estudio.zur-rose.ch/estudio/prescriptioncert"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[[self toXML] XMLData]];
NSData *xmlData = [[self toXML] XMLData];
[request setHTTPBody:xmlData];
NSLog(@"xml: %@", [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding]);
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (![response isKindOfClass:[NSHTTPURLResponse class]]) return;
callback((NSHTTPURLResponse*)response, error);
Expand Down
2 changes: 1 addition & 1 deletion AmiKoDesitin/EPrescription/ZurRoseProduct.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, strong) NSString *pharmacode; // optional
@property (nonatomic, strong) NSString *eanId; // optional
@property (nonatomic, strong) NSString *description; // optional
@property (nonatomic, strong) NSString *description_; // optional
@property (nonatomic, assign) BOOL repetition;
@property (nonatomic, assign) int nrOfRepetitions; // optional, 0 - 99
@property (nonatomic, assign) int quantity; // 0 - 999
Expand Down
4 changes: 2 additions & 2 deletions AmiKoDesitin/EPrescription/ZurRoseProduct.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ - (DDXMLElement *)toXML {
if (self.eanId) {
[e addAttribute:[DDXMLNode attributeWithName:@"eanId" stringValue:self.eanId]];
}
if (self.description) {
[e addAttribute:[DDXMLNode attributeWithName:@"description" stringValue:self.description]];
if (self.description_) {
[e addAttribute:[DDXMLNode attributeWithName:@"description" stringValue:self.description_]];
}
[e addAttribute:[DDXMLNode attributeWithName:@"repetition" stringValue:self.repetition ? @"true" : @"false"]];
if (self.nrOfRepetitions >= 0) {
Expand Down
20 changes: 20 additions & 0 deletions AmiKoDesitin/MLSendToZurRoseActivity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// MLSendToZurRoseActivity.h
// AmikoDesitin
//
// Created by b123400 on 2024/12/23.
// Copyright © 2024 Ywesee GmbH. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "EPrescription/ZurRosePrescription.h"

NS_ASSUME_NONNULL_BEGIN

@interface MLSendToZurRoseActivity : UIActivity

@property (nonatomic, strong) ZurRosePrescription *zurRosePrescription;

@end

NS_ASSUME_NONNULL_END
58 changes: 58 additions & 0 deletions AmiKoDesitin/MLSendToZurRoseActivity.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// MLSendToZurRoseActivity.m
// AmikoDesitin
//
// Created by b123400 on 2024/12/23.
// Copyright © 2024 Ywesee GmbH. All rights reserved.
//

#import "MLSendToZurRoseActivity.h"

@implementation MLSendToZurRoseActivity

- (NSString *)activityTitle {
return NSLocalizedString(@"Send to ZurRose", @"");
}

- (UIImage *)activityImage {
return [UIImage systemImageNamed:@"paperplane"];
}

- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems {
return YES;
}

- (void)prepareWithActivityItems:(NSArray *)activityItems {

}

- (void)performActivity {
[self.zurRosePrescription sendToZurRoseWithCompletion:^(NSHTTPURLResponse * _Nonnull res, NSError * _Nonnull error) {
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController *root = [[UIApplication sharedApplication].keyWindow rootViewController];
if (error || res.statusCode != 200) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Error", @"")
message:[error localizedDescription] ?: [NSString stringWithFormat:NSLocalizedString(@"Error Code: %ld", @""), res.statusCode]
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"")
style:UIAlertActionStyleDefault
handler:nil]];
[root presentViewController:alert animated:YES completion:nil];
} else {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
message:NSLocalizedString(@"Prescription is sent to ZurRose", @"")
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"")
style:UIAlertActionStyleDefault
handler:nil]];
[root presentViewController:alert animated:YES completion:nil];
}
});
}];
}

- (UIActivityCategory)activityCategory {
return UIActivityCategoryShare;
}

@end
7 changes: 3 additions & 4 deletions AmiKoDesitin/Model.xcdatamodeld/Model.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="15702" systemVersion="18G103" minimumToolsVersion="Automatic" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23231" systemVersion="23H124" minimumToolsVersion="Automatic" sourceLanguage="Objective-C" userDefinedModelVersionIdentifier="">
<entity name="Patient" representedClassName="PatientModel" syncable="YES">
<attribute name="birthDate" optional="YES" attributeType="String"/>
<attribute name="city" optional="YES" attributeType="String"/>
Expand All @@ -8,15 +8,14 @@
<attribute name="familyName" optional="YES" attributeType="String"/>
<attribute name="gender" optional="YES" attributeType="String"/>
<attribute name="givenName" optional="YES" attributeType="String"/>
<attribute name="healthCardNumber" optional="YES" attributeType="String"/>
<attribute name="heightCm" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="insuranceGLN" optional="YES" attributeType="String"/>
<attribute name="phoneNumber" optional="YES" attributeType="String"/>
<attribute name="postalAddress" optional="YES" attributeType="String"/>
<attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="uniqueId" optional="YES" attributeType="String"/>
<attribute name="weightKg" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="zipCode" optional="YES" attributeType="String"/>
</entity>
<elements>
<element name="Patient" positionX="-63" positionY="-18" width="128" height="253"/>
</elements>
</model>
4 changes: 4 additions & 0 deletions AmiKoDesitin/Patient.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#define KEY_AMK_PAT_COUNTRY @"country"
#define KEY_AMK_PAT_PHONE @"phone_number"
#define KEY_AMK_PAT_EMAIL @"email_address"
#define KEY_AMK_PAT_HEALTH_CARD_NUMBER @"health_card_number"
#define KEY_AMK_PAT_INSURANCE_GLN @"insurance_gln"

@interface Patient : NSObject

Expand All @@ -39,6 +41,8 @@
@property (atomic, copy) NSString *postalAddress;
@property (atomic, copy) NSString *phoneNumber;
@property (atomic, copy) NSString *emailAddress;
@property (atomic, copy) NSString *healthCardNumber;
@property (atomic, copy) NSString *insuranceGLN;

// Only available when patient is read from database
@property (nonatomic, strong, nullable) NSDate *timestamp;
Expand Down
6 changes: 6 additions & 0 deletions AmiKoDesitin/Patient.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ @implementation Patient
@synthesize postalAddress;
@synthesize phoneNumber;
@synthesize emailAddress;
@synthesize healthCardNumber;
@synthesize insuranceGLN;

- (void)importFromDict:(NSDictionary *)dict
{
Expand All @@ -40,6 +42,8 @@ - (void)importFromDict:(NSDictionary *)dict
country = [self getString:KEY_AMK_PAT_COUNTRY orNilFromDict:dict];
phoneNumber = [self getString:KEY_AMK_PAT_PHONE orNilFromDict:dict];
emailAddress = [self getString:KEY_AMK_PAT_EMAIL orNilFromDict:dict];
healthCardNumber = [self getString:KEY_AMK_PAT_HEALTH_CARD_NUMBER orNilFromDict:dict];
insuranceGLN = [self getString:KEY_AMK_PAT_INSURANCE_GLN orNilFromDict:dict];
}

- (NSDictionary <NSString *, NSString *> *)dictionaryRepresentation {
Expand All @@ -57,6 +61,8 @@ - (void)importFromDict:(NSDictionary *)dict
[patientDict setObject:self.country ?: @"" forKey:KEY_AMK_PAT_COUNTRY];
[patientDict setObject:self.phoneNumber ?: @"" forKey:KEY_AMK_PAT_PHONE];
[patientDict setObject:self.emailAddress ?: @"" forKey:KEY_AMK_PAT_EMAIL];
[patientDict setObject:self.healthCardNumber ?: @"" forKey:KEY_AMK_PAT_HEALTH_CARD_NUMBER];
[patientDict setObject:self.insuranceGLN forKey:KEY_AMK_PAT_INSURANCE_GLN];
return patientDict;
}

Expand Down
3 changes: 2 additions & 1 deletion AmiKoDesitin/PatientViewController+smartCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "PatientViewController.h"

#define NUMBER_OF_BOXES_FOR_OCR 3
#define NUMBER_OF_BOXES_FOR_OCR 4

#import "CameraViewController.h"

Expand All @@ -18,6 +18,7 @@ struct scannedResults {
NSString *cardNumberString;
NSString *dateString;
NSString *sexString;
NSString *bagNumber;
};

#pragma mark - class extension
Expand Down
Loading

0 comments on commit e64473d

Please sign in to comment.