5454import org .hl7 .fhir .r4 .model .ServiceRequest ;
5555import org .hl7 .fhir .r4 .model .TimeType ;
5656import org .hl7 .fhir .r4 .model .Type ;
57+ import org .hl7 .fhir .r4 .model .ValueSet ;
58+ import org .hl7 .fhir .r4 .model .ValueSet .ConceptSetComponent ;
5759import org .junit .AfterClass ;
5860import org .junit .BeforeClass ;
5961import org .junit .Test ;
6062import org .mitre .synthea .engine .Module ;
6163import org .mitre .synthea .engine .State ;
6264import org .mitre .synthea .export .FhirR4 ;
65+ import org .mitre .synthea .helpers .RandomCodeGenerator ;
6366import org .mitre .synthea .world .agents .Person ;
6467
6568public class ActionsTest {
@@ -82,6 +85,7 @@ public static void setupClass() throws FileNotFoundException {
8285 File file = new File (classLoader .getResource ("flexporter/test_mapping.yaml" ).getFile ());
8386
8487 testMapping = Mapping .parseMapping (file );
88+ testMapping .loadValueSets ();
8589 }
8690
8791 @ AfterClass
@@ -817,4 +821,34 @@ public void testGetAttribute() throws Exception {
817821 assertEquals ("Robert Rainbow" , name .getText ());
818822 }
819823
824+ @ Test
825+ public void testRandomCode () {
826+ Bundle b = new Bundle ();
827+ b .setType (BundleType .COLLECTION );
828+
829+ Map <String , Object > action = getActionByName ("testRandomCode" );
830+ Actions .applyAction (b , action , null , null );
831+
832+ Encounter e = (Encounter ) b .getEntryFirstRep ().getResource ();
833+
834+ Encounter .EncounterStatus status = e .getStatus ();
835+ assertNotNull (status );
836+ assertTrue (status == Encounter .EncounterStatus .PLANNED
837+ || status == Encounter .EncounterStatus .FINISHED
838+ || status == Encounter .EncounterStatus .CANCELLED );
839+
840+ Coding encClass = e .getClass_ ();
841+ assertNotNull (encClass );
842+ assertEquals ("http://terminology.hl7.org/CodeSystem/v3-ActCode" , encClass .getSystem ());
843+ String code = encClass .getCode ();
844+ assertTrue (code .equals ("AMB" ) || code .equals ("EMER" ) || code .equals ("ACUTE" ));
845+
846+ CodeableConcept type = e .getTypeFirstRep ();
847+ assertNotNull (type );
848+ Coding typeCoding = type .getCodingFirstRep ();
849+ assertNotNull (typeCoding );
850+ assertEquals ("http://terminology.hl7.org/CodeSystem/encounter-type" , typeCoding .getSystem ());
851+ code = typeCoding .getCode ();
852+ assertTrue (code .equals ("ADMS" ) || code .equals ("OKI" ));
853+ }
820854}
0 commit comments