The scenario: a download can return a document in more than one representation
A native client may prefer a server-rendered PDF while retaining compatibility with an older structured JSON document. It needs to choose the request, distinguish the response and produce a usable filename without conflating format negotiation with authorization or document quality. A compatibility path should remain explicit enough to review.
Five selected existing Android JVM cases passed for negotiation and filename helpers. Four previously passed portable Swift cases from a retained fake-transport run support the related request/response and filename behaviour. Those four were already included in the programme aggregate and are not added again. No actual medical document was fetched or rendered.
Choose the preferred PDF request deliberately
The Android helper prefers a nonblank supplied pdfUrl. Otherwise it uses the main capability URL and adds its selected format parameter when needed. Its existing case checks a supplied PDF URL, an ordinary URL, a URL with another query parameter, a blank alternate and an already selected PDF format.
Those fixtures cover specific string-construction forms. They are not an exhaustive URL-parser or fragment/query compatibility test. The inspected Swift fetcher selects its supplied alternate using a different optional-value policy and requests PDF with a JSON fallback preference. Record each platform’s exact selection contract rather than assuming a shared comment establishes identical behaviour for every alternate URL.
Keep capability request authority separate from representation
A retained Swift fake-transport case refuses an untrusted-host URL and verifies that the selected accepted capability request has no Authorization header. Another refuses an untrusted alternate PDF URL even when the main URL is trusted. This supports a concrete credential-separation boundary for those direct requests.
The inspected Android fetcher checks scheme, host and port against its API origin before building its selected request. That integration was source-reviewed only here. Redirects, transport interceptors, URL edge cases and current server capability scope require separate acceptance. An accepted host and a PDF preference do not establish that the requesting person is entitled to a current medical record.
Distinguish a MIME label from validated document bytes
The Android pure case checks selected PDF and JSON media labels, parameters, case handling, problem+json and absent/HTML labels. This is classification of header text. The inspected Android fetch branch returns bytes according to that classification; the pure case does not parse or validate a PDF.
The retained Swift case additionally refuses a selected PDF-labelled HTML body and accepts a synthetic body beginning with the PDF marker. That marker is still minimal screening rather than a full PDF validation or rendering test. Neither set of cases establishes safe execution of every embedded PDF object, complete byte integrity, clinical correctness or visual layout.
Make JSON compatibility an intentional fallback
The retained Swift JSON case decodes a synthetic structured document and checks selected number/content rows. The inspected Android screen can retain a JSON response from the preferred fetch and pass it into its older card path, rather than assuming every successful request is a PDF. Its source also checks selected document/facility/person identifiers before rendering the parsed card.
Those Android screen checks were not mounted or executed here. A JSON response is not automatically a valid clinical document simply because its content type is recognized. Schema decoding, record identity, issued/void state, cache reconciliation and actual access must remain connected to the authoritative result in installed acceptance.
Choose between filename normalization and filename refusal
The Android existing cases check ordinary quoted/unquoted filenames, an extended encoded filename and missing metadata. Its filename helper reduces selected path-like input to a basename, replaces unsupported characters, bounds the selected stem and adds a PDF suffix. Fallback naming distinguishes selected known document kinds and an unknown kind.
The retained Swift filename case instead refuses selected path separators, a non-PDF extension, an empty stem and unsupported characters. These are different lexical policies. Both can support a controlled handover when described accurately, but neither fixture writes a real file or proves that every platform share/save destination is safe. Actual filesystem and export integration need their own acceptance.
Keep identifier hiding at the presentation boundary
The Android constant-set case checks that selected identifier keys are hidden from the JSON fallback’s display policy while an ordinary items key is retained. The inspected recursive screen helper consults that set and an identifier-suffix rule while rendering content. This is useful for keeping internal identifiers out of a patient-facing card.
The original JSON bytes can still contain those identifiers; a display filter is not server-side redaction or a complete privacy boundary. Its constant-membership test also does not establish every nested value, translated label or unusual identifier spelling. Review the rendered card and separately authorized payload, cache and diagnostic surfaces according to their actual responsibilities.
Accept transport, resource budgets and visual quality separately
The selected source requests document bytes and hands them to cache/presentation layers. The helper cases do not establish an end-to-end streaming memory budget, download interruption recovery or correct PDF pagination. A byte prefix, media label and filename are upstream of those concerns.
Use generated controlled documents to test size bounds, truncated responses, lost capability responses, revoked access, installed cache reconciliation and real share/save interaction. Render the resulting PDFs and review the JSON cards independently. This batch contains synthetic byte stubs and metadata, so its evidence should not be used to claim that a clinical PDF looks correct or is complete.
A native document compatibility handover
Retain the five new Android cases and the four already counted Swift cases with their immutable source and log records. Extend acceptance with malformed alternate URLs, relevant redirect/transport behaviour, unknown content, current capability authorization and actual export destinations. Keep filename policy and representation compatibility explicit per platform.
For a CTO, the useful design is a chain of narrow contracts: choose a representation, enforce the capability-request boundary, classify/decode the response, apply a filename policy and reconcile the document for presentation. The selected local evidence supports parts of that chain. It does not replace current server, device, resource or clinical-document acceptance.
Compare the reviewed boundaries
Document metadata and effective document acceptance are separate
On smaller screens, scroll across to compare every column. Keyboard users can focus the table and use the arrow keys.
| Boundary | Selected evidence | Separate acceptance |
|---|---|---|
| Representation | Android URL/MIME cases and retained Swift negotiation | URL edge cases and current server compatibility |
| Capability request | Retained Swift trusted-host/no-bearer fixtures | Current authorization, transport and redirect policy |
| Filename | Android normalization and retained Swift refusal cases | Installed filesystem/share-save interaction |
| Presentation | Selected JSON row and identifier-policy evidence | Native cards, cache reconciliation and PDF visual review |
Illustrative control flow
Pseudocode summarizing the decision boundary. It is not copied production code or a deployment instruction.
chosen_url = choose_platform_document_representation(download_receipt)
response = fetch_under_selected_capability_request_policy(chosen_url)
representation = classify_and_decode_supported_response(response)
filename = apply_explicit_platform_filename_policy(response)
# Metadata classification and a byte prefix do not establish authorization or PDF quality.About this engineering series
Written by Omer Muneer Qazi from a review of Movo-X implementation and dated engineering records. This article explains source behaviour and historical observations; current production, clinical outcomes and store availability require their own verification. Examples are synthetic and proposed test cases are identified as such.
Explore the Movo-X engineering series → · Related implementation experience →
Discuss a similar engineering problem
Send the workflow, current platform and the decision your team needs to make. I can help define an implementation or review scope with concrete acceptance evidence.
Discuss your project on WhatsApp ↗