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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
|
# File 'lib/resource_generator.rb', line 273
def self.apply_invariants!(resource)
case resource.class
when FHIR::Appointment
resource.reason = minimal_codeableconcept('http://snomed.info/sct','219006')
resource.participant.each{|p| p.fhirType=[ minimal_codeableconcept('http://hl7.org/fhir/participant-type','emergency') ] }
when FHIR::AppointmentResponse
resource.participantType = [ minimal_codeableconcept('http://hl7.org/fhir/participant-type','emergency') ]
when FHIR::AuditEvent
resource.object.each do |o|
o.query=nil
o.name = "name #{SecureRandom.base64}" if o.name.nil?
end
when FHIR::Bundle
resource.total = nil if !['searchset','history'].include?(resource.fhirType)
resource.entry.each {|e|e.search=nil} if resource.fhirType!='searchset'
resource.entry.each {|e|e.request=nil} if !['batch','transaction','history'].include?(resource.fhirType)
resource.entry.each {|e|e.response=nil} if !['batch-response','transaction-response'].include?(resource.fhirType)
head = resource.entry.first
if !head.nil?
if head.request.nil? && head.response.nil? && head.resource.nil?
if resource.fhirType == 'document'
head.resource = generate(FHIR::Composition,3)
elsif resource.fhirType == 'message'
head.resource = generate(FHIR::,3)
else
head.resource = generate(FHIR::Basic,3)
end
end
if head.resource.nil?
head.fullUrl = nil
else
rid = SecureRandom.random_number(100) + 1
head.fullUrl = "http://projectcrucible.org/fhir/#{rid}"
head.resource.xmlId = "#{rid}"
end
end
when FHIR::CarePlan
resource.activity.each {|a| a.reference = nil if a.detail }
when FHIR::Claim
resource.item.each do |item|
item.fhirType = minimal_coding('http://hl7.org/fhir/v3/ActCode','OHSINV')
item.detail.each do |detail|
detail.fhirType = minimal_coding('http://hl7.org/fhir/v3/ActCode','OHSINV')
detail.subDetail.each do |sub|
sub.fhirType = minimal_coding('http://hl7.org/fhir/v3/ActCode','OHSINV')
sub.service = minimal_coding('http://hl7.org/fhir/ex-USCLS','1205')
end
end
end
resource.missingTeeth.each do |mt|
mt.tooth = minimal_coding('http://hl7.org/fhir/ex-fdi','42')
end
when FHIR::ClaimResponse
resource.item.each do |item|
item.adjudication.each{|a|a.code = minimal_coding('http://hl7.org/fhir/adjudication','benefit')}
item.detail.each do |detail|
detail.adjudication.each{|a|a.code = minimal_coding('http://hl7.org/fhir/adjudication','benefit')}
detail.subDetail.each do |sub|
sub.adjudication.each{|a|a.code = minimal_coding('http://hl7.org/fhir/adjudication','benefit')}
end
end
end
resource.addItem.each do |addItem|
addItem.adjudication.each{|a|a.code = minimal_coding('http://hl7.org/fhir/adjudication','benefit')}
addItem.detail.each do |detail|
detail.adjudication.each{|a|a.code = minimal_coding('http://hl7.org/fhir/adjudication','benefit')}
end
end
when FHIR::Communication
resource.payload = nil
when FHIR::CommunicationRequest
resource.payload = nil
when FHIR::Composition
resource.attester.each {|a| a.mode = ['professional']}
resource.section.each do |section|
section.emptyReason = nil
section.section.each do |sub|
sub.emptyReason = nil
sub.section = nil
end
end
when FHIR::ConceptMap
if(resource.sourceUri.nil? && resource.sourceReference.nil?)
resource.sourceReference = textonly_reference('ValueSet')
end
if(resource.targetUri.nil? && resource.targetReference.nil?)
resource.targetReference = textonly_reference('ValueSet')
end
when FHIR::Conformance
resource.fhirVersion = 'DSTU2'
resource.format = ['xml','json']
if resource.kind == 'capability'
resource.implementation = nil
elsif resource.kind == 'requirements'
resource.implementation = nil
resource.software = nil
end
resource.messaging.each{|m| m.endpoint = nil} if resource.kind != 'instance'
when FHIR::Contract
resource.actor.each do |actor|
actor.entity = textonly_reference('Patient')
end
resource.term.each do |term|
term.actor.each do |actor|
actor.entity = textonly_reference('Organization')
end
term.group.each do |group|
group.actor.each do |actor|
actor.entity = textonly_reference('Organization')
end
end
end
resource.friendly.each do |f|
f.contentAttachment = nil
f.contentReference = textonly_reference('DocumentReference')
end
resource.legal.each do |f|
f.contentAttachment = nil
f.contentReference = textonly_reference('DocumentReference')
end
resource.rule.each do |f|
f.contentAttachment = nil
f.contentReference = textonly_reference('DocumentReference')
end
when FHIR::DataElement
resource.mapping.each do |m|
m.fhirIdentity = SecureRandom.base64 if m.fhirIdentity.nil?
m.fhirIdentity.gsub!(/[^0-9A-Za-z]/, '')
end
when FHIR::DeviceMetric
resource.measurementPeriod = nil
when FHIR::DiagnosticReport
date = DateTime.now
resource.effectiveDateTime = date.strftime("%Y-%m-%dT%T.%LZ")
resource.effectivePeriod = nil
when FHIR::DocumentManifest
resource.content.each do |c|
c.pAttachment = nil
c.pReference = textonly_reference('Any')
end
when FHIR::DocumentReference
resource.docStatus = minimal_codeableconcept('http://hl7.org/fhir/composition-status','preliminary')
when FHIR::ElementDefinition
keys = []
resource.constraint.each do |constraint|
constraint.key = SecureRandom.base64 if constraint.key.nil?
constraint.key.gsub!(/[^0-9A-Za-z]/, '')
keys << constraint.key
constraint.xpath = "/"
end
resource.condition = keys
resource.mapping.each do |m|
m.fhirIdentity = SecureRandom.base64 if m.fhirIdentity.nil?
m.fhirIdentity.gsub!(/[^0-9A-Za-z]/, '')
end
resource.max = "#{resource.min+1}"
is_codeable = false
resource.fhirType.each do |f|
is_codeable = (['code','Coding','CodeableConcept'].include?(f.code))
end
resource.binding = nil unless is_codeable
when FHIR::Goal
resource.outcome.each do |outcome|
outcome.resultCodeableConcept = nil
outcome.resultReference = textonly_reference('Observation')
end
when FHIR::Group
resource.member = [] if resource.actual==false
resource.characteristic.each do |c|
c.valueCodeableConcept = nil
c.valueBoolean = true
c.valueQuantity = nil
c.valueRange = nil
end
when FHIR::ImagingObjectSelection
resource.uid = random_oid
index = SecureRandom.random_number(FHIR::ImagingObjectSelection::VALID_CODES[:title].length)
code = FHIR::ImagingObjectSelection::VALID_CODES[:title][index]
resource.title = minimal_codeableconcept('http://nema.org/dicom/dicm',code)
resource.study.each do |study|
study.uid = random_oid
study.series.each do |series|
series.uid = random_oid
series.instance.each do |instance|
instance.sopClass = random_oid
instance.uid = random_oid
end
end
end
when FHIR::ImagingStudy
resource.uid = random_oid
resource.series.each do |series|
series.uid=random_oid
series.instance.each do |instance|
instance.uid = random_oid
instance.sopClass = random_oid
end
end
when FHIR::Immunization
if resource.wasNotGiven
resource.explanation.reasonNotGiven = [ textonly_codeableconcept("reasonNotGiven #{SecureRandom.base64}") ]
resource.explanation.reason = nil
resource.reaction = nil
else
resource.explanation.reasonNotGiven = nil
resource.explanation.reason = [ textonly_codeableconcept("reason #{SecureRandom.base64}") ]
end
when FHIR::ImplementationGuide
resource.fhirVersion = "DSTU2"
resource.package.each do |package|
package.resource.each do |r|
r.sourceUri = nil
r.sourceReference = textonly_reference('Any')
end
end
when FHIR::List
resource.emptyReason = nil
resource.entry.each do |entry|
resource.mode = 'changes' if !entry.fhirDeleted.nil?
end
when FHIR::Media
if resource.fhirType == 'video'
resource.frames = nil
elsif resource.fhirType == 'photo'
resource.duration = nil
elsif resource.fhirType == 'audio'
resource.height = nil
resource.width = nil
resource.frames = nil
else
resource.height = nil
resource.width = nil
resource.frames = nil
end
when FHIR::Medication
if resource.product.try(:ingredient)
resource.product.ingredient.each {|i|i.amount = nil}
end
when FHIR::MedicationAdministration
date = DateTime.now
resource.effectiveTimeDateTime = date.strftime("%Y-%m-%dT%T.%LZ")
resource.effectiveTimePeriod = nil
if resource.wasNotGiven
resource.reasonGiven = nil
else
resource.reasonNotGiven = nil
end
resource.medicationReference = textonly_reference('Medication')
resource.medicationCodeableConcept = nil
when FHIR::MedicationDispense
resource.medicationReference = textonly_reference('Medication')
resource.medicationCodeableConcept = nil
resource.dosageInstruction.each {|d|d.timing = nil }
when FHIR::MedicationOrder
resource.medicationReference = textonly_reference('Medication')
resource.medicationCodeableConcept = nil
resource.dosageInstruction.each {|d|d.timing = nil }
when FHIR::MedicationStatement
resource.reasonNotTaken = nil if resource.wasNotTaken != true
resource.medicationReference = textonly_reference('Medication')
resource.medicationCodeableConcept = nil
resource.dosage.each{|d|d.timing=nil}
when FHIR::
resource.response.identifier.gsub!(/[^0-9A-Za-z]/, '') if resource.try(:response).try(:identifier)
when FHIR::NamingSystem
resource.replacedBy = nil if resource.status!='retired'
if resource.kind == 'root'
resource.uniqueId.each do |uid|
uid.fhirType='other' if ['uuid','oid'].include?(uid.fhirType)
end
end
resource.uniqueId.each do |uid|
uid.preferred = nil
end
when FHIR::NutritionOrder
resource.oralDiet.schedule = nil if resource.oralDiet
resource.supplement.each{|s|s.schedule=nil}
resource.enteralFormula.administration = nil if resource.enteralFormula
when FHIR::OperationDefinition
resource.parameter.each do |p|
p.binding = nil
p.part = nil
end
when FHIR::Order
resource.when.schedule = nil
when FHIR::Patient
resource.maritalStatus = minimal_codeableconcept('http://hl7.org/fhir/v3/MaritalStatus','S')
when FHIR::Procedure
resource.reasonNotPerformed = nil if resource.notPerformed != true
resource.focalDevice.each do |fd|
fd.action = minimal_codeableconcept('http://hl7.org/fhir/ValueSet/device-action','implanted')
end
when FHIR::Provenance
resource.entity.each do |e|
e.agent.relatedAgent = nil if e.agent
end
when FHIR::RelatedPerson
resource.relationship = minimal_codeableconcept('http://hl7.org/fhir/patient-contact-relationship','family')
when FHIR::Questionnaire
resource.group.required = true
resource.group.group = nil
resource.group.question.each {|q|q.options = nil }
when FHIR::QuestionnaireResponse
resource.group.group = nil
resource.group.question.each {|q|q.answer = nil }
when FHIR::Subscription
resource.status = 'requested' if resource.xmlId.nil?
resource.channel.payload = 'applicaton/json+fhir'
resource.end = nil
when FHIR::SupplyDelivery
resource.fhirType = minimal_codeableconcept('http://hl7.org/fhir/supply-item-type','medication')
when FHIR::SupplyRequest
resource.kind = minimal_codeableconcept('http://hl7.org/fhir/supply-kind','central')
if resource.when
resource.when.schedule = nil
resource.when.code = minimal_codeableconcept('http://snomed.info/sct','20050000')
end
when FHIR::StructureDefinition
resource.fhirVersion = 'DSTU2'
resource.snapshot.element.first.path = resource.constrainedType if resource.snapshot && resource.snapshot.element
resource.mapping.each do |m|
m.fhirIdentity.gsub!(/[^0-9A-Za-z]/, '') if m.fhirIdentity
end
when FHIR::TestScript
resource.variable.each do |v|
v.sourceId.gsub!(/[^0-9A-Za-z]/, '') if v.sourceId
v.path = nil if v.
end
if resource.setup
resource.setup.metadata = nil
resource.setup.action.each do |a|
a.assert = nil if a.operation
apply_invariants!(a.operation) if a.operation
apply_invariants!(a.assert) if a.assert
end
end
resource.test.each do |test|
test.metadata = nil
test.action.each do |a|
a.assert = nil if a.operation
apply_invariants!(a.operation) if a.operation
apply_invariants!(a.assert) if a.assert
end
end
if resource.teardown
resource.teardown.action.each do |a|
apply_invariants!(a.operation) if a.operation
end
end
when FHIR::TestScript::TestScriptSetupActionAssertComponent
keys = ['contentType','headerField','minimumId','navigationLinks','path','resource','responseCode','response','validateProfileId']
has_keys = []
keys.each do |key|
has_keys << key if resource.try(key.to_sym)
end
has_keys[1..-1].each do |key|
resource.send("#{key}=",nil)
end
resource.sourceId.gsub!(/[^0-9A-Za-z]/, '') if resource.sourceId
resource.validateProfileId.gsub!(/[^0-9A-Za-z]/, '') if resource.validateProfileId
when FHIR::TestScript::TestScriptSetupActionOperationComponent
resource.responseId.gsub!(/[^0-9A-Za-z]/, '') if resource.responseId
resource.sourceId.gsub!(/[^0-9A-Za-z]/, '') if resource.sourceId
resource.targetId.gsub!(/[^0-9A-Za-z]/, '') if resource.targetId
when FHIR::ValueSet
if resource.compose
resource.compose.include.each do |inc|
inc.filter = nil if inc.concept
end
resource.compose.exclude.each do |exc|
exc.filter = nil if exc.concept
end
end
else
end
end
|