|
54 | 54 | import org.hl7.fhir.r4.model.ServiceRequest;
|
55 | 55 | import org.hl7.fhir.r4.model.TimeType;
|
56 | 56 | import org.hl7.fhir.r4.model.Type;
|
| 57 | +import org.hl7.fhir.r4.model.ValueSet; |
| 58 | +import org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent; |
57 | 59 | import org.junit.AfterClass;
|
58 | 60 | import org.junit.BeforeClass;
|
59 | 61 | import org.junit.Test;
|
60 | 62 | import org.mitre.synthea.engine.Module;
|
61 | 63 | import org.mitre.synthea.engine.State;
|
62 | 64 | import org.mitre.synthea.export.FhirR4;
|
| 65 | +import org.mitre.synthea.helpers.RandomCodeGenerator; |
63 | 66 | import org.mitre.synthea.world.agents.Person;
|
64 | 67 |
|
65 | 68 | public class ActionsTest {
|
@@ -817,4 +820,65 @@ public void testGetAttribute() throws Exception {
|
817 | 820 | assertEquals("Robert Rainbow", name.getText());
|
818 | 821 | }
|
819 | 822 |
|
| 823 | + @Test |
| 824 | + public void testRandomCode() { |
| 825 | + Bundle b = new Bundle(); |
| 826 | + b.setType(BundleType.COLLECTION); |
| 827 | + |
| 828 | + ValueSet statusVs = constructValueSet( |
| 829 | + "http://hl7.org/fhir/encounter-status", |
| 830 | + "planned", "finished", "cancelled"); |
| 831 | + RandomCodeGenerator.loadValueSet("http://example.org/encounterStatus", statusVs); |
| 832 | + |
| 833 | + ValueSet classVs = constructValueSet( |
| 834 | + "http://terminology.hl7.org/CodeSystem/v3-ActCode", |
| 835 | + "AMB", "EMER", "ACUTE"); |
| 836 | + RandomCodeGenerator.loadValueSet("http://example.org/encounterClass", classVs); |
| 837 | + |
| 838 | + ValueSet typeVs = constructValueSet( |
| 839 | + "http://terminology.hl7.org/CodeSystem/encounter-type", |
| 840 | + "ADMS", "OKI"); |
| 841 | + RandomCodeGenerator.loadValueSet("http://example.org/encounterType", typeVs); |
| 842 | + |
| 843 | + Map<String, Object> action = getActionByName("testRandomCode"); |
| 844 | + Actions.applyAction(b, action, null, null); |
| 845 | + |
| 846 | + Encounter e = (Encounter) b.getEntryFirstRep().getResource(); |
| 847 | + |
| 848 | + Encounter.EncounterStatus status = e.getStatus(); |
| 849 | + assertNotNull(status); |
| 850 | + assertTrue(status == Encounter.EncounterStatus.PLANNED |
| 851 | + || status == Encounter.EncounterStatus.FINISHED |
| 852 | + || status == Encounter.EncounterStatus.CANCELLED); |
| 853 | + |
| 854 | + Coding encClass = e.getClass_(); |
| 855 | + assertNotNull(encClass); |
| 856 | + assertEquals("http://terminology.hl7.org/CodeSystem/v3-ActCode", encClass.getSystem()); |
| 857 | + String code = encClass.getCode(); |
| 858 | + assertTrue(code.equals("AMB") || code.equals("EMER") || code.equals("ACUTE")); |
| 859 | + |
| 860 | + CodeableConcept type = e.getTypeFirstRep(); |
| 861 | + assertNotNull(type); |
| 862 | + Coding typeCoding = type.getCodingFirstRep(); |
| 863 | + assertNotNull(typeCoding); |
| 864 | + assertEquals("http://terminology.hl7.org/CodeSystem/encounter-type", typeCoding.getSystem()); |
| 865 | + code = typeCoding.getCode(); |
| 866 | + assertTrue(code.equals("ADMS") || code.equals("OKI")); |
| 867 | + } |
| 868 | + |
| 869 | + private ValueSet constructValueSet(String system, String... codes) { |
| 870 | + ValueSet vs = new ValueSet(); |
| 871 | + |
| 872 | + // populates the codes so that they can be read in RandomCodeGenerator.loadValueSet |
| 873 | + ConceptSetComponent csc = new ConceptSetComponent(); |
| 874 | + csc.setSystem(system); |
| 875 | + for (String code : codes) { |
| 876 | + csc.addConcept().setCode(code).setDisplay(code); |
| 877 | + } |
| 878 | + |
| 879 | + vs.getCompose().getInclude().add(csc); |
| 880 | + |
| 881 | + return vs; |
| 882 | + } |
| 883 | + |
820 | 884 | }
|
0 commit comments