1
+ package org .hl7 .fhir .igtools .publisher .utils ;
2
+
3
+ import java .io .File ;
4
+ import java .io .IOException ;
5
+ import java .util .ArrayList ;
6
+ import java .util .List ;
7
+
8
+ import org .hl7 .fhir .r5 .model .CanonicalResource ;
9
+ import org .hl7 .fhir .r5 .model .Resource ;
10
+ import org .hl7 .fhir .utilities .TextFile ;
11
+ import org .hl7 .fhir .utilities .Utilities ;
12
+
13
+ public class HL7OrgFhirFixerForExtensions {
14
+
15
+ public static void main (String [] args ) throws IOException {
16
+ File folderRoot = new File ("/Users/grahamegrieve/web/www.hl7.org.fhir" );
17
+ File folderExt = new File ("/Users/grahamegrieve/web/www.hl7.org.fhir/extensions" );
18
+ new HL7OrgFhirFixerForExtensions ().execute (folderRoot , folderExt );
19
+ }
20
+
21
+ private void execute (File folderRoot , File folderExt ) throws IOException {
22
+
23
+ scanForEmptyFolders (folderRoot );
24
+ }
25
+
26
+ private void scanForEmptyFolders (File ff ) throws IOException {
27
+ boolean indexed = false ;
28
+ for (File f : ff .listFiles ()) {
29
+ if (f .isDirectory ()) {
30
+ if (!Utilities .existsInList (f .getName (), "assets" , "assets-hist" , "dist" , "dist-hist" , "less" , "images" , "less-glyphicons" , "less-joyo" , "html" , "css" ,
31
+ "quick" , "qicore" , "external" , "examples" , "sid" , ".git" , "ehrsrle" )) {
32
+ scanForEmptyFolders (f );
33
+ }
34
+ } else {
35
+ if (Utilities .existsInList (f .getName (), "index.html" , "index.php" , "web.config" , ".no.index" )) {
36
+ indexed = true ;
37
+ }
38
+ if (f .getName ().equals (".no.index" )) {
39
+ f .delete ();
40
+ }
41
+ if (f .getName ().equals ("web.config" )) {
42
+ String s = TextFile .fileToString (f );
43
+ String url = s .substring (s .indexOf ("destination=" )+13 );
44
+ url = url .substring (0 , url .indexOf ("\" " ));
45
+ String rf = genRedirect (url .replace ("http://hl7.org/fhir" , "" ));
46
+ String dst = Utilities .path (ff , "index.php" );
47
+ TextFile .stringToFile (rf , dst );
48
+ f .delete ();
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ private boolean lowerCaseHtmlExists (File ff ) throws IOException {
55
+ String path = Utilities .path (ff .getParentFile (), ff .getName ().toLowerCase ()+".html" );
56
+ return new File (path ).exists ();
57
+ }
58
+
59
+ private String genRedirect (String url ) {
60
+ return "<?php\r \n " +
61
+ "function Redirect($url)\r \n " +
62
+ "{\r \n " +
63
+ " header('Location: ' . $url, true, 302);\r \n " +
64
+ " exit();\r \n " +
65
+ "}\r \n " +
66
+ "\r \n " +
67
+ "$accept = $_SERVER['HTTP_ACCEPT'];\r \n " +
68
+ "if (strpos($accept, 'html') !== false)\r \n " +
69
+ " Redirect('/fhir" +url +"');\r \n " +
70
+ "else \r \n " +
71
+ " header($_SERVER[\" SERVER_PROTOCOL\" ].\" 404 Not Found\" );\r \n " +
72
+ "?>\r \n " +
73
+ "\r \n " +
74
+ "{ \" message\" : \" not-found\" }\r \n " +
75
+ "\r \n " ;
76
+ }
77
+
78
+ private boolean isResourceName (String name ) {
79
+ return Utilities .existsInList (name ,
80
+ "Account" , "ActivityDefinition" , "ActorDefinition" , "AdministrableProductDefinition" , "AdverseEvent" , "AllergyIntolerance" , "Appointment" , "AppointmentResponse" , "ArtifactAssessment" , "AuditEvent" ,
81
+ "Basic" , "Binary" , "BiologicallyDerivedProduct" , "BiologicallyDerivedProductDispense" , "BodySite" , "BodyStructure" , "Bundle" , "CanonicalResource" , "CapabilityStatement" , "CarePlan" , "CareTeam" ,
82
+ "CatalogEntry" , "ChargeItem" , "ChargeItemDefinition" , "Citation" , "Claim" , "ClaimResponse" , "ClinicalImpression" , "ClinicalUseDefinition" , "CodeSystem" , "Communication" , "CommunicationRequest" ,
83
+ "CompartmentDefinition" , "Composition" , "ConceptMap" , "Condition" , "ConditionDefinition" , "Conformance" , "Consent" , "Contract" , "Coverage" , "CoverageEligibilityRequest" , "CoverageEligibilityResponse" ,
84
+ "DataElement" , "DetectedIssue" , "Device" , "DeviceAssociation" , "DeviceComponent" , "DeviceDefinition" , "DeviceDispense" , "DeviceMetric" , "DeviceRequest" , "DeviceUsage" , "DeviceUseRequest" ,
85
+ "DeviceUseStatement" , "DiagnosticOrder" , "DiagnosticReport" , "DocumentManifest" , "DocumentReference" , "DomainResource" , "EffectEvidenceSynthesis" , "EligibilityRequest" , "EligibilityResponse" ,
86
+ "Encounter" , "EncounterHistory" , "Endpoint" , "EnrollmentRequest" , "EnrollmentResponse" , "EpisodeOfCare" , "EventDefinition" , "Evidence" , "EvidenceReport" , "EvidenceVariable" , "ExampleScenario" ,
87
+ "ExpansionProfile" , "ExplanationOfBenefit" , "FamilyMemberHistory" , "Flag" , "FormularyItem" , "GenomicStudy" , "Goal" , "GraphDefinition" , "Group" , "GuidanceResponse" , "HealthcareService" , "ImagingManifest" ,
88
+ "ImagingObjectSelection" , "ImagingSelection" , "ImagingStudy" , "Immunization" , "ImmunizationEvaluation" , "ImmunizationRecommendation" , "ImplementationGuide" , "Ingredient" , "InsurancePlan" , "InventoryItem" ,
89
+ "InventoryReport" , "Invoice" , "Library" , "Linkage" , "List" , "Location" , "ManufacturedItemDefinition" , "Measure" , "MeasureReport" , "Media" , "Medication" , "MedicationAdministration" , "MedicationDispense" ,
90
+ "MedicationKnowledge" , "MedicationOrder" , "MedicationPrescription" , "MedicationRequest" , "MedicationStatement" , "MedicationUsage" , "MedicinalProduct" , "MedicinalProductAuthorization" , "MedicinalProductContraindication" ,
91
+ "MedicinalProductDefinition" , "MedicinalProductIndication" , "MedicinalProductIngredient" , "MedicinalProductInteraction" , "MedicinalProductManufactured" , "MedicinalProductPackaged" ,
92
+ "MedicinalProductPharmaceutical" , "MedicinalProductUndesirableEffect" , "MessageDefinition" , "MessageHeader" , "MetadataResource" , "MolecularSequence" , "NamingSystem" , "NutritionIntake" , "NutritionOrder" ,
93
+ "NutritionProduct" , "Observation" , "ObservationDefinition" , "OperationDefinition" , "OperationOutcome" , "Order" , "OrderResponse" , "Organization" , "OrganizationAffiliation" , "PackagedProductDefinition" ,
94
+ "Parameters" , "Patient" , "PaymentNotice" , "PaymentReconciliation" , "Permission" , "Person" , "PlanDefinition" , "Practitioner" , "PractitionerRole" , "Procedure" , "ProcedureRequest" , "ProcessRequest" ,
95
+ "ProcessResponse" , "Provenance" , "Questionnaire" , "QuestionnaireResponse" , "ReferralRequest" , "RegulatedAuthorization" , "RelatedPerson" , "RequestGroup" , "RequestOrchestration" , "Requirements" ,
96
+ "ResearchDefinition" , "ResearchElementDefinition" , "ResearchStudy" , "ResearchSubject" , "Resource" , "RiskAssessment" , "RiskEvidenceSynthesis" , "Schedule" , "SearchParameter" , "Sequence" , "ServiceDefinition" ,
97
+ "ServiceRequest" , "Slot" , "Specimen" , "SpecimenDefinition" , "StructureDefinition" , "StructureMap" , "Subscription" , "SubscriptionStatus" , "SubscriptionTopic" , "Substance" , "SubstanceDefinition" ,
98
+ "SubstanceNucleicAcid" , "SubstancePolymer" , "SubstanceProtein" , "SubstanceReferenceInformation" , "SubstanceSourceMaterial" , "SubstanceSpecification" , "SupplyDelivery" , "SupplyRequest" , "Task" ,
99
+ "TerminologyCapabilities" , "TestPlan" , "TestReport" , "TestScript" , "Transport" , "ValueSet" , "VerificationResult" , "VisionPrescription" ,
100
+
101
+ "Supply" , "Contraindication" , "CapabilityStatement2" , "ClinicalUseIssue" , "DiagnosticRequest" , "NutritionRequest" ,
102
+ "DecisionSupportServiceModule" , "ModuleDefinition" , "GuidanceRequest" , "DecisionSupportRule" , "ModuleMetadata" , "OrderSet" , "ModuleDefinition" , "GuidanceRequest" , "EvidenceFocus" ,"ItemInstance"
103
+ );
104
+ }
105
+
106
+
107
+ }
0 commit comments